Sponsored Content
Top Forums Shell Programming and Scripting Parsing Nagios service config files with awk Post 302482041 by ctsgnb on Monday 20th of December 2010 12:41:49 PM
Old 12-20-2010
Code:
awk '/^define service\{$/,/^}$/{if(/service_description/||(/(host_name|hostgroup_name)/)||/contact_groups/||/check_command/){for(i=2;i<=NF;i++)x=(x)?x" "$i:$i;printf "%s",(/host/)?x:"~"x;x=y}}END{print y}' tst
liv_citrix_group,lon_citrix_group,liv_exchange_group,lon_exchange_group~CPU Loading~t2-admins,t2-mgrs~ctx_cpu_snmp!comstring 75 85

Code:
# awk '/^define service\{$/,/^\}$/{if(/service_description/||(/(host_name|hostgroup_name)/)||/contact_groups/||/check_command/){s=(/host/)?y:"~";$1="";A[NR]=substr($0,2)s}}/^\}$/{for(i in A)printf "%s",A[i]}END{print y}' tst
CPU Loading~t2-admins,t2-mgrs~ctx_cpu_snmp!comstring 75 85~liv_citrix_group,lon_citrix_group,liv_exchange_group,lon_exchange_group
#

Code:
# awk '/service_description/ { $1="" ; A[1]=substr($0,2) }/(host_name|hostgroup_name)/ { $1="" ; A[2]=substr($0,2) }/contact_groups/ { $1="" ; A[3]=substr($0,2) }/check_command/ { $1="" ; A[4]=substr($0,2) }/^\}$/{ print A[1]"~"A[2]"~"A[3]"~"A[4] }' tst
CPU Loading~liv_citrix_group,lon_citrix_group,liv_exchange_group,lon_exchange_group~t2-admins,t2-mgrs~ctx_cpu_snmp!comstring 75 85
#

Add this before the last print :
Code:
/^\}$/


Last edited by ctsgnb; 12-20-2010 at 03:59 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Parsing config file

Hi All, I have a requirement to parse a file. Let me clear you all on the req. I have a job which contains multiple tasks and each task will have multiple attributes that will be in the below format. Each task will have some sequence number according to that sequence number tasks shld... (0 Replies)
Discussion started by: rajeshorpu
0 Replies

2. Shell Programming and Scripting

parsing config file to create new config files

Hi, I want to use a config file as the base file and parse over the values of country and city parameters in the config file and generate separate config files as explained below. I will be using the config file as mentioned below: (config.txt) country:a,b city:1,2 type:b1... (1 Reply)
Discussion started by: clazzic
1 Replies

3. UNIX for Dummies Questions & Answers

Issue with parsing config variables

I am using MKS tool kit on windows server. One config variable is defined in windows environment and I am trying to use that variable. # Below RootDir is defined in windows RootDir="\\f01\var" # in unix script details="$RootDir/src|$RootDir/tgt" src=`echo $details|awk -F '|' '{print... (1 Reply)
Discussion started by: madhukalyan
1 Replies

4. Shell Programming and Scripting

Need help parsing config file in ksh

Hi all, I've done some searching here but haven't found exactly what I'm looking for so I thought I'd post up and see if someone can help out. I'm working on a shell script that I would like to store environment variables in an external file. I'm familiar with sourcing a file with variables in... (1 Reply)
Discussion started by: kungfusnwbrdr
1 Replies

5. Shell Programming and Scripting

Parsing config-file (perl)

Hi, i'm trying to parse a config file that have alot of rows similar to this one: Example value value value What i want to do is to split and save the row above in a hash, like this: Example = value value value Basically i want to split on the first whitespace after the first... (3 Replies)
Discussion started by: mikemikemike
3 Replies

6. Infrastructure Monitoring

Using SMF to register & start a (Nagios) service

I'm trying to register & start a service using SMF on Solaris 10. It's nsca, part of the Nagios monitoring system. I've got nsca running fine as a detached process, and can manually create passive checks via send_nsca. But when I try to run nsca as a daemon, I need some advice. The nsca... (0 Replies)
Discussion started by: lyle
0 Replies

7. Shell Programming and Scripting

Shell script that will compare two config files and produce 2 outputs 1)actual config file 2)report

Hi I am new to shell scripting. There is a requirement to write a shell script to meet follwing needs.Prompt reply shall be highly appreciated. script that will compare two config files and produce 2 outputs - actual config file and a report indicating changes made. OS :Susi linux ver 10.3. ... (4 Replies)
Discussion started by: muraliinfy04
4 Replies

8. Shell Programming and Scripting

parsing a config file using bash

Hi , I have a config _file that has 3 columns (Id Name Value ) with many rows . In my bash script i want to be able to parse the file and do a mapping of any Id value so if i have Id of say brand1 then i can use the name (server5X) and Value (CCCC) and so on ... Id Name ... (2 Replies)
Discussion started by: nano2
2 Replies

9. Red Hat

Nagios is sending "Service Alert: CentOS 5/HTTP is WARNING"

Hello All, I have setup Nagios 3.2.3 on CentOS release 5.7 (Final) with the default config files and added 1 host to it and it is sending "Service Alert: CentOS 5/HTTP is WARNING" frequently, how do you fix this one? what are the additional files that need to be added so that I can monitor the... (0 Replies)
Discussion started by: lovesaikrishna
0 Replies

10. AIX

NAGIOS Service not able to open port on AIX 7.1

I have an AIX 7.1 LPAR where Nagios agent was installed for monitoring. The issue is that when I start the nagios service (ncpa_listener), it starts but does not open the 5693 port it requires for communication. On all other LPARs the service opens the port and is listening. I tried reinstalling... (4 Replies)
Discussion started by: wibhore
4 Replies
nagios(8)                                                             Nagios                                                             nagios(8)

NAME
Nagios - network/systems status monitoring daemon SYNOPSIS
nagios [-h] [-v] [-s] [-d] <main_config_file> DESCRIPTION
nagios is a daemon program that monitors the status of various network accessible systems, devices, and more. For more information, please consult the online documentation available at http://www.nagios.org, or on your nagios server's web page. OPTIONS
main_config_file The main configuration file. On openSUSE systems this defaults to /etc/nagios/nagios.cfg -h A helpful usage message -v Reads all data in the configuration files and performs a basic verification/sanity check. Always make sure you verify your config data before (re)starting Nagios. You can also use the Nagios init script to verify your configuration - try: rcnagios check_verbose -s Shows projected/recommended check scheduling information based on the current data in the configuration files. -d Starts Nagios in daemon mode (instead of as a foreground process). FILES
/etc/nagios Default configuration directory for nagios AUTHOR
Nagios is written and maintained by Ethan Galstad <nagios@nagios.org>. This manual page was written by sean finney <seanius@debian.org> for the Debian GNU/Linux operating system (but it may be freely used, modified, and redistributed by others) and adapted by Lars Vogdt for openSUSE. sean finney, Lars Vogdt February 2006, May 2010 nagios(8)
All times are GMT -4. The time now is 02:15 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy