Categories
Linux Software

Nagios Extended Notification Mail

Screenshot nagios_mail

Ersatz für die von Nagios mitgelieferte Notification-Mail.

Eigentlich bin ich kein Fan von HTML-Mails, aber CSS-Formatierungen machen eine Notification-Mail schon übersichtlicher. Es wird aber auch eine Text-Variante für Handhelds etc. mitgesendet.

UPDATE: Now available here at my github profile!

Download: nagios_mail-0.9.zip (don’t use this, use the github page!)

Installation

Nach dem kopieren der nagios_mail.php müssen nur die Nagios-Notification-Definitionen geändert werden:

# /usr/local/nagios/etc/objects/misccommands.cfg
define command{
        command_name    host-notify-by-email
        command_line    /usr/bin/php -q /opt/nagios_mail.php
        }

define command{
        command_name    notify-by-email
        command_line    /usr/bin/php -q /opt/nagios_mail.php
        }

Je nach Distribution muss evt. der PHP-Pfad angepasst werden. Update: seit Version 0.3 ist PEAR nicht mehr notwendig!

Konfiguration

Im Header der PHP-Datei kann der Absender, die Nagios-URL oder das Subject geändert werden.

FAQ

Q: i want to use ICINGA with it. Is it possible?
A: Yes, but you have to replace in Line 643 “_NAGIOS” with “_ICINGA”

Q: Notifications through Nagios/Ichinga are empty. What to check?
A: check your php.ini for variables_order = “EGPCS”, the “E” is important.

Q: Notifications through Nagios/Ichinga are still empty. What to check?
A: check nagios.cfg/icinga.cfg for the following setting: enable_environment_macros=1

Changelog

0.9.0
  outlook 2007 html compatibility (back to stoneage)
  added color for UNKNOWN state

0.8.0
  added additional header configuration
  (for example to send high-priority mails)
  improved documentation
  improved debug mode

0.7.0
  fixed multipart issue (webmailer compatibility)
  added safari header (iPhone Mail compatibility)

0.6.0
  added subject templates
  added ability to disable sections

0.5.0
  added PHP4 compatibility

0.4.0
  added test-mode (if run from command-line)
  removed php-notices

0.3.0
  added readme
  removed Mail_mime dependency
  removed css definitions for webmail compatibility
  added links to hostname

0.2.0
  changed script to object oriented programming

146 replies on “Nagios Extended Notification Mail”

Hallo, ich bekomme die Notify nicht zum laufen. Habe genau nach Anleitung die Konfiguration vorgenommen. Ich bin noch nicht so fit in Linux, aber für mich stellt sich die Frage wie die Mail versendet werden soll? Ich denke das geht aus dem PHP Code hervor, muss ich denn für das Versenden noch ein Pfad einstellen? Sprich /usr/bin/mail oder so? Danke für eine schnelle Hilfe. Oliver

Bei nagios_mail-0.3 wird die mail() Funktion von PHP benutzt. Diese sollte zumindest auf Linux-Systemen einen sendmail-wrapper zum versenden verwenden. Je nach php.ini z.B. “sendmail_path = /usr/sbin/sendmail -t -i”

In der nächsten Version werde ich mal eine Test-Funktion einbauen. Update: die aktuelle Version (0.4) hat einen Test-Modus.

Hallo Otto, danke für die schnelle Antwort. Ich habe nun einige PHP Dateien gefunden und versuche diese gerade anzupassen. Mein Problem was ich derzeitig noch habe: Ich schicke Mails über /bin/mail mit dem Postfix. Wenn ich nun auf Sendmail umsteigen möchte muss dieser deinstalliert werden, was ich nicht kann da noch andere funktionen von dem Postfix abhängig sind. Wie kann ich PHP so umstricken das er den /bin/mail benutzt?

Zu früh gefreut. nur mit der Testmail hat es funktioniert. Nicht aber aus Nagios selbst. Trotz restart des Nagios Process.

Probiere mal das Script als Nagios-User aufzurufen, evt. kommt dann eine aussagekräftigere Fehlermeldung:

su -l -s /bin/sh NAGIOSUSER
php nagios_mail.php

CONTACTEMAIL env-var is empty (not run from Nagios?) or “mail_add_to_address” not configured (Testmode) unter dem Benutzer Nagios. Klar kein Mail empfänger drin. Ich habe aber mehere empfänger in den Contacts.

