Nagios HTML mail

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
ericosman
Posts: 20
Joined: Thu Oct 30, 2014 4:11 am

Re: Nagios HTML mail

Post 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
sreinhardt
-fno-stack-protector
Posts: 4366
Joined: Mon Nov 19, 2012 12:10 pm

Re: Nagios HTML mail

Post 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 youraddress@yourdomain.com -s "this is a test" mailserver.yourdomain.com
Nagios-Plugins maintainer exclusively, unless you have other C language bugs with open-source nagios projects, then I am happy to help! Please pm or use other communication to alert me to issues as I no longer track the forum.
ericosman
Posts: 20
Joined: Thu Oct 30, 2014 4:11 am

Re: Nagios HTML mail

Post 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 youraddress@yourdomain.com -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 my-email@mail.nl 
I recive an empty mail
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

Re: Nagios HTML mail

Post 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.
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
ericosman
Posts: 20
Joined: Thu Oct 30, 2014 4:11 am

Re: Nagios HTML mail

Post by ericosman »

Hi,

I need to add the | mailx -t ( otherwise it wont sent anything ) but againg an empty mail
sreinhardt
-fno-stack-protector
Posts: 4366
Joined: Mon Nov 19, 2012 12:10 pm

Re: Nagios HTML mail

Post 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.
Nagios-Plugins maintainer exclusively, unless you have other C language bugs with open-source nagios projects, then I am happy to help! Please pm or use other communication to alert me to issues as I no longer track the forum.
ericosman
Posts: 20
Joined: Thu Oct 30, 2014 4:11 am

Re: Nagios HTML mail

Post 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": "dave@daveeddy.com",
      "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": "nagios-html-email@0.0.1",
    "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": "dave@daveeddy.com"
    },
    "maintainers": [
      {
        "name": "bahamas10",
        "email": "dave@daveeddy.com"
      }
    ],
    "directories": {},
    "_shasum": "89e8f8d40d53ec7016d867ab96a2f43f6e70e5c0",
    "_resolved": "https://registry.npmjs.org/nagios-html-email/-/nagios-html-email-0.0.1.tgz"
  }
}</pre></body></html>
[root@Nagios objects]# 
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

Re: Nagios HTML mail

Post by abrist »

Methinks your script no-worky.
By the way, it has not been updated in three years
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
ericosman
Posts: 20
Joined: Thu Oct 30, 2014 4:11 am

Re: Nagios HTML mail

Post 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?
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

Re: Nagios HTML mail

Post 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?
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
Locked