Page 1 of 2

as pnp4nagios do generate the graph of my script?

Posted: Sat Apr 18, 2015 9:23 am
by alexprinou
I created a script shell script to get the information on my host mikrotik, and I wonder how do I generate the performace date for pnp4nagios generate the graph.
follows the code:
SSH output = $ ssh [email protected] "/ monitor-traffic interface interface = interfaceuniao once" | grep rx-bits-per-second | sed 's /% //'
# IFS = "";
#declare -a Array = ($ outputSSH)
#output = {$ array [1]}
if ["$ output" = "rx-bits-per-second: 10.0Mbps!"]; Then
echo "OK $ output"
exit 0;
elif ["$ output" == "rx-bits-per-second: 10.0Mbps"]; Then
echo "$ output Critical"
exit 2;
else
echo "Warning $ output"
exit 1;
fi
exit 3;
#exit $ STATE_OK

Return code of linux:
nagios:/usr/local/nagios/libexec# ./check_traffic_uniao_rx_centralfazendas
rx-bits-per-second: 174.0kbps
OK

Re: as pnp4nagios do generate the graph of my script?

Posted: Mon Apr 20, 2015 9:51 am
by tmcdonald
You need to supply properly-formatted perfdata at the end of your output:

https://nagios-plugins.org/doc/guidelines.html#AEN200

Re: as pnp4nagios do generate the graph of my script?

Posted: Mon Apr 20, 2015 7:37 pm
by Box293
I did a talk on this at the Nagios World Conference, you can watch it here:

https://www.youtube.com/watch?v=kqA2KcpUFg4
http://www.slideshare.net/nagiosinc/tro ... and-graphs

I might make it easier to understand.

Re: as pnp4nagios do generate the graph of my script?

Posted: Thu Apr 23, 2015 4:17 pm
by alexprinou
dear friends, that and my first script for Nagios took a look in the documentation even more unable to generate the performance date for pnp4nagios generate the chart you could help me with a clear example of how to do?

Re: as pnp4nagios do generate the graph of my script?

Posted: Thu Apr 23, 2015 4:45 pm
by abrist
As the guidelines state (https://nagios-plugins.org/doc/guidelines.html#AEN200):
Nagios 3 and newer will concatenate the parts following a "|" in a) the first line output by the plugin, and b) in the second to last line, into a string it passes to whatever performance data processing it has configured. (Note that it currently does not insert additional whitespace between both, so the plugin needs to provide some to prevent the last pair of a) and the first of b) getting run together.) Please refer to the Nagios documentation for information on how to configure such processing. However, it is the responsibility of the plugin writer to ensure the performance data is in a "Nagios Plugins" format. This is the expected format:

'label'=value[UOM];[warn];[crit];[min];[max]
You need to add the performance data to the end of your return string. You will need to clean up the output pulled from your device as the performance data does not support alpha strings as a performance data value.
For example, the following line:

Code: Select all

echo "OK $output"
Should be changed to:

Code: Select all

echo "OK $output | rx-bits-per-second=$value"
Where $value would be "174.0" in your example. You will need to clean up the output so that just the number from the check is loaded into the $value in the performance data.

Re: as pnp4nagios do generate the graph of my script?

Posted: Thu Apr 23, 2015 6:51 pm
by Box293
When modifying plugins to generate performance data, sometimes you might have some errors in the output and realize it a bit later. After fixing the problem in your plugin you may still have issues with the graphs not working.

In these situations, delete the .rrd and .xml files that were generated so the .rrd files are created from scratch. This ensures you are testing the graphs with the latest output from the plugin.

Re: as pnp4nagios do generate the graph of my script?

