snmp customization

1. Bash Scripts

Preparing to extend snmp – prepare the scripts you would like to run, move it to desired folder and make sure they are executable by “root” user. I think it is hygienical to create a new folder called “scripts” in “/etc/snmp” and put these scripts there. If you disagree, you can put it anywhere else on the system too, as long as “root” user will be able to access them.

2. Edit snmpd.conf

To extend snmp we need to edit “/etc/snmp/snmpd.conf” configuration file and add the extend configuration parameters that point to bash scripts. For this example purpose i will extend SNMP by two bash scripts, you can add more or less of course.
# Extend SNMP
extend script1 /etc/snmp/scripts/script1.sh
extend script2 /etc/snmp/scripts/script2.sh

3. Restart SNMPD Service

To apply configuration changes we need to restart “snmpd” service by running the following command:
[mitch@node01 ~]$ sudo service snmpd restart
 Stopping snmpd: [ OK ]
 Starting snmpd: [ OK ]

4. Test it out

After we’ve restarted SNMPD service we can proceed to run tests by manually triggering the scripts via “snmpget” command, where:
  • “v2c” tells it to use Simple Network Management Protocol Version 2
  • “geekpeek” is the configured community name (default is “public”) you can see in snmpd.conf file
  • “localhost” is the host we are connecting to
  • “script1” is the human readable name of the extended SNMP
  • “STRING: X” tells us the output of the bash script which is X
[mitch@node01 ~]$ snmpget -v2c -c geekpeek localhost 'NET-SNMP-EXTEND-MIB::nsExtendOutLine."script1".1'
NET-SNMP-EXTEND-MIB::nsExtendOutLine."script1".1 = STRING: 1
[mitch@node01 ~]$ snmpget -v2c -c geekpeek localhost 'NET-SNMP-EXTEND-MIB::nsExtendOutLine."script2".1'
NET-SNMP-EXTEND-MIB::nsExtendOutLine."script2".1 = STRING: 2
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.

5. Get the OID

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:
[mitch@node01 ~]$ snmptranslate -On 'NET-SNMP-EXTEND-MIB::nsExtendOutput1Line."script1".1'
.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
[mitch@node01 ~]$ snmptranslate -On 'NET-SNMP-EXTEND-MIB::nsExtendOutput1Line."script2".1'
.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
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.

snmp disk monitor

Disk Statistics
Regarding disk statistics one of method is to modify snmpd.conf file (append below contents). Please note that there are some limitations on certain oid/objects like dskTotal, diskAvail (more info here).

#includeAllDisks 10%
disk / 10%
disk /opt 10%
disk /opt/makalu/storage 10%
# where 10% is threshold,it is set when 10% threshold is reached and reachable with UCD-SNMP-MIB::dskErrorFlag.<number>. it defaults to 100kB

List out mountpoints/path
# snmpwalk -v2c -c public localhost UCD-SNMP-MIB::dskPath
UCD-SNMP-MIB::dskPath.1 = STRING: /
UCD-SNMP-MIB::dskPath.2 = STRING: /opt
UCD-SNMP-MIB::dskPath.3 = STRING: /opt/makalu/storage

~# snmpwalk -v2c -c public localhost UCD-SNMP-MIB::dskPercent.3
UCD-SNMP-MIB::dskPercent.3 = INTEGER: 4

~# snmpwalk -v2c -c public localhost UCD-SNMP-MIB::dskDevice.3
UCD-SNMP-MIB::dskDevice.3 = STRING: MainPool/storage

root@myserver:~# df -hT
Filesystem Type Size Used Avail Use% Mounted on
udev devtmpfs 1.5G 0 1.5G 0% /dev
MainPool/ROOT/root zfs 47G 3.6G 43G 8% /
...
MainPool/application zfs 47G 3.4G 44G 8% /opt
...
MainPool/storage zfs 28G 1.1G 27G 4% /opt/data/storage
...

Note:- The percentage value usage is rounded off to ceiling value

zfs grub rescue

Boot into rescue linux
Setup the root zfspool and mounts
zfs set mountpoint=/mnt rpool/ROOT/pve-1
rm -rf /mnt/*
zfs mount rpool/ROOT/pve-1
mount -t proc /proc /mnt/proc
mount –rbind /dev /mnt/dev
mount –rbind /sys /mnt/sys
#Enter the chroot
chroot /mnt /bin/bash
source /etc/profile
You are now in the chroot
#fix apt and reinstall the required utils
dpkg –configure -a
apt-get update && apt-get dist-upgrade -y
apt-get install –reinstall grub-pc
apt-get install –reinstall zfs-initramfs
apt-get install –reinstall pve-kernel-4.4 linux-image-amd64
#install and configure
grub-install /dev/disk/by-id/
grub-install /dev/disk/by-id/
update-grub2
for x in $(cat /proc/cmdline); do case $x in root=ZFS=*) BOOT=zfs; ;; esac; done
grub-probe /
update-initramfs -u -k all
zfs set mountpoint=/ rpool/ROOT/pve-1
#exit the chroot
exit
Re-assign the mountpoint of the zfs and reboot
umount /mnt
umount rpool/ROOT/pve-1
zfs set mountpoint=/ rpool/ROOT/pve-1
Set the server to boot via hard drive and then Reboot (shutdown -r now)
If the system does not start, reboot into rescue linux and run the following to set the root path.
zfs set mountpoint=/ rpool/ROOT/pve-1


I don't know of a way to shrink a zfs partition (without a send/recreate/receive), so you better have room for your ext4 somewhere already.
  1. Create your ext partition
  2. Mount it somewhere temporarily
  3. rsync -avPX /boot/. /<tempboot>/.
  4. unmount /<tempboot>
  5. Move /boot to another location on zfs (eg. /bootbackup)
  6. Recreate /boot mountpoint and mount your new partition there
  7. Add the new boot ext4 partition to /etc/fstab
  8. Re-run update-grub (maybe even update-initramfs for good measure)
  9. Cross fingers and reboot
This is all from memory, so it's probably...right. The /bootbackup allows you to a location to periodically rsync your /boot ext4 into the pool for recovery purposes.