Bitte nochmal mit einer Mailadresse in “mail_add_to_address” versuchen (als Nagios-User).

Hi! Sorry for writing in english but my german is not that good unfortunatly. Thanks for a great script. I have some problems though. The test works brilliant but the real notifications wont work. I do not recive anything. My config file is command.cfg and not misccommands.cfg but I guess it does not matter. I also had to use command_name notify-service-by-email and notify-host-by-email (default) and not host-notify-by-email and notify-by-email as your config showed. Maybe I missed something?

Hi,

– make sure that in Nagios configuration the “enable_environment_macros=1” setting is enabled.
– check the nagios log-file while running passive check commands
– test running the nagios_mail.php as the nagios user:

su -l -s /bin/sh NAGIOSUSER
php nagios_mail.php

Thanks for your super fast reply. Now it works great. Now I will just try to add the pnpgraphs in the mail as well.

Hey,
also ich bekomme das Script einfach nicht zum laufen.
“enable_environment_macro” ist auf 1 gesetzt.
Testmail klappt, sofern eine Mailadresse unter “mail_add_to_address” eingetragen ist. Lass ich die Mailadresse eingetragen, verschickt Nagios auch eine Testmail an die eingetragene Adresse. Nehme ich die Adresse wieder raus, kommt keine Mail an, Nagios meldet aber den Versand einer Mail. Im Sendmail-Log steht aber kein Eintrag.
Auch mir kommt es vor als ob die Macros nicht übergeben werden.
Achja, sendmail-path ist auch gesetzt.
???

Hi,

please check that the “variables_order” setting in php.ini contains an “E”, it should be something like variables_order = “EGPCS”. If the “E” is missing no Nagios-macros will be transfered to the PHP-Script.

If someone is worried about performance or security issues: you could create a seperate php.ini (like php.ini_nagios) and specify it at the command definition in nagios:

command_line /usr/bin/php -q -c /etc/php.ini_nagios /opt/nagios_mail.php

Die in der Mail angezeigte Kontaktgruppe ist nicht die Kontaktgruppe des Servers. Ich habe noch nicht herausbekommen, welche er dort nimmt.

Hallo
bekomme leider einen PHP Fehler: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or ‘}’ in nagios_mail.php on line 548.
Hat jemand eine hierzu eine Idee??

Hallo, Skript funktioniert auf Anhieb, vielen Dank für die Arbeit!
Wie kann ich einstellen, dass im Betreff der Mail zuerst der Hostname und danach der Service Typ angezeigt wird?

Vielen Dank und Gruss

Luca

Hi,

das geht derzeit nur, indem in Zeile 622 (Host) und 646 (Service) die jeweiligen Zeilen vertauscht werden. Bei Gelegenheit werde ich das mal komfortabeler gestalten…

Vielen Dank, hat funktioniert!
Wie kann ich die Contact Details und Statistics ganz ausblenden?

Danke und Gruss

Luca

Version 0.6: Das Subject kann jetzt in der Konfiguration geändert werden. Bei den Sektionen gibt es ab sofort auch einen Schalter “active” mit welchem z.B. die Kontakt-Details abgeschaltet werden können.

Hallo Otto,
ich komm nicht weiter. Mein Problem ist, dass der Nagios keine HTML-Mails versendet, die Testmail kommt aber an. Ich kann das Script als NagiosUser ausführen, in der php.ini hab ich den sendmailpfad und EGPCS eingetragen.
Hast du noch einen Tipp fuer mich?

In jedem Abschnitt der Konfiuguration gibt es einen Schalter “active” – dieser muss auf “false” gesetzt werden um eine Sektion (oder eine ganze Gruppe) zu deaktivieren. Alternativ ist es auch möglich, den Schalter “active” auf “HOST” oder “SERVICE” zu setzen, um den Abschnitt je nach Notification-Typ anzuzeigen.

Hallo, versuche es gerade in Groundwork Open Source zu integrieren und habe volgenden fehler:
/usr/local/groundwork/php/bin -q usr/local/groundwork/php/lib/php/nagios_mail.php
Error executing command (Permission denied)
Bin kein Linux guru… hast du eine Idee ?
Danke.

Ich bin so blöd !!!
/usr/local/groundwork/php/bin/php -q /usr/local/groundwork/php/lib/php/nagios_mail.php

