Hello Paul,
now I got what I need:
snmpwalk -v2c -c testing 192.168.1.14 NET-SNMP-MIB::netSnmpPlaypen.1.3
NET-SNMP-MIB::netSnmpPlaypen.1.3 = INTEGER: 2150
NET-SNMP-MIB::netSnmpPlaypen.1.3 = INTEGER: 2150
But the value will not be refreshed.
Looks like the script will only one time at start from snmpd.
/etc/snmp/snmpd.conf
perl do "/scripts/get_V_TempWarm.pl"
Gesendet: Dienstag, 21. April 2020 um 23:21 Uhr
Von: "Paul Herring" <pauljherr...@gmail.com>
An: "Dennis Schneck" <dennisschn...@web.de>
Cc: net-snmp-users@lists.sourceforge.net
Betreff: Re: Re: bash script - extend - output as integer
Von: "Paul Herring" <pauljherr...@gmail.com>
An: "Dennis Schneck" <dennisschn...@web.de>
Cc: net-snmp-users@lists.sourceforge.net
Betreff: Re: Re: bash script - extend - output as integer
On Tue, Apr 21, 2020 at 8:14 PM Dennis Schneck <dennisschn...@web.de> wrote:
Hello Paul,thanks but exit code only max 255 (or I am wrong?) but I need 4 digets for example 9999so is there another way ?
From the same link:
> Integer exit codes are limited to a range of 0–255. For values that are likely to exceed 256, either use the standard output of the script (which will be typed as a string) or a different method of extending the agent.
So. Your options are
- use STRING anyway (their first suggestion)
- don't use extend and write a proper agent (their second)
- old-skool - use scaled integers, where 0 represents - er - 0. And 255 represents (to pick your example) 9999 - quick example of this third:
---
#!/bin/bash -u
val=${1:-0}
scaled=$((255*val/9999))
exit ${scaled}
---
val=${1:-0}
scaled=$((255*val/9999))
exit ${scaled}
---
$ for x in 1 10 39 40 41 250 500 5000 7500 9999; do ./scaled.sh ${x}; echo "${x} -> $?"; done
1 -> 0
10 -> 0
39 -> 0
40 -> 1
41 -> 1
250 -> 6
500 -> 12
5000 -> 127
7500 -> 191
9999 -> 255
1 -> 0
10 -> 0
39 -> 0
40 -> 1
41 -> 1
250 -> 6
500 -> 12
5000 -> 127
7500 -> 191
9999 -> 255
----
Note each unit of output represents a range of about 40 input units. If you can 'tighten' that 0-9999 range it may improve, bur your granularity is still stuck to 256 values.
Out of range numbers go silly with that specific script - you'd need error checking:
$ for x in 10000 20000 30000 40000; do ./scaled.sh ${x}; echo "${x} -> $?"; done
10000 -> 255
20000 -> 254
30000 -> 253
40000 -> 252
10000 -> 255
20000 -> 254
30000 -> 253
40000 -> 252
Gesendet: Dienstag, 21. April 2020 um 15:36 Uhr
Von: "Paul Herring" <pauljherr...@gmail.com>
An: "Dennis Schneck" <dennisschn...@web.de>
Cc: net-snmp-users@lists.sourceforge.net
Betreff: Re: bash script - extend - output as integer> Note that the exit code (“8” in this example) is provided as an INTEGER type and any output is provided as a STRING type.You want get_TempOfRoom1.sh to exit (the return code) with the value you want in the INTEGER, not echo it out.On Tue, Apr 21, 2020 at 1:56 PM Dennis Schneck <dennisschn...@web.de> wrote:Hello,how to get an integer value from a bash script if using "extend" in /etc/snmp/snmpd.conf ?extendTempOfRoom1
/scripts/get_TempOfRoom1
.shgot only STRING but no INTEGERNET-SNMP-EXTEND-MIB::nsExtendOutput1Line."TempOfRoom1" = STRING: 2210
like to get:NET-SNMP-EXTEND-MIB::nsExtendResult."TempOfRoom1
" = INTEGER: 2210 insted of "NET-SNMP-EXTEND-MIB::nsExtendOutput1Line."TempOfRoom1" = STRING: 2210
"
PJH
_______________________________________________ Net-snmp-users mailing list Net-snmp-users@lists.sourceforge.net Please see the following page to unsubscribe or change other options: https://lists.sourceforge.net/lists/listinfo/net-snmp-users