Custom Plugin

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
haile711
Posts: 197
Joined: Thu May 28, 2015 7:36 am

Custom Plugin

Post by haile711 »

Hey Guys,

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
this is the result from running the script, but this isnt what i really want.
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
Im stuck trying to iterate through the for loop and get all the status to be on the same line.

Something like this
STATUS: OK HTTP Response 200 for 10.xx.xx.xx, 10.xx.xx.xx, 10.xx.xx.xx, etc ..
STATUS: NOT OK HTTP Response 404 for 10.xx.xx.xx, 10.xx.xx.xx, 10.xx.xx.xx, etc..
Can you guys help me out.

Thanks

Hai
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: Custom Plugin

Post by tmcdonald »

While we generally speaking do not provide assistance with custom plugins, I can give the following advice:
  • You will want to put all the IPs and states into an array and iterate over that array, checking if any are not 200 (or whatever your criteria is)
  • This would be much easier in a language like Python since it has better functions for dealing with arrays (which is essentially what you are looking to make)
Former Nagios employee
haile711
Posts: 197
Joined: Thu May 28, 2015 7:36 am

Re: Custom Plugin

Post by haile711 »

thxs for the suggestion tmcdonald, you can close this thread
kyang

Re: Custom Plugin

Post by kyang »

Sounds good!

If you have any more questions, feel free to create another thread!

Thank you for using the Nagios Support Forum!
Locked