Hi Team,
This is first my question on forum. Just started working on Nagios and We need to change format of alert email to json format. Currently it is coming as plain text, Can anyone please change text to json format as per below sample.
{
"nagios_alert": {
"server_name": "Nagios Master Production",
"app_name": " pepS",
"service_name": " sscp",
"host": " localhost",
"state": " WARNING",
"last_state": " WARNING",
"check_attempt": " 4",
"max_check_attempt": "4",
"state_since": " 0d 0h 7m 0s",
"is_downtime": " 0",
"service_last_ok": "16",
"service_check_output_short": " PROCS WARNING: 271 processes with STATE = RSZDT ",
"service_check_output_long": " ",
"notification_type": " PROBLEM",
"date_time": " Wed Feb 27 14:32:16 UTC 2019",
"additional_info": "PROCS WARNING: 271 processes with STATE = RSZDT"
}
}
Thanks in advance for the help
How to change alert email to json format
Re: How to change alert email to json format
Nagios Core dispatches notifications via notification/event handlers, which reference a specific command to execute.
Here are the default ones:
If you wanted to change the templating, you'd simply change what was fed into the /bin/mail command and add whatever macros you like:
Then just feed that body into your /usr/bin/printf command. I wouldn't directly copy+paste that though because it has exactly zero JSON linting or CLI escaping
Here are the default ones:
Code: Select all
# 'notify-host-by-email' command definition
define command{
command_name notify-host-by-email
command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /bin/mail -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$
}
# 'notify-service-by-email' command definition
define command{
command_name notify-service-by-email
command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$\n" | /bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
}
Code: Select all
{
"nagios_alert": {
"additional_info": "$HOSTOUTPUT$",
"app_name": "dunno what this is",
"check_attempt": "$HOSTATTEMPT$",
"date_time": "maybe use $(date +%s)?",
"host": "$HOSTNAME$",
"is_downtime": "$SERVICEDOWNTIME$",
"last_state": "$LASTSERVICESTATE$",
"max_check_attempt": "$MAXHOSTATTEMPTS$",
"notification_type": "$NOTIFICATIONTYPE$",
"server_name": "Nagios Master Production",
"service_check_output_long": "$LONGSERVICEOUTPUT$",
"service_check_output_short": "$SERVICEOUTPUT$",
"service_last_ok": "$LASTSERVICEOK$",
"service_name": "$SERVICEDISPLAYNAME$",
"state": "$SERVICESTATE$",
"state_since": "$LASTSERVICESTATECHANGE$"
}
}
Former Nagios employee
https://www.mcapra.com/
https://www.mcapra.com/
-
- Posts: 5324
- Joined: Wed Aug 22, 2018 4:39 pm
- Location: saint paul
Re: How to change alert email to json format
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
Be sure to check out our Knowledgebase for helpful articles and solutions!
Be sure to check out our Knowledgebase for helpful articles and solutions!
Re: How to change alert email to json format
Thanks for the help, will let you know if i will stuck somewhere.
Really appreciated your help
Really appreciated your help
-
- Posts: 5324
- Joined: Wed Aug 22, 2018 4:39 pm
- Location: saint paul
Re: How to change alert email to json format
Hi @gouravin,
Sounds good. We'll keep this topic open for now.Thanks for the help, will let you know if i will stuck somewhere.
Really appreciated your help
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
Be sure to check out our Knowledgebase for helpful articles and solutions!
Be sure to check out our Knowledgebase for helpful articles and solutions!
Re: How to change alert email to json format
Hi Benjaminsmith,
Thanks for the help, really appreciate your help here.
We could close this thread.
Thanks for the help, really appreciate your help here.
We could close this thread.
-
- DevOps Engineer
- Posts: 19396
- Joined: Tue Nov 15, 2011 3:11 pm
- Location: Nagios Enterprises
- Contact:
Re: How to change alert email to json format
Great!gouravin wrote:Hi Benjaminsmith,
Thanks for the help, really appreciate your help here.
We could close this thread.
Closing