Created
January 20, 2012 13:03
-
-
Save skarllot/1647308 to your computer and use it in GitHub Desktop.
Zabbix external script to check Windows service via SNMP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# ----------------------------------------------------------------------------- | |
# Check service status | |
# | |
# Params: hostname, ip, community, servicename, serviceparams | |
# ----------------------------------------------------------------------------- | |
# $1 Remote IP | |
# $2 Service name | |
# $3 Service parameters | |
get_pid() | |
{ | |
PID=`snmpwalk -v2c -c $DEF_COMMUNITY $1 hrSWRunName | grep "\"$2\"" | awk '{print $1}' | awk -F. '{print $2}'` | |
if [ -z $PID ]; then | |
PID=-1 | |
fi | |
if [ ! $PID -eq -1 ] && [ ! -z $3 ] && [ ! "$3" == "-" ]; then | |
VALID=0 | |
IFS=$'\n' | |
for ipid in $PID; do | |
MATCH=`snmpwalk -v2c -c $DEF_COMMUNITY $1 hrSWRunParameters.$ipid | grep "$3" | wc -l` | |
if [ $MATCH -eq 1 ]; then | |
VALID=1 | |
break | |
fi | |
done | |
if [ $VALID -eq 0 ]; then | |
PID=-1 | |
fi | |
fi | |
} | |
# $1 Remote IP | |
# $2 Service name | |
# $3 Service parameters | |
get_status() | |
{ | |
get_pid $1 $2 $3 | |
if [ $PID -eq -1 ]; then | |
STATUS=0 | |
STATUS_DESC="stopped" | |
return | |
fi | |
STATUS=`snmpwalk -v2c -c $DEF_COMMUNITY $1 hrSWRunStatus.$PID | awk -F= '{print $2}' | awk -F: '{print $2}' | awk '{print $1}'` | |
STATUS_DESC=`echo $STATUS | awk -F\( '{print $1}'` | |
STATUS=`echo $STATUS | awk -F\( '{print $2}' | awk -F\) '{print $1}'` | |
} | |
DEF_COMMUNITY=$3 | |
get_status $2 $4 $5 | |
echo "$STATUS" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment