Skip to content
Open
Changes from all commits
Commits
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
40 changes: 22 additions & 18 deletions ganglia-nagios-bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def handle_metric(self, metric_name, service_name, attrs):
self.value_handler.process(self.metric, service_name, self.host_name, metric_name, metric_value, metric_tn, metric_tmax, metric_dmax, last_seen)

# main program code
if __name__ == '__main__':
if __name__ == '__main__':
try:
# parse command line
parser = argparse.ArgumentParser(description='read Ganglia XML and generate Nagios check results file')
Expand All @@ -221,22 +221,26 @@ def handle_metric(self, metric_name, service_name, attrs):
metrics.append((metric_c, metric_def[1]))
hosts.append((host_c, metrics))
clusters_c.append((cluster_c, hosts))

# connect to the gmetad or gmond
sock = socket.create_connection((gmetad_host, gmetad_port))
# set up the SAX parser
parser = xml.sax.make_parser()
pg = PassiveGenerator(force_dmax)
parser.setContentHandler(GangliaHandler(clusters_c, pg))
# run the main program loop
parser.parse(SocketInputSource(sock))

# write out for Nagios
pg.done()

# all done
sock.close()
except socket.error as e:
logging.warn('Failed to connect to gmetad: %s', e.strerror)
except Exception as e:
logging.warn('Failed to read configuration file: %s', e)
while True:
try:
# connect to the gmetad or gmond
sock = socket.create_connection((gmetad_host, gmetad_port))
# set up the SAX parser
parser = xml.sax.make_parser()
pg = PassiveGenerator(force_dmax)
parser.setContentHandler(GangliaHandler(clusters_c, pg))
# run the main program loop
parser.parse(SocketInputSource(sock))

# write out for Nagios
pg.done()

# all done
sock.close()
time.sleep(60)
except socket.error as e:
logging.warn('Failed to connect to gmetad: %s', e.strerror)