So gehts :-)

Vielen Dank ! Super script !!!

Hallo Otto, great script — Kudos to you! :-)
I have the notifications running, but can’t seem to use the ‘Acknowledge this problem’ option. I suspect that this is due to the fact that the nagios environment (which sends out the emails) is runs as user ‘nagios’, and the recipients are not authenticated with this account as they click the link.

Is this fix-able? Is there something I can do to enable these links?

Thanks,
Jaap.

Hi Jaap,
“Acknowledge this problem” is just a link to the right place at the webinterface. The authentication takes place in the interface. This is not fixable ;). The only thing you can try is so specify username and password in your $config[‘nagios_url’] variable like this: “http://user:password@www.example.com/nagios”. But i would never recommend this! Otto

Everything works great, thank you very much for the plugin!

I followed another guide for Nagios and now have information put into a wikki page link that I have configured via the extended host or service template. Would it be possible to add a line somewhere in the nagios_mail.php notification to append information that is found in the extended field link to the email that is sent? This might be easier said then done, but thought it couldn’t hurt to ask.

Hi Jason. Sorry i dont understand exactly what you mean. What field “link” do you mean? Is it a Nagios Config-Var? Pleace specify more details ;)

Well right now in the extended templates I have used the URL Notes field as ‘http://nagios.testbox.net/wikki/$HOSTNAME$’. We have been filling out that page with information such as primary contact, secondary contact, applications running on that server, etc. It would be great to have the information from that appended to end of the alert emails.

Sehr geehrter Herr Berger,

das Skript ist absolut klasse und mit Hilfe des einen oder anderen Tipps aus den Kommentaren kam es einwandfrei zum Laufen, vielen Dank für das Bereitstellen dieser Lösung!

Mit freundlichen Grüßen aus Rödermark,
Oliver Köhl

Dear Mr. Berger,

thank you very much for this script by using the help out of the comments it works great. Thank you for sharing this solution with the community.

Best regards from Roedermark (Germany),
Oliver Koehl

Thanks for your plugin, it really works great and makes nagios messages at lot more readable even on my mobile.
One thing I can’t get to work is to show the host and service acknowledgment if I set “active” to “HOST” or “SERVICE”.
It works fine for host and service notifies but when a service or host is acknowledges it doesn’t show the author and the comment of the person who acknowledged the problem. Any help would really be appreciated.

Hi,
Mail kommt schonmal schöner an, nur nich wie im screenshot mit so einem Roten Viereck bzw Grünen. der quelltext sagst: irgendwas mit “green” hab da mal den hex farbcode eingetragen hilft auch nix.
bin aber auch kein php/html master also irgendeine idee?

gruß Mecke

Hi, das variiert je nach Benachrichtigung: “problems” sind rot, “recoverys” grün, “warnings” orange, “acknowledgements” blau. Welchen Mail-Client verwendest du denn?

also wir verwenden outlook 2007, schuldige die späte antwort, habe den html code jetzt auch nochmal im Firefox angeschaut und da wird es richtig dargestellt also outlook2007 problem oder einstellungs sache.
wenn ich gefunden habe wo es einzustellen ist sage ich nochmal bescheid

Hi!
Just to extend the range I repost my prior post in english:
I just won’t get this script to run on my server. In Testmode an email is send (as well via commandline as via nagios). But within the testmail there are no macros resolved. Is that normal? As soon as I remove the mail_add_to_address no emails are sent which leads me to the assumption that no macros are provided to the script by nagios. But the enable_environment_macros configuration is set to 1 and the standard printf notifications are working perfectly. Thanks in advance for any help!

Finally I was able to fix the problem and the problem had nothing to do with the script, just with my debian installation any my lag in php knowledge.

For all debian user:
Make sure you have the package “php5-cli” installed on your system. It’s the command-line interpreter for the php5 scripting language and without this package no php5-commandline-scripts will run. Hopefuly this information can prevent someone else from hours of debugging!
Thanks again Otto for all your help!

Hallo Otto,

ich habe die Notification per Mail super einfach zum laufen bekommen und finde es sieht echt gut aus. Hast du einen Tipp für mich, warum die Statistik-Sektion nicht ausgegeben wird? Die Rubriken in der Config sind alle aktiviert (true).

