Page 2 of 3

Re: Nagios HTML mail

Posted: Fri Nov 14, 2014 8:29 am
by ericosman
I'm "logged in" as nagios
bash-4.1$ nagios-html-email service http://nagios.example.com | mailx -t
env NAGIOS_CONTACTEMAIL or `-a <address>` must be supplied!

Usage: nagios-html-email [options] <service|host> [arg1] [arg2] ...

This command is meant to be run from nagios when a service or host
experiences problems. The output will be suitable for passing to
a mail program that takes raw email data like `mailx -t`

Options
-a, --address <email> the email address to send mail to, defaults to env NAGIOS_CONTACTEMAIL
-h, --help print this message and exit
-s, --subject <subject> the email subject to use, defaults to _subject for the host/service, or default nagios subject
-t, --template-dir <dir> dir to find ejs template files, defaults to builtin templates
-u, --updates check for available updates on npm
-v, --version print the version number and exit
No message, no subject; hope that's ok
No recipients specified
"/var/spool/nagios/dead.letter" 7/186

Re: Nagios HTML mail

Posted: Fri Nov 14, 2014 12:39 pm
by sreinhardt
To correct rhassing a wee bit, I would highly suggest against setting nagios user to have a valid shell by default. "su nagios -s /bin/bash" should always be used instead to specify the shell for this user session. Regardless, it looks like the script is giving you errors not because of who you are running as, but because you are not providing a sending address, recipient, subject, or message.

Try something like, this is only going to output the message to screen, but let's make sure its formatted correctly first before trying to send it off:

Code: Select all

nagios-html-email-service -a [email protected] -s "this is a test" mailserver.yourdomain.com

Re: Nagios HTML mail

Posted: Mon Nov 17, 2014 5:21 am
by ericosman
sreinhardt wrote:To correct rhassing a wee bit, I would highly suggest against setting nagios user to have a valid shell by default. "su nagios -s /bin/bash" should always be used instead to specify the shell for this user session. Regardless, it looks like the script is giving you errors not because of who you are running as, but because you are not providing a sending address, recipient, subject, or message.

Try something like, this is only going to output the message to screen, but let's make sure its formatted correctly first before trying to send it off:

Code: Select all

nagios-html-email-service -a [email protected] -s "this is a test" mailserver.yourdomain.com
I still get the same message.. :(

But whenn i try this :

Code: Select all

nagios-html-email service http://nagios.wetron.intra | mailx [email protected] 
I recive an empty mail

Re: Nagios HTML mail

Posted: Mon Nov 17, 2014 5:55 pm
by abrist
What is the output of:

Code: Select all

nagios-html-email service http://nagios.wetron.intra
If it is empty, then there is an issue with the script or the service passed to it.
It it outputs data, then the issues is with mailx or the pipe.

Re: Nagios HTML mail

Posted: Tue Nov 18, 2014 2:27 am
by ericosman
Hi,

I need to add the | mailx -t ( otherwise it wont sent anything ) but againg an empty mail

Re: Nagios HTML mail

Posted: Tue Nov 18, 2014 1:11 pm
by sreinhardt
We actually do not want to send an email, so sans the | mailx -t would be ideal. We purely want to make sure that the output from your nagios-html-email is correctly formatting output prior to piping to mailx. It sounds like some or most of it is right, but clearly parts of it are not.

Re: Nagios HTML mail

Posted: Wed Nov 19, 2014 5:32 am
by ericosman
Whenn i try this :

Code: Select all

[root@Nagios objects]# nagios-html-email -a service service
i get this :

Code: Select all

To: service
Reply-To: service
Subject: undefined - undefined undefined
Content-Type: text/html

template /usr/lib/node_modules/nagios-html-email/templates/service.html.ejs error: ejs:32
    30| <html>
    31| 	<body>
 >> 32| 		<br />
    33| 		<span style="background-color: <%= colors.service[nagios.SERVICESTATE] %>; padding: 1px 5px; border: 1px solid black;"><%= nagios.SERVICESTATE %></span> -
    34| 		<strong><%= nagios.HOSTALIAS.split('.')[0] %> <%= nagios.SERVICEDESC %></strong>
    35| 		<br />

Cannot call method 'split' of undefined
<html><body><pre>{
  "args": [],
  "nagios": {},
  "package": {
    "name": "nagios-html-email",
    "version": "0.0.1",
    "description": "Generate HTML emails for Nagios service and host alerts",
    "author": {
      "name": "Dave Eddy",
      "email": "[email protected]",
      "url": "http://www.daveeddy.com"
    },
    "repository": {
      "type": "git",
      "url": "git://github.com/Voxer/nagios-html-email.git"
    },
    "license": "MIT",
    "preferGlobal": true,
    "bin": {
      "nagios-html-email": "./nagios-html-email.js"
    },
    "dependencies": {
      "posix-getopt": "~1.0.0",
      "ejs": "~0.8.5",
      "latest": "~0.1.2"
    },
    "bugs": {
      "url": "https://github.com/Voxer/nagios-html-email/issues"
    },
    "homepage": "https://github.com/Voxer/nagios-html-email",
    "_id": "[email protected]",
    "dist": {
      "shasum": "89e8f8d40d53ec7016d867ab96a2f43f6e70e5c0",
      "tarball": "http://registry.npmjs.org/nagios-html-email/-/nagios-html-email-0.0.1.tgz"
    },
    "_from": "nagios-html-email@",
    "_npmVersion": "1.3.14",
    "_npmUser": {
      "name": "bahamas10",
      "email": "[email protected]"
    },
    "maintainers": [
      {
        "name": "bahamas10",
        "email": "[email protected]"
      }
    ],
    "directories": {},
    "_shasum": "89e8f8d40d53ec7016d867ab96a2f43f6e70e5c0",
    "_resolved": "https://registry.npmjs.org/nagios-html-email/-/nagios-html-email-0.0.1.tgz"
  }
}</pre></body></html>
[root@Nagios objects]# 

Re: Nagios HTML mail

Posted: Wed Nov 19, 2014 5:54 pm
by abrist
Methinks your script no-worky.
By the way, it has not been updated in three years

Re: Nagios HTML mail

Posted: Wed Nov 26, 2014 9:04 am
by ericosman
i'm back :)
This time with : http://exchange.nagios.org/directory/Ad ... v2/details

I could not find the libexec folder so i created a folder in my nagios folder called htmlmail. Chmodd it to 777 with the files in it .
Nagios still wont sent mails to me but whenn i execute them in terminal i recive an mail...

Does anyone knows this problem?

Re: Nagios HTML mail

Posted: Wed Nov 26, 2014 12:42 pm
by abrist
ericosman wrote:Nagios still wont sent mails to me but whenn i execute them in terminal i recive an mail...
Were you running it as user nagios?
Can you post the command definitions you are using?