Creating a custom SNMP oid for a bash script

I would like to know how many files are in a certain directory, so i create a little one liner that counts them:
In my case i want to know the files on my replicated slave of postgres.
I make a directory in my snmp folder which is located in:/etc/snmp
mkdir /etc/snmp/scripts

Create a script you want:
vi /etc/snmp/scripts/postgresfiles.sh

Dont forget the #!/bin/bash or you will get a “Exec format error” this also happends if you enter a “new-line/blank” above your script
#!/bin/bash
ls -al /database/postgres/pgsql/data/pg_xlog | grep -c ^-

Also make your script executable:
chmod +x /etc/snmp/scripts/postgresfiles.sh

In my case my script returns the value 10.
sh /etc/snmp/scripts/postgresfiles.sh

After this we edit the snmpd.conf
vi /etc/snmp/snmpd.conf

Add an extend after your disk/main config this looks something like:
syslocation yourlocation
syscontact yourcontact

disk / 10000
disk /var 10000
disk /usr 10000
disk /tmp 10000
disk /home 10000
disk /boot 10000
disk /database 10000
disk /database.san 10000

load 12 14 14

#PostgreSQL Monitoring
extend postgresfiles /etc/snmp/scripts/postgresfiles.sh

Next we restart SNMP
/etc/init.d/snmpd restart

Now we should have a custom extended oid which we could walk/get:
snmpget -v2c -c public localhost 'NET-SNMP-EXTEND-MIB::nsExtendOutLine."postgresfiles".1'

This should return something like:
NET-SNMP-EXTEND-MIB::nsExtendOutLine."postgresfiles".1 = STRING: 10

Now we want to know what kind of OID belongs to this line, so we run the following:
snmptranslate -On 'NET-SNMP-EXTEND-MIB::nsExtendOutLine."postgresfiles".1'

In my case this returns the following oid:
1.3.6.1.4.1.8072.1.3.2.4.1.2.13.112.111.115.116.103.114.101.115.102.105.108.101.115.1

Now you can use this custom oid to make a graph in cacti or use it to monitor your server on custom scripts/oids

This entry was posted in CentOS, SNMP and tagged , , , , , , . Bookmark the permalink.

Leave a Reply