AWK command email output.

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.
Locked
martin09
Posts: 23
Joined: Thu Jul 09, 2015 2:16 am

AWK command email output.

Post by martin09 »

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
jolson
Attack Rabbit
Posts: 2560
Joined: Thu Feb 12, 2015 12:40 pm

Re: AWK command email output.

Post by jolson »

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?
Twits Blog
Show me a man who lives alone and has a perpetually clean kitchen, and 8 times out of 9 I'll show you a man with detestable spiritual qualities.
martin09
Posts: 23
Joined: Thu Jul 09, 2015 2:16 am

Re: AWK command email output.

Post by martin09 »

Here's the AWK commands and i'm using Nagios Core.

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.txt
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.
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: AWK command email output.

Post by ssax »

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.
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: AWK command email output.

Post by tmcdonald »

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.
Former Nagios employee
Locked