Viele Grüße
Daniel

Evt. werden die Variablen nicht von Nagios übergeben… Schalte mal den debug-modus ein – im Text-Body der Mail sollten dann alle Variablen auftauchen. Gruß Otto.

Hallo Otto,

den Debug-Modus hab ich eingeschaltet, jedoch sehe ich die Variablen nicht in der Mail. Mal davon ausgehend, dass Nagios diese Daten nicht übergibt, wie kann ich Nagios dazu bringenm, es doch zu tun?

Viele Grüße
Daniel

Die Debug-Ausgabe ist nur in der Text-Variante der Mail sichtbar (nicht HTML). Ansonsten in den Quelltext der Mail schauen… Welche Nagios Version?

Hallo Otto,

ich nutze Nagios® 3.0.6 mit der Groundwork-Oberfläche. Im Quelltext der Mail ist leider nichts zu erkennen. Hilft es dir, wenn ich Auszüge der Mail hier poste?

Viele Grüße
Daniel

Hi Otto, erstma vielen Dank für dein super php script, ich hab mich lange mit dem normalen notifications rumgeschlagen und nichts hat geklappt. nun hab ich in 2 minuten dein php script installiert und hab auch erfolgreich die Test-Mail bekommen, nun aber weiss ich nicht recht wie weiter? in meiner Testmail steht z.b
Hostname — HOSTNAME
Alias –HOSTALIAS

muss ich noch weitere konfigurationen machen z.b in contacts.cfg oder so damit er mir service fehler sendet?

sry das ist alles neuland für mich bitte um verständniss.

Cheers

Sorry, dann würde ich erstmal checken, warum die normale Notification nicht funktioniert. Etwas einlesen in die Nagios-Konfiguration kann ich dir wohl keiner ersparen… ;) Gruß Otto

Hi Otto, ich hab mal den debug modus eingeschaltet und hier ein Auszug aus dem Log.

[1255422647] Warning: Attempting to execute the command “/usr/bin/printf “%b” “***** Nagios *****\n\nNotification Type: $PROBLEM$\n\nService: HD – C:\ System\nHost: $vialissrv03$\nAddress: 192.168.0.27\nState: WARNING\n\nDate/Time: Tue Oct 13 09:00:47 CEST 2009\n\nAdditional Info:\n\nC:\ – total: 19.99 Gb – used: 15.99 Gb (80%) – free 4.00 Gb (20%)” | /bin/mail -s “** $PROBLEM$ Service Alert: $vialissrv03$/HD – C:\ System is WARNING **” jonas.korteweg@vialis.ch” resulted in a return code of 127. Make sure the script or binary you are trying to execute actually exists…
[1255422807] SERVICE ALERT: server23.rph.local;Memory Usage;OK;HARD;3;Memory usage: total:4192.58 Mb – used: 3210.33 Mb (77%) – free: 982.25 Mb (23%)

muss ich evtl. den /usr/bin/printf umleiten zu irgendeinem anderen ort?

köntnest du mir bitte weiterhelfen? Tausend Dank

Ok, ich habs gelöst. Danke totzdem für die Hilfe und vielen Dank für dein super script!!

Hi Jonas,

ich hab genau das selbe Problem das bei mir
Hostname — HOSTNAME
Alias –HOSTALIAS
drinsteht.
Wie hast du das gelöst ?

Grüße Sabrina

Hi, das mit Hostname — HOSTNAME ist der Testmodus. Im Testmodus wird einfach jeder wert mit dem Namen der Nagios-Variable gefüllt. Wenn das Script dann von Nagios ausgeführt wird, füllen sich diese Variablen mit den realen Werten. Soweit also durchaus normal im Testmodus. Der Testmodus ist eigentlich nur dafür da um zu checken ob überhaupt vom System die Mail verschickt werden kann.

Problem ist wenn das von Nagios ausgeführt wird, ist das genau so.
Die Mail sieht genauso wie die Testmail aus, weis echt nicht wo ich da den Fehler hab.

Danke dir schonmal Otto.

Hat sich erledigt. Ich hätte nur von Anfang an die richtige Datei bearbeiten sollen :)

Vielen Dank für das tolle Script!

Hi. I’m using your email mod and i find it very useful.
I modified (actually a friend of mine) your version adding a custom field because i need to report some custom infos based on host o service condition. For example if the notification is for a down of a host, then i add some text. If the host is in recovery, then i add some other text. Could you implement this in your original script? I can send you mine to copy from that.
Thank you

your welcome to send me your additions. i will see if i can include them. (you will find the address at the top of the script.) Otto

Problems with Outlook 2007. The HTML page is not correctly formated on Outlook 2007, no color notification..etc..

Hi, sorry i can not look at this at the moment (don’t have 2007). I tested it successfull with outlook 2003. Are you sure you dont have “simple html” or something like that enabled? Otto

Hi, Otto..
Your E-mail addition to nagios works very well with Outlook 2003. My company is upgrading to Outlook 2007, and for some reason the formatting on the mailpage is all wrong.

All information is now located on the very left side of the mail so you have to scroll to the bottom of the page to get all information. No color buttons are displayed. If you forward a mail in Outlook 2003 this is similar; all info is pressed on the very left side of the mail page.

I have tried to play around with the different settings in Outlook 2007, but so far no luck :( If you google HTML and Outlook 2007 you see there are several issues here..

/terje

Hi, Otto..
It works..!! The HTML code is now displayed correctly in Outlook 2007 (and 2003) Thanks ! :)

Hi Otto,

thanks for the script! I used it with nagios for some time now without problems.
I switched to ICINGA (the nagios fork) and tried to make it work again. I am stuck with the following error:
(su’ed to ICINGAUSER)
# php -q nagios_mail.php
PHP Notice: Undefined index: mail_add_to_address in /usr/local/icinga/bin/nagios_mail.php on line 696

CONTACTEMAIL env-var is empty (not run from Nagios?) or ‘mail_add_to_address’ not configured (Testmode)

So where do I need to look at? Is it an problem due to icinga? I have openSuse 11.2 on 64 bit and have enabled the EGPCS variables_order in the php.ini.

Thomas

Hi,

sorry i actually dont tested with ICINGA (and i think i dont get the chance to do so in the next weeks). But it seems that the ENV-Vars are not available to the mail-script – or maybe they are spelled different? Did you tried the debug-mode of the script?

Otto

Hallo,

eine vielleicht blöde Frage, aber wenn ich in Nagios
“Send custom host notification”
ausführe, bekomme ich auch die E-Mail im HTML-Format, aber
der Kommentar wird nicht mitgeschickt. Läßt sich der noch
irgendwo aktivieren?

Gruß,
Carsten

Stimmt, der Kommentar wird nirgendwo ausgegeben (hab die Funktion noch nie benutzt). Die Variable heißt “NOTIFICATIONCOMMENT”. Du könntest einfach einen neuen Abschnitt einfügen. z.B. unter Host-Output (ca. Zeile 247):

array(
‘name’ => false,
‘nagios_env’ => ‘HOSTOUTPUT’,
‘required’ => false,
),
array(
‘name’ => “Comment”,
‘nagios_env’ => ‘NOTIFICATIONCOMMENT’,
‘required’ => false,
),

Habe heute auch die Benachrichtigung integriert in Nagios 3.2.0. Funktioniert hervoragend. Für meinen Geschmack etwas zu viel Infos, aber man kann die Sektionen die man nicht will in der nagios_mail.php einfach auskommentieren.
Jetzt hab ich aber noch eine Frage. Würde gerne die Links ändern, Bei Host Information würde ich gerne, wenn ich auf die Addresse klicke, auf die Nagiosseite des Hosts kommen. Außerdem würde ich gerne unter Service Details wenn ich auf den Service klicke, gleich zu Nagios und dem Service wechseln. Kannst du mir einen hint geben wie ich das bewerkstelligen kann?
Danke

Das Skript ist wunderbar und wir würden es gerne nutzen,
nur müssen wir feststellen was uns eigentlich hätte klar sein können das es nicht mit dem SystemMonitoring Plugin für OTRS 2.4 zusammen harmoniert. Das liegt wohl offensichtlich an den RegEX und den Subjects, also mit etwas “reenginiering” sollte es aber durchaus klappen. Danke nochmals

hallo,
habe das script jetzt auch bei mir laufen.
Bei SLES OS gibt es wohl zu beachten das es 2 PHP.inis gibt. Für PHP5-CLI und PHP5 Apache:

/etc/php5/cli/php.ini
/etc/php5/apache2/php.ini

