I need to monitor the network tunnel status,the value is "ACTIVE" "DOWN" "CRASHED",so i need to convert it to numeric。
I wrote a .sh script,it should display "1",but it display "0"
my script:
networktunnel.sh
#!/bin/shdf
status=$(snmpwalk -v 2c -c $snmpcommunity $hostname $OID | awk -F':' '{print $NF}' | awk -F'"' '{print $2}')
case $status in
ACTIVE) print "1"
;;
DOWN) print "2"
;;
CRASHED) print "3"
;;
esac
Data input Method configuration :
Data Input Methods:networktunnel
Input Type:Script/Command
Input String:<path_cacti>/scripts/test.sh <snmpcom><host><OID>
Input Fields:snmpcom、host、OID
output:Status
How to write a script to covert string to numeric
Moderators: Developers, Moderators
-
- Posts: 2
- Joined: Tue Jul 09, 2013 4:22 am
How to write a script to covert string to numeric
- Attachments
-
- display
- 2013-07-09_181053.jpg (37.89 KiB) Viewed 672 times
-
- configuration
- 2013-07-09_180431.jpg (109.22 KiB) Viewed 672 times
-
- Posts: 2
- Joined: Tue Jul 09, 2013 4:22 am
Re: How to write a script to covert string to numeric
I had solved this problem.
script:
#!/bin/shdf
snmpcom=$1
hostname=$2
OID=$3
status=$(snmpwalk -v 2c -c $snmpcom $hostname $OID | awk -F':' '{print $NF}' | awk -F'"' '{print $2}')
case $status in
ACTIVE) No=1
print "status:$No"
;;
DOWN) No=2
print "status:$No"
;;
CRASHED) No=3
print "status:$No"
;;
esac
congiuration:
script:
#!/bin/shdf
snmpcom=$1
hostname=$2
OID=$3
status=$(snmpwalk -v 2c -c $snmpcom $hostname $OID | awk -F':' '{print $NF}' | awk -F'"' '{print $2}')
case $status in
ACTIVE) No=1
print "status:$No"
;;
DOWN) No=2
print "status:$No"
;;
CRASHED) No=3
print "status:$No"
;;
esac
congiuration:
- Attachments
-
- my configuration
- 2013-07-10_174319.jpg (98.85 KiB) Viewed 655 times
Who is online
Users browsing this forum: No registered users and 0 guests