Writing a Nagios/Icinga Plugin using PHP

2.09.2010

Note to self: If you want to write a check plugin for Nagios / Icinga using PHP, remember the following things:

  • Start the first line of the script with #!/usr/bin/php -q
  • Don’t put any empty lines between the shebang and the opening php tag (<?php)
  • Return values are either 0 (OK), 1 (WARNING) or 2 (CRITICAL)
  • Return those values using exit(), not using return()
  • Before the exit statement, return some info using echo. Nagios / Icinga will only display the first line of the output.
Fork me on GitHub

Kommentare

[New Post] Writing a Nagios/Icinga Plugin using PHP http://blog.ich-wars-nicht.ch/2010/09/wr... – via #twitoaster

what do you know about the performance data if you write a own plugin ???

@rossixx: I don’t quite understand your question. Are you talking about the usage of PHP? Or about Nagios/Icinga plugins in general?

Nagios !

send Performance Data by the plugin.

Ah. I don’t think you can send actual performance data to Nagios. The main return value is either OK, WARNING or CRITICAL. But you can echo some string, which will be used as the status message and could be parsed.

But I might be wrong.

no. you are right. the plugin send a string back to nagiuos

first part is 0, 1, 2 or 3 | and the other part is used as performance date or what ever you want.

but my problem is how to tell the right nagios what is which part of the fu**ing post… :-(

I want to use a self-written nagios plugin by nrpe, but i get “NRPE: Unable to read output” but on the client everything is okay (test with echo $?)

@Dave: Sorry, I don’t use NRPE (in fact I don’t currently run Nagios at all), so I don’t know about that. Try to check the output and the return status of your plugin.

Hinterlasse einen Kommentar

Dein Kommentar:

XHTML: Sie dürfen folgende Tags verwenden: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">

Kategorien

Switch to our mobile site