Wichtig ist vor allen, das die EGPCS Option.

Ansonsten ist das Script ein solides Grundgerüst um seine Notifications zu customizen… Danke dafür!

Hello

I found this script very useful. Thank you!

Just to let you know there is a typo at line 301:
‘name’ => ‘Servive details’ :)

IRO

Hallo Otto,

finde dein script total super. Allerdings funktioniert es bei mir überhaupt nicht so wie es soll. Es scheitert schon an der Testmail. Ich bin jetzt auch nicht so der Linuxspezialist. Das komische ist, wenn ich die Testmail versende, kommt sie beim ersten Versuch an. Will ich noch eine weitere versenden passiert nichts mehr. Sobald ich die nagios_mail.php allerdings verändere und speicher, sendet er automatisch wieder eine Testmail raus.

In der php.ini habe ich “sendmail_path = /usr/sbin/sendmail -t -i” gesetzt und die variables order stimmt auch. Wie genau läuft das denn ab, aus der nagios_mail.php wird die E-Mail generiert und dann per sendmail (Postfix) versendet?

Hast du vielleicht eine Idee wodran das liegen könnte? Oder irgendwo was in logs geschrieben, dass ich den Fehler näher eingrenzen kann? Produktiv habe ich das ganze bis jetzt noch nicht getestet, nur die Testmails.

Achso und noch was, bei mir gibts es in /usr/bin/ einmal ‘php’ und einmal ‘php5’ , ist es egal welches es verwende? Hab es mit beiden versucht, aber wie gesagt nach der ersten Testmail geht keine weitere Testmail mehr raus.

MfG
chris

Sorry, mir fällt dazu nicht viel ein. Grundsätzlich würde ich mich erstmal darum kümmern das die Testmail zuverlässig versendet wird. PHP generiert die Mail und versendet diese dann über das eingestellte sendmail-kommando. Meist ist das dann ein Wrapper auf das jeweilige Tool des Mailservers. Wie das genau bei Postfix ist weiß ich nicht aber ich gehe davon aus, dass es mit der Standardeinstellung funktionieren sollte. Warum es nur beim ersten Mal funktioniert kann ich dir nicht sagen ;)

Ok also wir haben das Script eingesetzt und jetzt musste wieder leider feststellen, das aber einer gewissen Größenordnung an Services/Hosts bzw. ab einer Menge Mails es dazu kommt das ein Nagios Prozess sich so verabschiedet, das komplette Nagios Systeme hängen, nichts mehr wird executed. Auch mit enable large_installtion_tweaks um die Prozessverwaltung vom OS übernehmen zu lassen, brachte leider keine Besserung. Nutzen nun leider wieder standard. “mailx”, “mail” – Trotzdem genial das Script. Aber wir vermuten der zusätzliche PHP Gewerkel macht dann doch nochmals Performance aus.

Kommando zurück, das Problem ist viel Komplexer.
Irgendwas in Verbindung mit localtime() in Verbindung mit environment_macros, glibc usw. Hängt Nagios weg. Das Problem gab es schon in älteren nagiosversionen also auch in 3.2.1 und tritt vermehrt auf in Verbindung mit Livestatus.

For Icinga, the environment variable names are different.
To retrieve correctly the variable in the script, the following change must be done at line 643 (v0.9):

