Im using AWK command in sending mails regarding warning and critical alerts in our nagios, everything is working fine, however, email output seems to be not in order, is there a command that can manipulate the output?..
i'll be needing the output by column like :
Warning Server Server Status Comment
Warning Server Server Status Comment
Warning Server Server Status Comment
instead, my output is like this:
Warning Server Server Status Comment
Warning Server Server Status Comment\
Warning Server Server Status Comm
ent
AWK command email output.
Re: AWK command email output.
Please post the AWK command that you're using to send emails - this may help us better understand what is going on here.
Are you using Nagios Core or Nagios XI?
Are you using Nagios Core or Nagios XI?
Re: AWK command email output.
Here's the AWK commands and i'm using Nagios Core.
1st and 2nd command used to grep the necessary warning and critical status i needed.
3rd command is used to print only the lines necessary in sending like status, server name and comments.
4th command is used to separate lines with symbol ";" and rearrange it to my desired format
5th command is what i'm using to send emails
I was hoping to find a script that can set the output column-wise since the output i'm getting is not in order.
Code: Select all
#!/bin/bash
cat /usr/local/nagios/var/nagios.log | grep 'CURRENT SERVICE STATE' | grep WARNING > /usr/local/nagios/libexec/Directory/test1.txt
sleep 10
cat /usr/local/nagios/var/nagios.log | grep 'CURRENT SERVICE STATE' | grep CRITICAL >> /usr/local/nagios/libexec/Directory/test1.txt
sleep 10
awk '{$1=$2=$3=$4=""; print}' /usr/local/nagios/libexec/Directory/test1.txt > /usr/local/nagios/libexec/Directory/test2.txt
awk -F";" '{ printf "%-20s %-20s %-20s %-20s\n", $3, $1, $2, $6}' /usr/local/nagios/libexec/Directory/test2.txt > /usr/local/nagios/libexec/Directory/test3.txt
sleep 10
mail -s 'Nagios: CURRENT SERVICE STATE' [email protected] < /usr/local/nagios/libexec/Directory/test3.txt3rd command is used to print only the lines necessary in sending like status, server name and comments.
4th command is used to separate lines with symbol ";" and rearrange it to my desired format
5th command is what i'm using to send emails
I was hoping to find a script that can set the output column-wise since the output i'm getting is not in order.
Re: AWK command email output.
If you look at the test3.txt file it shows that they are one line per so it is proper, you may want to construct and HTML email and use tables in order to properly format it in the email.
Re: AWK command email output.
Maybe I don't understand the intention of this script, but do you truly want to get a single email with every historical warning/critical state in the scope of the nagios log? Would it not suffice to use the default method of one alert per current issue? There is plenty of notification logic built in that can be used to alert you to problems.
How is this being launched? Is it on a cron or is this a notification command associated with a host/service?
It looks from your first post like you are getting newlines in your output, but without seeing real output it is hard to tell.
How is this being launched? Is it on a cron or is this a notification command associated with a host/service?
It looks from your first post like you are getting newlines in your output, but without seeing real output it is hard to tell.
Former Nagios employee