Posted: Fri Apr 24, 2015 11:19 am
by alexprinou
dear friends I modified the script in bash runs without errors in the nagios return critical.
code:
# Bash -x check_traffic guapirama_tx_central farms
SSH output = $ ssh [email protected] "/ monitor-traffic interface interface = interfaceguapirama once" | grep tx-bits-per-second | sed 's /% //'> tx-guapirama.txt
value = 1024
comp = 18432
output = $ (sed 's / tx-bits-per-second: //; s / Mbps //; s / kbps //' tx-guapirama.txt)
output = $ (echo $ output | cut -d -f 1.)
show = $ (sed 's / tx-bits-per-second: // g' tx-guapirama.txt)
if [$ output -g 18]; then echo "$ Ok shows" exit 0;
elif [$ output -l 18]; Then
calc = $ [$ output * $ value]
if [$ calc -l $ comp]; then
echo "$ Ok shows" exit 0;
else echo "$ Critical shows" exit 2;
fi
else echo "$ Warning shows" exit 1;
fi
exit 3;

good to have this script Graphical this correct? or missing something.
from what I understand the output of commands.cfg will be something like
command_line $ USER1 $ / check_snmp -H $ HostAddress $ -C publicnovanet .1.3.6.1.4.1.14988.1.1.1.2.1.14.212.202.109.17.95.10.5 -o -w, -c -66, -74
more as I place my script pass this information?
I want Nagios alarm if the data TRANSMISSION move from 18Mbps

script of return:
nagios / usr / local / nagios / libexec # ./check_traffic_guapirama_tx_centralfazendas
Ok 4.3Mbps
nagios / usr / local / nagios / libexec #

Re: as pnp4nagios do generate the graph of my script?

Posted: Fri Apr 24, 2015 2:18 pm
by abrist
Please reread my post and the associated guidelines. You need to output a "pipe" character ( "|" ) after your status output, and then a label for the perfrormance data track, and equals sign ( "=" ) and then the value. Try appending your status output with "| rx=$output". for example:

Code: Select all

[snip]
if [$ calc -l $ comp]; then
echo "$ Ok shows| rx=$output" exit 0;
else echo "$ Critical shows | rx=$output" exit 2;
fi
else echo "$ Warning shows | rx=$output" exit 1;
fi
exit 3;
Of this still does not work, try seding out the "Mbps" from the output used for the performance data value.

Re: as pnp4nagios do generate the graph of my script?

Posted: Wed Apr 29, 2015 8:48 am
by alexprinou
DEAR FRIENDS able GENERATING GRAPHIC NAGIOS NO THANKS TO HELP YOU, MY WHEEL PLUGIN NORMAL IN A NETWORK EQUIPMENT WHEN ADD IN OTHER EQUIPMENT HE RETURNS uknow ERROR.

FOLLOW THE CODE:

# bash -x check_ccq_alvorada_rx_18
outputSSH=$ ssh [email protected] "/interface wireless monitor 1 once"|grep rx-ccq|sed 's/%//' > ccq-rx-alvorada-18.txt
output=$(sed 's/rx-ccq://g' ccq-rx-alvorada-18.txt)
if [ $output -ge 85 ] ; then
echo "$output % | ccqrx=$output"
exit 0;
elif [ $output -le 85 ]; then
echo "$output % | ccqrx=$output"
exit 2;
else
echo "ERROR - SEM RETORNO NO ARQUIVO ccq-rx-alvorada-18.txt"
exit 1;
fi
exit 3;



CODE OF RETURN:

nagios:/usr/local/nagios/libexec# ./check_ccq_alvorada_rx_18
: esperado expressão de número inteiro 99
: esperado expressão de número inteiro 99
ERROR - SEM RETORNO NO ARQUIVO ccq-rx-alvorada-18.txt
nagios:/usr/local/nagios/libexec#

FILE GENERATED BY NAGIOS:

nagios:/usr/local/nagios/libexec# cat /tmp/ccq-rx-alvorada-18.txt
nagios:/usr/local/nagios/libexec#

Re: as pnp4nagios do generate the graph of my script?

Posted: Wed Apr 29, 2015 10:13 am
by Box293
So it looks like your plugin is creating this file:

ccq-rx-alvorada-18.txt

When you were testing I assume you did your testing as the user root.

When the nagios monitoring engine goes to run the command, it does this as the user nagios.

So what is happening is the user nagios probably doesn't have permissions to the file ccq-rx-alvorada-18.txt.

Delete the file so the nagios user creates it with the correct permissions OR change the permissions on the file so the nagios user can update it.

Does this fix your problem?