if (strpos($key, ‘NAGIOS_’) !== false) {
to
if (strpos($key, ‘ICINGA_’) !== false) {

Yannick

Hi Otto,
ich habe leider immernoch das Problem, dass die Mails nur im Test-Modus ankommen und keine brauchbaren Infos enthalten.
Tortzdem ein echt super Script!!!
Wenn jetzt das noch funktioniert, ist das eine wunderbare alternative.

Tino

Hallo Otto,

kann es sein das Dein Script nur unter Nagios 3.x arbeitet ?
Ich bekomme Ihn unter Nagios 2.5 (SuSE SLES9) nicht zum Fliegen.

Gruss Heiko

Hi

Back in English I’m afraid!

I’ve installed the scripts and the test works fine, but I get nothing at all from Nagios. I’ve confirmed that environment macros are enabled and tested as the nagios user which is fine. The Nagios logs show a notification being sent, but I get nothing.

Not really sure where to look next to try and troubleshoot.

Thanks

Joe

Hi,

when I try to send the test email I get the following error message:
/usr/bin/php -q /opt/nagios_mail.php

Could not open input file: /opt/nagios_mail.php

does anyone know what is wrong?
Please help.
Thanks in advance.

Hi,

I reinstalled my system and configured postfix (before it was exim4)
I had also to change “variables_order” to “EGPCS” in php.ini.
Everything works fine. Great script.
Thank you

Hi Otto,
geniales script.
Leider wird bei den (service notification) der Betreff z.T viel zu lange > 300 Zeichen. Wie kann ich nur den Betreff kürzen, damit dieser auch in Outlook 2007 angezeigt wird? habe mit substr rumprobiert, leider ohne Erfolg.
Besten Dank

Hi Otto,

möchte noch anfügen, das ich im Betreff natürlich den “%%SERVICEOUTPUT%%” auch mit anzeigen möchte. Ist dieser zu lang >160 Zeichen, sollte er auf 160 Zeichen gekürzt werden. In der Beschreibung soll die volle Länge ersichtlich bleiben.

Ich würde das ganze auch gernen nutzen. Leider funktioniert dies überhaupt nicht. Ich habe die oben genannten E-Mail Definitionen in die Datei /usr/local/nagios/etc/commands.cfg gepackt, wo auch meine normalen E-Mail Notification Optionen enthalten sind. In den Contacten habe ich den den Bezeichner (host-notify-by-email) dementsprechend abgeändert. Leider verschickt er keine E-Mails .. mh..
Fehlt noch irgendwo was? Habe die Datei unter /opt/ abgelegt.

Hi, the version 0.9 is not working with PHP4. It’s using the “__construct” method that doesn’t exists on PHP4. If you’re using PHP4, as I’m, the solution is remove the “__construct()”, merging everything with “function setConfig($config)”.

Continuing… original:
function setConfig($config) {
$this->config = (array)$config;
}
function __construct() {
foreach ($_ENV as $key => $value) {
if (strpos($key, ‘NAGIOS_’) !== false) {
$this->nagios[substr($key, 7)] = $value;
$this->replace[‘%%’ . substr($key, 7) . ‘%%’] = $value;
}
}
}
FIXED:
function setConfig($config) {
$this->config = (array)$config;

### Comment these lines
### }
### function __construct() {
foreach ($_ENV as $key => $value) {
if (strpos($key, ‘NAGIOS_’) !== false) {
$this->nagios[substr($key, 7)] = $value;
$this->replace[‘%%’ . substr($key, 7) . ‘%%’] = $value;
}
}
}

In some cases the solution might be the setting of “variables_order” in php.ini. Default is “EGPCS” but certain distributions have the explicit setting “GPCS”. The text discourages the use of “E” in production environments and states that getenv() should be used to get the setting of environment variables instead.
Maybe somebody is able to provide a patch for the script.

Reference:
http://www.nagios-portal.org/wbb/index.php?page=Thread&threadID=20500

thanks, i will look at it. But i think (dont looked at the manual yet) that getenv() does also need the EGPCS setting, so it might be no difference in security, right? Edit: just saw that is it not a security thing but a performance issue on production servers. So i change it anyway.

Tolles Script! Habe aber das Problem, dass außer der Testmail keine Mails von Nagios kommen. nagios.log sagt zwar, dass ein Notification verschickt werden soll … aber wo das Ganze stockt habe ich noch nicht erkannt … jemand ideen? Danke!

ja super script! hab seit icinga beta im einsatz bis 1.0.1 lief es auch…. update auf 1.2.1 + icinga-web frontend seit dem kommen keine notifies mehr…
es kommt bei eingabe folgender fehler…
root@icinga:~# /usr/bin/php -q -c /usr/local/icinga/mail/icinga_mail.php
PHP: syntax error, unexpected ‘{‘ in /usr/local/icinga/mail/icinga_mail.php on line 14
ausschnitt line 14:
* define command{
^^das steht bei mir in der line
hat wer eine idee/lösung?
vielen dank im voraus

sende ich aber eine testmail kommt diese an

Hi, sieht so aus als wäre der php-Aufruf nicht richtig: mit “-c” soll der pfad zur php.ini angegeben werden und nicht die php-datei selbst. Also z.B. so: /usr/bin/php -q -c /etc/php.ini /usr/local/icinga/mail/icinga_mail.php

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.