0

I have to create a report based on the nagios log file. I am going to write a shell script for this. The log file is as follows :


[1420520400] CURRENT SERVICE STATE: abc.com;service;CRITICAL;HARD;3;OK : OK : Last on 10-01-2015, Users = 2, Employees = 0

[1420520400] CURRENT SERVICE STATE: def.com;service;CRITICAL;HARD;3;WARNING : Last on 10-01-2015, Users = 2, Employees = 0

[1420520400] CURRENT SERVICE STATE: ghi.com;service;CRITICAL;HARD;3;CRITICAL : Last on 2014-11-19, Users = 2, Employees = 0


From this file, I want to generate the report as follows :


Name : abc.om

Date : 10-01-2015

Users : 2

Employees : 0


Name : def.om

Date : 10-01-2015

Users : 2

Employees : 0


Name : ghi.om

Date : 2014-11-19

Users : 2

Employees : 0


It would be great if anyone help me to achieve this.

1
  • I tried by using grep and sed, but it didn't give the exact result. Also I am new with the shell scripting. Commented Jan 15, 2015 at 6:43

1 Answer 1

1

This command will give you the above output, from the log file just change the file name from input.log to the actual file name.

$ cat input.log |cut -d';' -f1,6|sed -e 's/\<CURRENT SERVICE STATE\>/NAME=/g'|sed -e 's/\<OK\>//g'|sed -e 's/\<Last on\>/Date =/g'|tr -d ':'|sed 's/WARNING//g'|sed 's/CRITICAL//g'|cut -c 14-|tr -s ' '|tr ',;' '\n'                                                                         

Output:

enter image description here

Here, I used '=' but you can change the output exactly same as above if you use, following command,

$ cut -d';' -f1,6 input.log|sed -e 's/\<CURRENT SERVICE STATE\>/NAME=/g'|sed -e 's/\<OK\>//g'|sed -e 's/\<Last on\>/Date =/g'|tr -d ':'|sed 's/WARNING//g'|sed 's/CRITICAL//g'|cut -c 14-|tr -s ' '|tr ',;' '\n' |tr '=' ':'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.