Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Standalone class for generating Nagios checkresult file, New config format, Skip checkresults for the hosts and services not known to Nagios #7

Open
wants to merge 35 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
dd1ede0
Added separate class for generating checkresults for Nagios Passive c…
MirrorZ Apr 9, 2014
53a00c1
Fixed minor tab issues
MirrorZ Apr 9, 2014
637c0fd
fixed tabs
MirrorZ Apr 9, 2014
8a2013c
fixed tabs
MirrorZ Apr 9, 2014
b8f5e6c
fixed tabs
MirrorZ Apr 9, 2014
cfb2dfb
Added a module for Nagios checkresult class
MirrorZ Apr 29, 2014
629b50b
Removed temp file
MirrorZ Apr 29, 2014
0d23801
included GPL license
MirrorZ Apr 29, 2014
fa1e390
removed NagiosCheckResult.py
MirrorZ Apr 29, 2014
d39271f
Added nagios_checkresult.py
MirrorZ Apr 29, 2014
a7416f0
Added build_host and build_service
MirrorZ May 10, 2014
0e73ac1
Exception handle for temfile added
MirrorZ May 13, 2014
858f6ae
Flexibility in Data sent to checkresult file
MirrorZ May 14, 2014
cda8781
Accept output string
MirrorZ May 14, 2014
8084076
send file time and checkresult time
MirrorZ May 15, 2014
8a29266
Accept file time and checkresult time
MirrorZ May 15, 2014
e2ff3ca
unit test for nagios_checkresult
MirrorZ May 17, 2014
4be2d9f
Added space in error message
MirrorZ May 28, 2014
76e8bfd
Converted tabs to spaces
MirrorZ Jun 2, 2014
8c517d1
Corrected try block
MirrorZ Jun 2, 2014
f6778f9
error in checkresult file creation handled by calling class
MirrorZ Jun 2, 2014
e4fb226
Handles error during creation of checkresult file
MirrorZ Jun 2, 2014
55aee79
Fixed indentation
MirrorZ Jun 2, 2014
73f4ab4
New config format
MirrorZ Jul 27, 2014
3d8526b
Added cluster defintion config format
MirrorZ Jul 28, 2014
857f1a2
Check for Hosts known by Nagios
MirrorZ Aug 5, 2014
83f5ad9
Config format
MirrorZ Aug 5, 2014
c6b48ce
Fixed indentation
MirrorZ Aug 5, 2014
cffd0d6
Fixed bugs in the parser for adding multiple metrics for same host
MirrorZ Aug 6, 2014
9e13e8b
Fixed error when no host matches
MirrorZ Aug 7, 2014
1d6515f
Added comments
MirrorZ Aug 9, 2014
7a759ed
Remove leading space while collecting hostnames from conf
MirrorZ Aug 14, 2014
d12788a
added default configuration file
MirrorZ Aug 15, 2014
38195a6
Removed sample.conf
MirrorZ Aug 15, 2014
6f51621
Added default path for conf file
MirrorZ Aug 15, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions conf_parser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#! /usr/bin/python

from configobj import ConfigObj,ConfigObjError


class ConfigParser:
def __init__(self):
self.clusters =[]

def parse (self,config_file):
try:
config = ConfigObj(config_file)

#get gmetad host information and nagios checkresult directory
self.gmetad_host = config.pop('gmetad_host')
self.gmetad_port = config.pop('gmetad_port')
self.force_dmax = config.pop('force_dmax')
self.tmax_grace = config.pop('tmax_grace')
self.strip_domains = config.pop('strip_domains')
self.nagios_result_dir = config.pop('nagios_result_dir')


for cluster_name in config.keys():
cluster_hosts = {}
#get hosts in the cluster
for host_name in config[cluster_name].keys():
metrics = []
#collect metric for each host in the cluster
for metric_name in config[cluster_name][host_name].keys():
metric_def = {}
metric_def['service_name'] = config[cluster_name][host_name][metric_name]['service_name']
if 'crit_above' in config[cluster_name][host_name][metric_name].keys():
metric_def['crit_above'] = config[cluster_name][host_name][metric_name]['crit_above']
metric_def['crit_below'] = None
if 'crit_below' in config[cluster_name][host_name][metric_name].keys():
metric_def['crit_below'] = config[cluster_name][host_name][metric_name]['crit_below']
metric_def['crit_above'] = None
if 'warn_above' in config[cluster_name][host_name][metric_name].keys():
metric_def['warn_above'] = config[cluster_name][host_name][metric_name]['warn_above']
metric_def['warn_below'] = None
if 'warn_below' in config[cluster_name][host_name][metric_name].keys():
metric_def['warn_below'] = config[cluster_name][host_name][metric_name]['warn_below']
metric_def['warn_above'] = None
metrics.append((metric_name,metric_def))
for host in host_name.split(','):
cluster_hosts.setdefault(host.lstrip(), []).append(metrics)
self.clusters.append((cluster_name,cluster_hosts))

except (ConfigObjError, IOError), e:
print 'Could not read %s' % (e)
87 changes: 87 additions & 0 deletions ganglia-nagios-bridge.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
gmetad_host = '127.0.0.1'
gmetad_port = 8649
# This overrides the DMAX attribute from all metrics in all hosts
# If DMAX > 0 and TN > DMAX, then a metric state is considered
# UNKNOWN and Nagios will potentially send an alert
force_dmax = 0

# Every collection group in gmond.conf defines a time_threshold
# This value appears as TMAX in the XML.
# The gmond process should normally send every metric again before
# the value timer TN > TMAX.
# If ganglia-nagios-bridge is polling a gmond collector
# then a very small tmax_grace period (perhaps 5 seconds) is used.
# If ganglia-nagios-bridge is polling a gmetad server then
# tmax_grace should be set higher than the polling interval configured
# in gmetad.
tmax_grace = 30

# Ganglia XML typically contains FQDNs for all hosts, as it obtains
# the hostnames using reverse DNS lookups. Nagios, on the other hand,
# is often configured with just the hostname and no domain. Setting
# strip_domains = True will ensure that the domain part is stripped from
# the hostname before passing it to Nagios.
strip_domains = True

# This is the directory where Nagios expects to read checkresults
# submitted in batch
nagios_result_dir = '/var/lib/nagios3/spool/checkresults'

# This is where we select the metrics that we want to map from
# Ganglia to Nagios service names
# Any metric not matched in the configuration will be ignored and
# not passed to Nagios.
# Defintion for multiple clusters and their hosts to be monitored
# along with their metrics is added in a nested format
#
# Format overview :
# cluster definiton specifying the clustername and hostnames and
# associated metrics to be monitored
#
# can add mutliple cluster names
# [cluster_name]
# Add comma separated host name(s) and and the common metrics to be monitored
# [[hostname(s) separated by ,]]
# Metric name of the metric to be monitored for the hostnames
# [[[metric name]]]
# metric attributes: corresponding service name and threshold values
# service_name =
# warn_above/below =
# crit_above/below =

# Sample configuration

[cluster_name]
[[host_01, host_02]]
[[[proc_total]]]
service_name = Total Processes
warn_above = 180
crit_above = 200
[[[load_one]]]
service_name = Current Load
warn_above = 0.1
crit_above = 0.3
[[host_02]]
[[[cpu_idle]]]
service_name = CPU IDLE
warn_above = 85
crit_above = 90
[[[disk_free]]]
service_name = DISK FREE
warn_below = 5
crit_below = 2
[[[cpu_speed]]]
service_name = CPU SPEED
warn_below = 2112
crit_below = 2000
[Production1]
[[host3, host12]]
[[[disk_free]]]
service_name = DISK FREE
warn_below = 10
crit_below = 5
[[host1]]
[[[cpu_speed]]]
service_name = CPU SPEED
warn_below = 2000
crit_below = 1890
Loading