SDK Script snmp-trap.are

snmp-trap.are
/* DESC: This script can be used to send SNMP traps
 * Copyright (C) 2014 NetModule AG, Switzerland
 */
 
HOST = "192.168.1.254";
PORT = 162;
VERSION = 3;
COMMUNITY = "public";
USER = "traptest";
PASS = "mypassword";
AUTH = "SHA";
PRIV = "AES";
ENGINE = "0x8000000001020304";
 
nb_syslog("sending SNMPv%d traps to %s:%d", VERSION, HOST, PORT);
 
if (VERSION == 1) {
    /* use SNMPv1 */
    rc = nb_snmp_traphost(HOST, PORT, VERSION, COMMUNITY);
} else {
    /* use SNMPv3 */
    rc = nb_snmp_traphost(HOST, PORT, VERSION, USER, PASS, AUTH, PRIV, ENGINE);
}
if (rc != 0) {
    nb_syslog("unable to set SNMPv%d traphost", VERSION);
    exit(1);
}
 
/* send null trap */
if (nb_snmp_trap(".1.2.3.4.5", "n", "") == 0) {
    nb_syslog("sent null trap");
} else {
    nb_syslog("unable to send null trap");
}
 
/* send an integer trap */
if (nb_snmp_trap(".1.2.3.4.5", "i", 1) == 0) {
    nb_syslog("sent integer trap");
} else {
    nb_syslog("unable to send integer trap");
}
 
/* send an octet string trap */
if (nb_snmp_trap(".1.2.3.4.5", "s", "test") == 0) {
    nb_syslog("sent string trap");
} else {
    nb_syslog("unable to send string trap");
}
 
/* send an integer inform */
if (nb_snmp_inform(".1.2.3.4.5", "i", 1) == 0) {
    nb_syslog("sent integer inform");
} else {
    nb_syslog("unable to send integer inform");
}
 
exit(0);