Custom Plugin
Posted: Thu Oct 26, 2017 10:25 am
Hey Guys,
I am trying to write this plugin to check all the api validation
this is the result from running the script, but this isnt what i really want.
Something like this
Thanks
Hai
I am trying to write this plugin to check all the api validation
Code: Select all
#!/bin/bash
libexec="/usr/local/nagios/libexec"
#hostname=$1
hostname="hostname1 hostname2 hostname3 hostname4 hostname5 hostname6"
nagios_ok=0
nagios_warning=1
nagios_critical=2
nagios_unknown=3
#if [[ $hostname == "" ]]; then
# echo "please enter a host to check"
# exit $nagios_unknown
#fi
for host in $hostname;
do
output=$(curl -s -i -H 'accept: application/json' -H 'x-xxx-webservice-client-id: apimonitoring' "http://$host/v4/catalog/category/5545" -H 'Host:api-local.dal.xxx.com' | grep "HTTP/1.1" | awk '{print $2}')
if [[ $output == "200" ]]; then
echo "STATUS: OK HTTP Response $output for $host"
# exit $nagios_ok
else
echo "STATUS: NOT OK HTTP Response $output for $host"
# exit $nagios_critical
fi
done
Im stuck trying to iterate through the for loop and get all the status to be on the same line.STATUS: OK HTTP Response 200 for 10.xx.xx.xx
STATUS: OK HTTP Response 200 for 10.xx.xx.xx
STATUS: OK HTTP Response 200 for 10.xx.xx.xx
STATUS: NOT OK HTTP Response for 10.xx.xx.xx
STATUS: OK HTTP Response 200 for 10.xx.xx.xx
STATUS: NOT OK HTTP Response for 10.xx.xx.xx
STATUS: NOT OK HTTP Response for 10.xx.xx.xx
STATUS: NOT OK HTTP Response 404 for 10.xx.xx.xx
STATUS: NOT OK HTTP Response 404 for 10.xx.xx.xx
STATUS: NOT OK HTTP Response 404 for 10.xx.xx.xx
STATUS: NOT OK HTTP Response 404 for 10.xx.xx.xx
STATUS: NOT OK HTTP Response 404 for 10.xx.xx.xx
STATUS: OK HTTP Response 200 for 10.xx.xx.xx
STATUS: OK HTTP Response 200 for 10.xx.xx.xx
STATUS: OK HTTP Response 200 for 10.xx.xx.xx
Something like this
STATUS: OK HTTP Response 200 for 10.xx.xx.xx, 10.xx.xx.xx, 10.xx.xx.xx, etc ..
Can you guys help me out.STATUS: NOT OK HTTP Response 404 for 10.xx.xx.xx, 10.xx.xx.xx, 10.xx.xx.xx, etc..
Thanks
Hai