Page 1 of 2

Project of communication

Posted: Tue Apr 29, 2014 5:04 am
by kiko67
Hi everybody,

I'm from France and excuse my english,
I'm currently in a job training and my boss asked me to do a project.
He wants that Nagios communicate his notifications towards an external software of IT asset management written in Java whiwh has a MySQL database.
The goal is doing statistics and for that receiving notifications without losing it.
But:
He don't want plugins like NDOutils,
and also he don't want use mail server (it could be down).

What kind of solutions do you think about?

Re: Project of communication

Posted: Tue Apr 29, 2014 10:23 am
by sreinhardt
sounds like you need to write an event handler or other notification command to make the additions to your database that you want. Otherwise I really see NDOutils as about the only other real option.

Note I am moving this to core support, as it is not related to the plugins package.

Re: Project of communication

Posted: Wed Apr 30, 2014 2:43 am
by kiko67
No i wish Nagios send notifications to a temporary text file leavin the deafault email solution running.
I put this in misccommands
Does it work?
what i have to put instead of $CONTACTEMAIL$ ?
Thanks.

"HOST ALERT:\n
\n
Notification Type: $NOTIFICATIONTYPE$\n
Host: $HOSTNAME$\n
State: $HOSTSTATE$\n
Address: $HOSTADDRESS$\n
Info: $HOSTOUTPUT$\n
\n
Date/Time: $LONGDATETIME$\n"
|
/tmp/textnotif.txt
"HOST ALERT:
$HOSTNAME$
is
$HOSTSTATE$ - $NOTIFICATIONTYPE$"
$CONTACTEMAIL$

notify_service_by_txt

/usr/bin/printf "%b"
"SERVICE ALERT:\n
\nNotification Type: $NOTIFICATIONTYPE$\n
\n
Service: $SERVICEDESC$\n
Host: $HOSTALIAS$\n
Address: $HOSTADDRESS$\n
State: $SERVICESTATE$\n
\n
Date/Time: $LONGDATETIME$\n
\n
Additional Info:\n
\n
$SERVICEOUTPUT$"
|
/tmp/textnotif.txt
"SERVICE ALERT:
$HOSTALIAS$ - $SERVICEDESC$
is
$SERVICESTATE$ - $NOTIFICATIONTYPE$"
$CONTACTEMAIL$

Re: Project of communication

Posted: Wed Apr 30, 2014 11:59 am
by sreinhardt
I'm sorry, that is really hard to understand what you are doing with those commands, could you format and use

Code: Select all

 [ /code] tags(minus the spaces). The idea of appending to a text file or creating lots of indiviual text files will work. However I should note that you can only have one notification type per contact, so you cannot do email and text file notifications without dual contacts.

Re: Project of communication

Posted: Mon May 05, 2014 2:17 am
by kiko67
Thanks for your help,
i enter these commands in my misccommands file:
/bin/echo -e "HOST ALERT:\n\n
Notification Type: $
NOTIFICATIONTYPE$\n
Host: $HOSTNAME$\n
State: $HOSSTATE$\n
Address: $HOSTADDRESS$\n
Info: $HOSTOUTPUT$\n
Date/Time: $LONGDATETIME$\n"
>>
/tmp/notif_text.txt
"HOST ALERT: $HOSTNAME$ is $HOSTSTATE$' - $NOTIFICATIONTYPE$"

and i don't know what to put as email address
if i put nagios@localhost is it correct ?

And when i enter the command in my prompt the file /tmp/notif-text.txt is created with:
HOST ALERT:localhost is $ - $
Notification type: $
Host: Localhost
State: $
Address: $
Info: $
Date/Time: $

But after when i put the same command in my misccommand file the notifications aren't written as a text.
Why ?


How should i proceed to have notifications only (and not the all log file) in a text file?

Re: Project of communication

Posted: Mon May 05, 2014 9:53 am
by abrist
kiko67 wrote:and i don't know what to put as email address
if i put nagios@localhost is it correct ?
Probably not. If you are referring to the $CONTACTEMAIL$ macro, this is the email address to send the notification to, so it should be a real email.
kiko67 wrote: And when i enter the command in my prompt the file /tmp/notif-text.txt is created with:
HOST ALERT:localhost is $ - $
Notification type: $
Host: Localhost
State: $
Address: $
Info: $
Date/Time: $

But after when i put the same command in my misccommand file the notifications aren't written as a text.
Why ?
How are you calling this script? As an event handler, or some other way? It looks like $HOSTNAME$ is the only populated macro.
kiko67 wrote: How should i proceed to have notifications only (and not the all log file) in a text file?
Could you clarify? Are you just trying to log notifications?

Re: Project of communication

Posted: Tue May 06, 2014 3:51 am
by kiko67
kiko67 wrote:How are you calling this script? As an event handler, or some other way? It looks like $HOSTNAME$ is the only populated macro
I enter this script in my NConf plugin. It is saved in /etc/nagios/global/misccommand.cfg like this:
define command{
command name notify-host-by-txt
command_line /bin/echo -e "HOST ALERT:\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" >> /tmp/notif_texte.txt "HOST ALERT: $HOSTNAME$ is $HOSTSTATE$ - $NOTIFICATIONTYPE$"
kiko67 wrote:Could you clarify? Are you just trying to log notifications?
Yes my goal is to send notifications to a text file.
Three days that i work on it.
After that, a script of another software will search in this text file and enter the datas in a database.
But it will be another stuff.
Now, i have to find the solution to write notifications in a text file.
Thx

Re: Project of communication

Posted: Tue May 06, 2014 9:42 am
by abrist
kiko67 wrote:command_line /bin/echo -e "HOST ALERT:\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" >> /tmp/notif_texte.txt "HOST ALERT: $HOSTNAME$ is $HOSTSTATE$ - $NOTIFICATIONTYPE$"
What is the purpose of the macros at the end:

Code: Select all

"HOST ALERT: $HOSTNAME$ is $HOSTSTATE$ - $NOTIFICATIONTYPE$"
Are these commands run as event handlers or as notification handlers?

Re: Project of communication

Posted: Wed May 07, 2014 2:50 am
by kiko67
kiko67 wrote:What is the purpose of the macros at the end:
I copy these macros from email notification command but i remove it and i try without it.

The problem is to understand which is the right solution to send the notifications to a text file and not only to an email ?
Because the log file is too big and i want only notifications in a text.
kiko67 wrote:Are these commands run as event handlers or as notification handlers?
I think as notification because i've created a contact and put this command in /etc/nagios/global/misccommand.cfg file like the "notify-by-email" command.

I'm in a job training, and nagios was already installed with NConf 1.2.5 plugin to configure it.....
And this task is driving me crazy! :shock:
Thanks for your help.

Re: Project of communication

Posted: Wed May 07, 2014 8:42 am
by kiko67
Thanks to everybody,
the command works, i don't know how but it works.
Now the second phase of the project is to make an agent that will search and find in our text file the intresting datas and put it in a database.
Thanks for your help.