For more information regarding the security incident at F5, the actions we are taking to address it, and our ongoing efforts to protect our customers, click here.

Forum Discussion

J_LE_42749's avatar
J_LE_42749
Icon for Nimbostratus rankNimbostratus
Jul 09, 2015

Custom MIB: is that possible to launch an external bash script?

Hello,

I want to monitor the ASM slow transactions into a custom MIB, so that it gets graphs on an external monitoring system (MRTG for instance).

I wrote a small script that count the number of slow transactions from /var/log/asm, compare to previously saved value and return the number of new events (file rotation is being considered as well).

The script:

!/bin/bash
logfile="/var/log/asm"
tmpfile="/tmp/asmslowtransac.tmp"

lastcount=$(if [ -f $tmpfile ]; then cat $tmpfile; else echo 0; fi)
echo "Old => " $lastcount

newcount=$(grep "Slow transactions" $logfile | awk '{print $24}' | sed 's/(//g' | sed 's/)//g' | awk '{s+=$1} END {print s}')
echo "New => " $newcount

if [ $lastcount -le $newcount ]; then
        newevents=$(($newcount - $lastcount))
        newevents=${newevents-}
else
        newevents=$newcount
fi

echo $newevents
echo $newcount > $tmpfile

My problem is that I want this script to be started when the OID is being polled but this does not work. Here is the content of /config/snmp/custom_mib.tcl:

register_mib ".2" asm_slow_transactions INT


 proc asm_slow_transactions {}
 {
 set status [catch {exec /bin/bash /shared/count_slow_transac.sh} result]
   if {$status != 0} {
        set result -1
  }
  return $result
  }

The script is located in /shared/ for now and has (I believe) enough privileges:

[root@e21ylbprd01:Active:In Sync] shared  ll count_slow_transac.sh
-rwxr-xr-x 1 root root 496 Jul  9 17:04 count_slow_transac.sh
[root@e21ylbprd01:Active:In Sync] shared 

When I do a snmpwalk against the OID I am just getting -1, which means that the exec operation failed:

[root@e21ylbprd01:Active:In Sync] ~  snmpwalk -Os -c MONITSEC -v 2c localhost .1.3.6.1.4.1.3375.2.100.2
bigipTrafficMgmt.100.2.0 = INTEGER: -1
[root@e21ylbprd01:Active:In Sync] ~ 

I can have the script running through crontab, and have the custom MIB just reading the INT from a file but this is not exactly what I want since I prefer to NOT have anything in crontab, first because it does not survive to an upgrade and second (less important) because I want to capture the value at the moment the SNMP polling is being done (and not the value from the previous script cycle).

Any help/suggestion will be appreciated!

Thanks

J

3 Replies

  • asn if you try with

    exit $newevents
    instead of
    echo $newevents
    in your bash script, what is the result?

  • Hi Amolari and thanks for your reply.

    Unfortunately it does not work either 😞

    In the custom MIB config file (/config/snmp/custom_mib.tcl) if I return the status of command

    [catch {exec /bin/bash /shared/count_slow_transac.sh} result]
    I am getting '1' (expecting '0' => no error)

    My interpretation of this '1' output is that the snmp daemon is unable to run

    exec /bin/bash /shared/count_slow_transac.sh
    command when getting polled against the custom OID.

    But I don't understand why it cannot issue the command...

    ps aux
    command shows that snmpd is running under root account so it cannot be a permission issue.

    [root@bigip:Active:In Sync] shared  ps aux | grep snmp
    root      5982  0.0  0.0   1628   364 ?        S    Jun09   0:00 runsv rmonsnmpd
    root      5984  0.0  0.0   1628   356 ?        S    Jun09   0:00 runsv nokiasnmpd
    root      6145  0.0  0.0   1628   368 ?        S    Jun09   0:00 runsv snmpd
    root      7684  0.3  0.2  33864 19364 ?        S    09:42   0:00 /usr/sbin/snmpd -f -c /config/snmp/snmpd.conf -I-ifTable ifXTable ipAddressTable -Lsd -LF 6 /var/log/snmpd.log -p /var/run/snmpd.pid
    root      7706  0.1  0.0  23036  6428 ?        S    09:42   0:00 /usr/sbin/rmonsnmpd -f -c /config/snmp/subagents.conf -s -l /dev/null
    root      8173  0.0  0.0   3128   756 pts/0    S+   09:46   0:00 grep snmp
    [root@bigip:Active:In Sync] shared