Differences

This shows you the differences between two versions of the page.

Link to this comparison view

sdk:scripts:snmp-trap [2015/05/05 15:04] – external edit 127.0.0.1sdk:scripts:snmp-trap [2022/09/05 12:24] (current) schmitt
Line 5: Line 5:
  */  */
  
-/* use SNMPv1 */ +HOST = "192.168.1.254"
-rc nb_snmp_traphost("192.168.1.254"162, 1, "public");+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) { if (rc != 0) {
-    printf("unable to set traphost\n");+    nb_syslog("unable to set SNMPv%d traphost", VERSION);
     exit(1);     exit(1);
 } }
  
 /* send null trap */ /* send null trap */
-if (nb_snmp_trap(".1.2.3.4.5", "n", ""!= 0) { +if (nb_snmp_trap(".1.2.3.4.5", "n", ""== 0) { 
-    printf("unable to send null trap");+    nb_syslog("sent null trap"); 
 +} else { 
 +    nb_syslog("unable to send null trap");
 } }
  
 /* send an integer trap */ /* send an integer trap */
-if (nb_snmp_trap(".1.2.3.4.5", "i", 1) != 0) { +if (nb_snmp_trap(".1.2.3.4.5", "i", 1) == 0) { 
-    printf("unable to send integer trap");+    nb_syslog("sent integer trap"); 
 +} else { 
 +    nb_syslog("unable to send integer trap");
 } }
  
 /* send an octet string trap */ /* send an octet string trap */
-if (nb_snmp_trap(".1.2.3.4.5", "s", "test"!= 0) { +if (nb_snmp_trap(".1.2.3.4.5", "s", "test"== 0) { 
-    printf("unable to send octet string trap");+    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); exit(0);
- 
 </code> </code>