Page 1 of 1

NRPE: Custom plugin

Posted: Tue May 08, 2018 5:45 am
by lexer
Hello!
I had make own custom plugin on Bash that checks *.txt file to control quantity of messages in DB.
Here it is:

Code: Select all

#!/bin/bash
msgs=`cat msgs_stats.txt | tail -1 | awk '{print $5}'`
case $msgs in
[1000-99999999999999999999999999999999999999]*)
echo "OK - $msgs messages in DB"
exit 0
;;
[1-999]*)
echo "WARNING - $msgs messages in DB"
exit 1
;;
[0]*)
echo "CRITICAL - $msgs messages in DB"
exit 2
;;
*)
echo "UNKNOWN - $msgs messages in DB"
exit 3
;;
esac

The result is:

Code: Select all

# ./check_msg_stats.sh
OK - 1609677783 messages in DB
https://prnt.sc/jf7u7p

In Nagios it works fine except graphic data. What I have to do to draw graphics?
http://prntscr.com/jf7usc


P.S. I use Nagios XI 5.4.11

Re: NRPE: Custom plugin

Posted: Tue May 08, 2018 10:08 am
by tmcdonald
You need to output a performance data string - https://nagios-plugins.org/doc/guidelines.html#AEN200

Re: NRPE: Custom plugin

Posted: Tue May 08, 2018 10:17 am
by lexer
Can u help me with that?
I'm not a programmer and haven't necessary knowledge to implement that

Re: NRPE: Custom plugin

Posted: Tue May 08, 2018 10:25 am
by tmcdonald
If you read the documentation it will make sense. You were able to get most of the way there in bash, the rest is just adding | msgs=$msgs to your output, basically. Read the docs, try some things and come back with specific questions about what is not working, and we can help with that.

Re: NRPE: Custom plugin

Posted: Tue May 08, 2018 1:50 pm
by lexer
I almost make it by own, by adding to output only | $msgs.
Now it's working as I need.
Thanks a lot=)

Re: NRPE: Custom plugin

Posted: Wed May 09, 2018 9:04 am
by tmcdonald
No problem. Mind if I close this up?

Re: NRPE: Custom plugin

Posted: Fri May 11, 2018 1:34 am
by lexer
Hello.
One more question. Now my script looks like that:

Code: Select all

#!/bin/bash
msgs=`cat /home/wialon/wlocal/storage/ms/msgs_stats.txt | tail -1 | awk '{print $5}'`
case $msgs in
[1000-99999999999999999999999999999999999999]*)
echo "OK - $msgs messages in DB | msgs=$msgs"
exit 0
;;
[1-999]*)
echo "WARNING - $msgs messages in DB | msgs=$msgs"
exit 1
;;
[0]*)
echo "CRITICAL - $msgs messages in DB | msgs=$msgs"
exit 2
;;
*)
echo "UNKNOWN - $msgs messages in DB | msgs=$msgs"
exit 3
;;
esac
When zero messages should be Critical status, but in for some reason it wasn't.
What I should change?

Re: NRPE: Custom plugin

Posted: Fri May 11, 2018 3:08 pm
by cdienger
[1000-99999999999999999999999999999999999999]*)
echo "OK - $msgs messages in DB | msgs=$msgs"
exit 0
;;
[1-999]*)
The ranges are not valid regex or at least are not doing what you think they should. Here are a couple resources to help:

https://regex101.com
http://gamon.webfactional.com/regexnume ... generator/