SNMP can make your life as a system administrator a lot easier by performing many of the tasks that you’d either have to do by hand or automate by writing some clever script. It’s relatively easy to take care of most everyday system monitoring: SNMP can poll for disk-space utilization, notify you when mirrors are syncing, or record who is logging in or out of the system. This chapter introduces some interesting scripts for automating common system administration tasks. The SNMP scripts in this chapter represent just a few of the things SNMP allows you to do; use them as a launching pad for your own ideas.
Chapter 9 contained some scripts for collecting SNMP information using Perl, OpenView’s snmptrap program, and some other tools. Here’s how we used snmptrap to generate a trap giving us information about some problems with the database:
/opt/OV/bin/snmptrap -c public nms .18.104.22.168.4.1.2789.2500 "" 6 3003 "" \.22.214.171.124.4.1.2500.3003.1 octetstringascii "Oracle" \ .126.96.36.199.4.1.2500.3003.2 octetstringascii "Backup Not Running" \ .188.8.131.52.4.1.2500.3003.3 octetstringascii "Call the DBA Now for Help"
The way you send a trap in Perl is a little more involved, but it’s still easy to do:
#!/usr/local/bin/perl # Filename: /opt/local/perl_scripts/snmptrap.pl use SNMP_util "0.54"; # This will load the BER and SNMP_Session snmptrap("public\@nms:162", ".184.108.40.206.4.1.2789", "sunserver1", 6, 1247, ".220.127.116.11.4.1.2789.1247.1", ...