Aw: Re: Re: bash script - extend - output as integer

2020-04-22 Thread Dennis Schneck

Sorry Paul,

changed my script now it looks like it works!

 

Thank you!

 

 

 

Gesendet: Mittwoch, 22. April 2020 um 13:04 Uhr
Von: "Dennis Schneck" 
An: net-snmp-users@lists.sourceforge.net
Betreff: Aw: Re: Re: bash script - extend - output as integer




 

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

 


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" 
An: "Dennis Schneck" 
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 

so 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)  - quick example of this third:

 


---

#!/bin/bash -u
val=${1:-0}
scaled=$((255*val/))
exit ${scaled}
---

$ for x in 1 10 39 40 41 250 500 5000 7500 ; 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
 -> 255



 

Note each unit of output represents a range of about 40 input units. If you can 'tighten' that 0- 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 1 2 3 4; do ./scaled.sh ${x}; echo "${x} -> $?"; done
1 -> 255
2 -> 254
3 -> 253
4 -> 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



https://docs.fedoraproject.org/en-US/Fedora/18/html/System_Administrators_Guide/sect-System_Monitoring_Tools-Net-SNMP-Extending.html

 

> 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 ?

 

extend TempOfRoom1 /scripts/get_TempOfRoom1.sh

 

got only STRING but no INTEGER

 


NET-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





___
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


Aw: Re: Re: bash script - extend - output as integer

2020-04-22 Thread Dennis Schneck

 

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

 


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" 
An: "Dennis Schneck" 
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  wrote:




 

Hello Paul,

thanks but exit code only max 255 (or I am wrong?) but I need 4 digets for example 

so 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)  - quick example of this third:

 


---

#!/bin/bash -u
val=${1:-0}
scaled=$((255*val/))
exit ${scaled}
---

$ for x in 1 10 39 40 41 250 500 5000 7500 ; 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
 -> 255



 

Note each unit of output represents a range of about 40 input units. If you can 'tighten' that 0- 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 1 2 3 4; do ./scaled.sh ${x}; echo "${x} -> $?"; done
1 -> 255
2 -> 254
3 -> 253
4 -> 252


 

 







Gesendet: Dienstag, 21. April 2020 um 15:36 Uhr
Von: "Paul Herring" 
An: "Dennis Schneck" 
Cc: net-snmp-users@lists.sourceforge.net
Betreff: Re: bash script - extend - output as integer



https://docs.fedoraproject.org/en-US/Fedora/18/html/System_Administrators_Guide/sect-System_Monitoring_Tools-Net-SNMP-Extending.html

 

> 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  wrote:




 

Hello,

how to get an integer value from a bash script if using "extend" in /etc/snmp/snmpd.conf ?

 

extend TempOfRoom1 /scripts/get_TempOfRoom1.sh

 

got only STRING but no INTEGER

 


NET-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


Aw: Re: Re: bash script - extend - output as integer

2020-04-21 Thread Dennis Schneck
Hi Paul,

thank you very much.


 

I will try to write a agent!

 

 

 

Gesendet: Dienstag, 21. April 2020 um 23:21 Uhr
Von: "Paul Herring" 
An: "Dennis Schneck" 
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  wrote:




 

Hello Paul,

thanks but exit code only max 255 (or I am wrong?) but I need 4 digets for example 

so 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)  - quick example of this third:

 


---

#!/bin/bash -u
val=${1:-0}
scaled=$((255*val/))
exit ${scaled}
---

$ for x in 1 10 39 40 41 250 500 5000 7500 ; 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
 -> 255



 

Note each unit of output represents a range of about 40 input units. If you can 'tighten' that 0- 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 1 2 3 4; do ./scaled.sh ${x}; echo "${x} -> $?"; done
1 -> 255
2 -> 254
3 -> 253
4 -> 252


 

 







Gesendet: Dienstag, 21. April 2020 um 15:36 Uhr
Von: "Paul Herring" 
An: "Dennis Schneck" 
Cc: net-snmp-users@lists.sourceforge.net
Betreff: Re: bash script - extend - output as integer



https://docs.fedoraproject.org/en-US/Fedora/18/html/System_Administrators_Guide/sect-System_Monitoring_Tools-Net-SNMP-Extending.html

 

> 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  wrote:




 

Hello,

how to get an integer value from a bash script if using "extend" in /etc/snmp/snmpd.conf ?

 

extend TempOfRoom1 /scripts/get_TempOfRoom1.sh

 

got only STRING but no INTEGER

 


NET-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