myapit

snmp-custom-script

Nov 24th, 2020
1,276
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Extend SNMP
  2. extend script1 /etc/snmp/scripts/script1.sh
  3. extend script2 /etc/snmp/scripts/script2.sh
  4. 3. Restart SNMPD Service
  5. To apply configuration changes we need to restart “snmpd” service by running the following command:
  6.  
  7. [mitch@node01 ~]$ sudo service snmpd restart
  8.  Stopping snmpd: [ OK ]
  9.  Starting snmpd: [ OK ]
  10. 4. Test it out
  11. After we’ve restarted SNMPD service we can proceed to run tests by manually triggering the scripts via “snmpget” command, where:
  12.  
  13. “v2c” tells it to use Simple Network Management Protocol Version 2
  14. “geekpeek” is the configured community name (default is “public”) you can see in snmpd.conf file
  15. “localhost” is the host we are connecting to
  16. “script1” is the human readable name of the extended SNMP
  17. “STRING: X” tells us the output of the bash script which is X
  18. [mitch@node01 ~]$ snmpget -v2c -c geekpeek localhost 'NET-SNMP-EXTEND-MIB::nsExtendOutLine."script1".1'
  19. NET-SNMP-EXTEND-MIB::nsExtendOutLine."script1".1 = STRING: 1
  20. [mitch@node01 ~]$ snmpget -v2c -c geekpeek localhost 'NET-SNMP-EXTEND-MIB::nsExtendOutLine."script2".1'
  21. NET-SNMP-EXTEND-MIB::nsExtendOutLine."script2".1 = STRING: 2
  22. As we can see the “script1” output is “1” and the “script2” output is “2”, which in my case is ok and i confirmed normal operation of SNMP.
  23.  
  24. 5. Get the OID
  25. There’s one more thing missing, to make this useful. To wrap things up we need to get the OID of these extended scripts and we can use this OID to make monitoring checks. To get the OIDs we need to run the “snmptranslate” command as you see below:
  26.  
  27. [mitch@node01 ~]$ snmptranslate -On 'NET-SNMP-EXTEND-MIB::nsExtendOutput1Line."script1".1'
  28. .1.3.6.1.4.1.8072.1.3.2.3.1.1.11.109.111.110.95.115.101.110.100.101.114.115
  29. [mitch@node01 ~]$ snmptranslate -On 'NET-SNMP-EXTEND-MIB::nsExtendOutput1Line."script2".1'
  30. .1.3.6.1.4.1.8072.1.3.2.3.1.1.14.100.99.115.95.112.111.115.110.95.100.101.108.97.121
  31. Voila and we got the OIDs we can call via SNMP. What we get is the output of the scripts configured in snmpd.conf file. Told you it’s really easy to extend snmp.
  32.  
  33. https://geekpeek.net/extend-snmp-run-bash-scripts-via-snmp/
  34. https://github.com/ahmednawazkhan/guides/blob/master/snmp/creating-custom-mib.md
  35. https://stackoverflow.com/questions/40525027/how-to-pass-variables-for-a-script-via-snmp-by-using-snmpget
  36. https://stackoverflow.com/questions/52720128/snmpd-pass-to-run-python
RAW Paste Data