Мониторинг SNMP трапов#
В текущей реализации поддерживаются версии SNMP v1 и v2c.
Файл правил состоит из пяти основных частей:
Header — документация с определением переменных;
Lookup — таблицы приведения числовых обозначений в человекочитаемый формат;
Preparation — подготовка служебной информации и предварительная обработка трапов;
Body — ветвление правил по SNMP трапам;
Footer — подготовка результата для дальнейшей обработки.
Header — подготовка переменных#
if (typeof $OID1 == "undefined") $OID1 = "";
if (typeof $OID2 == "undefined") $OID2 = "";
if (typeof $OID3 == "undefined") $OID3 = "";
if (typeof $OID4 == "undefined") $OID4 = "";
if (typeof $OID5 == "undefined") $OID5 = "";
if (typeof $OID6 == "undefined") $OID6 = "";
if (typeof $OID7 == "undefined") $OID7 = "";
if (typeof $OID8 == "undefined") $OID8 = "";
if (typeof $OID9 == "undefined") $OID9 = "";
if (typeof $OID10 == "undefined") $OID10 = "";
if (typeof $OID11 == "undefined") $OID11 = "";
if (typeof $OID12 == "undefined") $OID12 = "";
if (typeof $1 == "undefined") $1 = "";
if (typeof $2 == "undefined") $2 = "";
if (typeof $3 == "undefined") $3 = "";
if (typeof $4 == "undefined") $4 = "";
if (typeof $5 == "undefined") $5 = "";
if (typeof $6 == "undefined") $6 = "";
if (typeof $7 == "undefined") $7 = "";
if (typeof $8 == "undefined") $8 = "";
if (typeof $9 == "undefined") $9 = "";
if (typeof $10 == "undefined") $10 = "";
if (typeof $11 == "undefined") $11 = "";
if (typeof $12 == "undefined") $12 = "";
_Manager = "";
_Agent = "";
_Class = "";
_Node = "";
_NodeAlias = "";
_AlertKey = "";
_AlertGroup = "";
_Summary = "";
_Severity = "";
_Type = "";
_Identifier = "";
_ExpireTime = 0;
_FirstOccurrence = new Date($ReceivedTime * 1000);
_LastOccurrence = _FirstOccurrence;
_Alert = false;
Lookup — таблицы приведения#
IANAifType = {
"1": "Other", // other - none of the following
"2": "Regular 1822", // regular1822
"3": "HDH 1822", // hdh1822
"4": "DDN X.25", // ddnX25
"5": "RFC-877 X.25", // rfc877x25
"6": "Ethernet CSMA-CD", // ethernetCsmacd
"7": "ISO 8802.3 CSMA-CD", // iso88023Csmacd
"8": "ISO 8802.4 Token Bus", // iso88024TokenBus
...
"212": "Voice FGD Exchange Access North American", // voiceFGDEANA - voice FGD Exchange Access North American
"213": "Voice Direct Inward Dialing" // voiceDID - voice Direct Inward Dialing
}
ifAdminStatus = {
"1": "Up", // up - ready to pass packets
"2": "Down", // down
"3": "Testing" // testing - in some test mode
}
ifOperStatus = {
"1": "Up", // up - ready to pass packets
"2": "Down", // down
"3": "Testing", // testing - in some test mode
"4": "Unknown", // unknown - status can not be determined for some reason.
"5": "Dormant", // dormant
"6": "Not Present", // notPresent - some component is missing
"7": "Lower Layer Down" // lowerLayerDown - down due to state of lower-layer interface(s)
}
Preparation — подготовка данных#
// Устанавливаем стандартный Agent, Manager и Class
_Manager = "SNMP Trap adapter on " + hostname()
_Agent = "SNMPagent"
_Class = "300"
// Проверяем если получили SNMPv2 трап и ковертируем его в SNMPv1 стилÑ