161
163
log('Check command not found: {}'.format(parts[0]))
164
def write(self, nagios_context, hostname, nagios_servicegroups=None):
166
def write(self, nagios_context, hostname, nagios_servicegroups):
165
167
nrpe_check_file = '/etc/nagios/nrpe.d/{}.cfg'.format(
167
169
with open(nrpe_check_file, 'w') as nrpe_check_config:
177
179
nagios_servicegroups)
179
181
def write_service_config(self, nagios_context, hostname,
180
nagios_servicegroups=None):
182
nagios_servicegroups):
181
183
for f in os.listdir(NRPE.nagios_exportdir):
182
184
if re.search('.*{}.cfg'.format(self.command), f):
183
185
os.remove(os.path.join(NRPE.nagios_exportdir, f))
185
if not nagios_servicegroups:
186
nagios_servicegroups = nagios_context
189
188
'nagios_hostname': hostname,
190
189
'nagios_servicegroup': nagios_servicegroups,
211
210
super(NRPE, self).__init__()
212
211
self.config = config()
213
212
self.nagios_context = self.config['nagios_context']
214
if 'nagios_servicegroups' in self.config:
213
if 'nagios_servicegroups' in self.config and self.config['nagios_servicegroups']:
215
214
self.nagios_servicegroups = self.config['nagios_servicegroups']
217
self.nagios_servicegroups = 'juju'
216
self.nagios_servicegroups = self.nagios_context
218
217
self.unit_name = local_unit().replace('/', '-')
220
219
self.hostname = hostname
322
321
check_cmd='check_status_file.py -f '
323
322
'/var/lib/nagios/service-check-%s.txt' % svc,
326
def copy_nrpe_checks():
328
Copy the nrpe checks into place
331
NAGIOS_PLUGINS = '/usr/local/lib/nagios/plugins'
332
nrpe_files_dir = os.path.join(os.getenv('CHARM_DIR'), 'hooks',
333
'charmhelpers', 'contrib', 'openstack',
336
if not os.path.exists(NAGIOS_PLUGINS):
337
os.makedirs(NAGIOS_PLUGINS)
338
for fname in glob.glob(os.path.join(nrpe_files_dir, "check_*")):
339
if os.path.isfile(fname):
341
os.path.join(NAGIOS_PLUGINS, os.path.basename(fname)))
344
def add_haproxy_checks(nrpe, unit_name):
346
Add checks for each service in list
348
:param NRPE nrpe: NRPE object to add check to
349
:param str unit_name: Unit name to use in check description
352
shortname='haproxy_servers',
353
description='Check HAProxy {%s}' % unit_name,
354
check_cmd='check_haproxy.sh')
356
shortname='haproxy_queue',
357
description='Check HAProxy queue depth {%s}' % unit_name,
358
check_cmd='check_haproxy_queue_depth.sh')