Hey there!Box293 wrote:Can you upload the plugin please so I can have a play.
In my original post, I pasted the original code. Is this what you are looking for?
Hey there!Box293 wrote:Can you upload the plugin please so I can have a play.
Hey there,Box293 wrote:Can you upload the most recent code please.
Code: Select all
#!/bin/bash
# Nagios plugin to monitor a MOBOTIX camera's recording status, as well as other fields.
# The script will download the http://<camip>/control/camerainfo?json file and store
# it locally to /tmp/$FILENAME.txt so that multiple curl are not required.
#
# The script takes several parameters
# - IP of the camera
# - camera username, needs rights to access /control/camera
# - camera password
###########################################################################################
#Set Script Name variable
#SCRIPT=`basename ${BASH_SOURCE[0]}`
# Initialize variables
USER="admin"
PW="meinsm"
# parameters for the script
# check each parameter to be set, else use default values
# quit on no IP set!
function HELP {
echo "check_mxfw - check the flash wear of a MOBOTIX camera"
echo "# arguments are : "
echo "# -H ip "
echo "# -u username "
echo "# -p password "
exit 0;
}
# check number of arguments, of no are given, show help
NUMARGS=$#
if [ $NUMARGS -eq 0 ]; then
HELP
fi
# Process arguments
while getopts ":H:u:p:?" OPTIONS
do
case $OPTIONS in
H) #set IP
IP=$OPTARG
;;
u) # check for username, else set default
USER=$OPTARG
;;
p) # check for password, else set default
PW=$OPTARG
;;
*) # ungecognized option, show help
HELP
;;
?) # show help
HELP
;;
esac
done
shift $((OPTIND-1))
#DEBUG
#echo "IP : $IP, USER : $USER, PW : $PW, WARNING : $WARNING, CRITICAL : $CRITICAL"
DATE=$(date | awk -F ' ' '{print $4}' | sed 's/\://g';)
TEMPNAME=$(echo $IP|sed 's/\./\_/g')
FILENAME=$(echo $TEMPNAME-$DATE)
#echo $TEMPNAME
#echo $FILENAME
INFO=$(curl http://$USER:$PW@$IP/control/camerainfo?json -o "/tmp/$FILENAME.txt"| grep -e "Model" -e "Factory IP Address" -e "Hardware" -e "Image Sensor" -e "Software" -e "Current Uptime" -e "Temperature" | awk '!/Hardware Gains/' | awk -F '"' '{print $2, " - ", $4}')
INFOERROR=$(cat /tmp/$FILENAME.txt | grep "couldn't connect to host")
#if [[ $INFOERROR == "" ]]; then
# echo "CRITICAL - Cannot connect to camera!"
# exit 2
#fi
### The camera info has been scraped and stored in /tmp/$FILENAME.txt.
### We will now grep this local file for the rest of our info, instead
### of doing multiple HTTP Requests to curl the info.
#Pull static information from the camera status page
#CAMINFO=$(cat /tmp/$FILENAME.txt | grep -e "Model" -e "Factory IP Address" -e "Hardware" -e "Image Sensor" -e "Software" -e "Current Uptime" -e "Camera Name" -e "Link Speed" | awk '!/Hardware Gains/' | awk -F '"' '{print $2, " - ", $4}' )
CAMINFO=$(cat /tmp/$FILENAME.txt | grep -e "Model" -e "Factory IP Address" -e "Hardware" -e "Image Sensor" -e "Software" -e "Current Uptime" -e "Camera Name" -e "Link Speed" -e "Temperature" | awk '!/Hardware Gains/' | awk -F '"' '{printf "%-30s %s\n", $2, $4}' )
###################################
# Recording Settings
###################################
RECTYPE=$(cat /tmp/$FILENAME.txt | grep "Type" | awk -F '"' '{print $4}')
RECPATH=$(cat /tmp/$FILENAME.txt | grep "Path" | awk -F '"' '{print $4}')
RECERROR=$(cat /tmp/$FILENAME.txt | grep "Status" | awk -F '"' '{print $4}')
#DEBUG
#echo "RECORDING TYPE = $RECTYPE"
#echo "RECORDING PATH = $RECPATH"
#echo "RECORDING ERROR = $RECERROR"
###################################
# Storage Usage
###################################
CURRENTUSAGE=$(cat /tmp/$FILENAME.txt | grep "Current Usage" | awk -F '"' '{print $4}')
MAXSTORAGE=$(cat /tmp/$FILENAME.txt | grep "Maximum Size" | sed 's/[A-Za-z]*//g' | awk -F '"' '{print $4}')
MAXSTORAGEGB=$(($MAXSTORAGE / 1024))
#DEBUG
#echo "CURRENT STORAGE = $CURRENTUSAGE"
#echo "MAXIMUM STORAGE = $MAXSTORAGE"
#echo "MAXIMUM STORAGE - GB = $MAXSTORAGEGB"
###################################
# Display Information
###################################
#echo "-------------------- "
#echo "Camera Information"
#echo "-------------------- "
#echo "$CAMINFO"
#echo "-------------------- "
#echo "Storage Information"
#echo "-------------------- "
#echo "Recording Type $RECTYPE"
#echo "Recording Path $RECPATH"
#echo "Recording Status $RECERROR"
#echo "Current Usage $CURRENTUSAGE"
#echo "Maximum Storage Space $MAXSTORAGEGB GB"
exit_message=""
exit_message+="CAMERA INFORMATION\n"
exit_message+="------------------\n"
exit_message+="$CAMINFO\n"
exit_message+="------------------\n"
exit_message+="Recording Type $RECTYPE"
echo $exit_message
###################################
# Delete $FILENAME.txt
###################################
rm -f /tmp/$FILENAME.txt
###################################
# NAGIOS Logic Section
###################################
if [[ $RECERROR == "- checking for serverpath failed!" ]]; then
echo "CRITICAL - Cannot find server path!"
exit 2
elif [[ $RECERROR == *"- mount failed!"* ]]; then
echo "CRITICAL - Failed to mount Network Share!"
exit 2
elif [[ $RECERROR == "*" ]]; then
echo "CRITICAL - Unknown Error: $RECERROR"
exit 2
else
echo "OK - Recording OK!"
exit 0
fi
Code: Select all
CAMINFO=$(cat /tmp/$FILENAME.txt | grep -e "Model" -e "Factory IP Address" -e "Hardware" -e "Image Sensor" -e "Software" -e "Current Uptime" -e "Camera Name" -e "Link Speed" -e "Temperature" | awk '!/Hardware Gains/' | awk -F '"' '{printf "%-30s %s\n", $2, $4}' )
Code: Select all
$
CAMINFO=$(cat /tmp/$FILENAME.txt | grep -e "Model\n")
CAMINFO+=$(cat /tmp/$FILENAME.txt | grep -e "Factory IP Address\n")
Code: Select all
CAMINFO=$(cat /tmp/$FILENAME.txt | grep -e "Model"\n)
CAMINFO+=$(cat /tmp/$FILENAME.txt | grep -e "Factory IP Address"\n)
Which part of my issue are you referring to here and where do I insert this?tmcdonald wrote:Newlines likely won't display as you intend in an HTML page - change the \n to <br /> to be an HTML break, and if that renders then all you need to do is go to Admin -> System Settings, and check Allow HTML Tags in Host/Service Status.
Code: Select all
/usr/lib/nagios/plugins/testmobotix.sh: command substitution: line 91: syntax error near unexpected token `)'
/usr/lib/nagios/plugins/testmobotix.sh: command substitution: line 91: `cat /tmp/$FILENAME.txt | grep -e "Model"<br />)'
/usr/lib/nagios/plugins/testmobotix.sh: command substitution: line 92: syntax error near unexpected token `)'
/usr/lib/nagios/plugins/testmobotix.sh: command substitution: line 92: `cat /tmp/$FILENAME.txt | grep -e "Factory IP Address"<br />)'
/usr/lib/nagios/plugins/testmobotix.sh: line 110: / 1024: syntax error: operand expected (error token is "/ 1024")
Code: Select all
/usr/lib/nagios/plugins/testmobotix.sh: line 90: syntax error near unexpected token `newline'
/usr/lib/nagios/plugins/testmobotix.sh: line 90: `CAMINFO=$(cat /tmp/$FILENAME.txt | grep -e "Model")</ br>'
I'm revisiting this, as I wanted to add things like perf data for things etc.Box293 wrote:What was the final solution, it may help others in the future.
Code: Select all
root@raspberrypi:/usr/lib/nagios/plugins# ./check_mobotix.sh.orig -H 192.168.1.251 -u admin -p Empire99 -w 10 -c 12
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 3693 0 3693 0 0 1178 0 --:--:-- 0:00:03 --:--:-- 1179
--------------------
Camera Information
--------------------
Model M25M-Secure
Hardware T2r4.3b, 806 MHz
Image Sensor color 5MP
Software MX-V4.4.0.31 (2016-04-05)
Current Uptime 1 day 21:32:14
Camera Name EmpireComm-BackLot
Link Speed and Duplex 100Mbps / Full Duplex
Camera Temperature 25°C (77°F)
--------------------
Storage Information
--------------------
Recording Type CIFS File Server
Recording Path \\\\192.168.1.2\\Mobotix
Recording Status
Current Usage 1.1 GBytes (0.0%)
Maximum Storage Space 4.00 GB
CRITICAL - Camera is too hot! 25°C|temp=25
Code: Select all
root@raspberrypi:/usr/lib/nagios/plugins# /usr/local/nrdp/clients/nrds/nrds.pl -H 'Derek Test'
/usr/lib/nagios/plugins/check_mobotix.sh.orig: 26: /usr/lib/nagios/plugins/check_mobotix.sh.orig: function: not found
ERROR: STDIN must be either 3 or 4 fields long, I found 1
ERROR: STDIN must be either 3 or 4 fields long, I found 1
ERROR: STDIN must be either 3 or 4 fields long, I found 1
ERROR: STDIN must be either 3 or 4 fields long, I found 1
ERROR: STDIN must be either 3 or 4 fields long, I found 1
Code: Select all
#!/bin/bash
# Nagios plugin to monitor a MOBOTIX camera's recording status, as well as other fields.
# The script will download the http://<camip>/control/camerainfo?json file and store
# it locally to /tmp/$FILENAME.txt so that multiple curl are not required.
#
# The script takes several parameters
# - IP of the camera
# - camera username, needs rights to access /control/camera
# - camera password
###########################################################################################
#Set Script Name variable
#SCRIPT=`basename ${BASH_SOURCE[0]}`
# Initialize variables
USER="admin"
PW="meinsm"
CRITICALTEMP=0
WARNINGTEMP=0
# parameters for the script
# check each parameter to be set, else use default values
# quit on no IP set!
function HELP {
echo "check_mxfw - check the flash wear of a MOBOTIX camera"
echo "# arguments are : "
echo "# -H ip "
echo "# -u username "
echo "# -p password "
echo "# -c critical temp in celsius "
echo "# -w warning temp in celsius "
exit 0;
}
# check number of arguments, of no are given, show help
NUMARGS=$#
if [ $NUMARGS -eq 0 ]; then
HELP
fi
# Process arguments
while getopts ":H:u:p:w:c:?" OPTIONS
do
case $OPTIONS in
H) #set IP
IP=$OPTARG
;;
u) # check for username, else set default
USER=$OPTARG
;;
p) # check for password, else set default
PW=$OPTARG
;;
c) # check for critical temp
CRITICALTEMP=$OPTARG
;;
w) # check for warning temp
WARNINGTEMP=$OPTARG
;;
*) # ungecognized option, show help
HELP
;;
?) # show help
HELP
;;
esac
done
shift $((OPTIND-1))
#DEBUG
#echo "IP : $IP, USER : $USER, PW : $PW, WARNING : $WARNING, CRITICAL : $CRITICAL"
DATE=$(date | awk -F ' ' '{print $4}' | sed 's/\://g';)
TEMPNAME=$(echo $IP|sed 's/\./\_/g')
FILENAME=$(echo $TEMPNAME-$DATE)
#echo $TEMPNAME
#echo $FILENAME
INFO=$(curl http://$USER:$PW@$IP/control/camerainfo?json -o "/tmp/$FILENAME.txt"| grep -e "Model" -e "Factory IP Address" -e "Hardware" -e "Image Sensor" -e "Software" -e "Current Uptime" -e "Temperature" | awk '!/Hardware Gains/' | awk -F '"' '{print $2, " - ", $4}')
### The camera info has been scraped and stored in /tmp/$FILENAME.txt.
### We will now grep this local file for the rest of our info, instead
### of doing multiple HTTP Requests to curl the info.
#Pull static information from the camera status page
#CAMINFO=$(cat /tmp/$FILENAME.txt | grep -e "Model" -e "Factory IP Address" -e "Hardware" -e "Image Sensor" -e "Software" -e "Current Uptime" -e "Camera Name" -e "Link Speed" | awk '!/Hardware Gains/' | awk -F '"' '{print $2, " - ", $4}' )
CAMINFO=$(cat /tmp/$FILENAME.txt | grep -e "Model" -e "Factory IP Address" -e "Hardware" -e "Image Sensor" -e "Software" -e "Current Uptime" -e "Camera Name" -e "Link Speed" -e "Temperature" | awk '!/Hardware Gains/' | awk -F '"' '{printf "%-30s %s\n", $2, $4}' )
###################################
# Recording Settings
###################################
RECTYPE=$(cat /tmp/$FILENAME.txt | grep "Type" | awk -F '"' '{print $4}')
RECPATH=$(cat /tmp/$FILENAME.txt | grep "Path" | awk -F '"' '{print $4}')
RECERROR=$(cat /tmp/$FILENAME.txt | grep -m 1 "Status" | awk -F '"' '{print $4}')
TEMP=$(cat /tmp/$FILENAME.txt | grep "Temperature" | awk -F '"' '{print $4}')
TEMPARR=($TEMP)
CELSIUS=${TEMPARR[0]//[^0-9]*}
#DEBUG
#echo "RECORDING TYPE = $RECTYPE"
#echo "RECORDING PATH = $RECPATH"
#echo "RECORDING ERROR = $RECERROR"
###################################
# Storage Usage
###################################
CURRENTUSAGE=$(cat /tmp/$FILENAME.txt | grep "Current Usage" | awk -F '"' '{print $4}')
MAXSTORAGE=$(cat /tmp/$FILENAME.txt | grep "Maximum Size" | sed 's/[A-Za-z]*//g' | awk -F '"' '{print $4}')
MAXSTORAGEGB=$(awk "BEGIN {printf \"%.2f\",${MAXSTORAGE} / 1024}")
#DEBUG
#echo "CURRENT STORAGE = $CURRENTUSAGE"
#echo "MAXIMUM STORAGE = $MAXSTORAGE"
#echo "MAXIMUM STORAGE - GB = $MAXSTORAGEGB"
###################################
# Display Information
###################################
echo "-------------------- "
echo "Camera Information"
echo "-------------------- "
echo "$CAMINFO"
echo "-------------------- "
echo "Storage Information"
echo "-------------------- "
echo "Recording Type $RECTYPE"
echo "Recording Path $RECPATH"
echo "Recording Status $RECERROR"
echo "Current Usage $CURRENTUSAGE"
echo "Maximum Storage Space $MAXSTORAGEGB GB"
###################################
# Delete $FILENAME.txt
###################################
rm -f /tmp/$FILENAME.txt
###################################
# NAGIOS Logic Section
###################################
#if [[ $RECERROR == "- checking for serverpath failed!" ]]; then
# echo "CRITICAL - Cannot find server path!"
# exit 2
#elif [[ $RECERROR == *"- mount failed!"* ]]; then
# echo "CRITICAL - Failed to mount Network Share!"
# exit 2
#elif [[ $RECERROR == "*" ]]; then
# echo "CRITICAL - Unknown Error: $RECERROR"
# exit 2
#if [ -z ${RECERROR+x} ]; then
if [ $CELSIUS -gt $CRITICALTEMP ] && [ $CRITICALTEMP -gt 0 ]; then
echo "CRITICAL - Camera is too hot! $CELSIUS°C|temp=$CELSIUS"
exit 2
elif [ $CELSIUS -gt $WARNINGTEMP ] && [ $WARNINGTEMP -gt 0 ]; then
echo "WARNING - Camera could overheat soon! $CELSIUS°C"
exit 1
elif [[ -z $RECERROR ]]; then
echo "OK - Recording OK!"
exit 0
else
echo "CRITICAL $RECERROR"
exit 2
fi