mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Change from a module config file to brute force locating the nagios configs so we can find the command file.
This commit is contained in:
parent
4caf85e37b
commit
6b73907811
1 changed files with 36 additions and 25 deletions
|
@ -31,44 +31,50 @@ Action Summaries (all must be delegate_to'd a nagios server):
|
||||||
action: nagios action=enable_alerts service=host host=$inventory_hostname
|
action: nagios action=enable_alerts service=host host=$inventory_hostname
|
||||||
action: nagios action=disable_alerts services=httpd,git,nfs host=$inventory_hostname
|
action: nagios action=disable_alerts services=httpd,git,nfs host=$inventory_hostname
|
||||||
|
|
||||||
|
Note: 'service' is an alias for 'services'. Separate multiple services
|
||||||
|
with commas.
|
||||||
|
|
||||||
Note: 'service' is an alias for 'services'.
|
Set the path to the command file explicitly with the 'cmdfile'
|
||||||
Separate multiple services with commas.
|
parameter.
|
||||||
|
|
||||||
|
|
||||||
Configuration:
|
|
||||||
|
|
||||||
If your nagios cmdfile is not /var/spool/nagios/cmd/nagios.cmd you
|
|
||||||
can configure ansible (on your nagios server) to use the correct
|
|
||||||
one by making a file called /etc/ansible/modules/nagios.conf that
|
|
||||||
looks like this:
|
|
||||||
|
|
||||||
[main]
|
|
||||||
cmdfile = /path/to/your/nagios.cmd
|
|
||||||
|
|
||||||
When calling this module via ansible, use the 'cmdfile' parameter to
|
|
||||||
set it explicitly.
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
import ConfigParser
|
import ConfigParser
|
||||||
import types
|
import types
|
||||||
import time
|
import time
|
||||||
|
import os.path
|
||||||
MODULE_CONFIG = '/etc/ansible/modules/nagios.conf'
|
|
||||||
DEFAULT_CMDFILE = '/var/spool/nagios/cmd/nagios.cmd'
|
|
||||||
|
|
||||||
######################################################################
|
######################################################################
|
||||||
|
|
||||||
|
|
||||||
def which_cmdfile():
|
def which_cmdfile():
|
||||||
try:
|
locations = [
|
||||||
config = ConfigParser.SafeConfigParser({'cmdfile': DEFAULT_CMDFILE})
|
# rhel
|
||||||
config.read(MODULE_CONFIG)
|
'/etc/nagios/nagios.cfg',
|
||||||
return config.get('main', 'cmdfile')
|
# debian
|
||||||
except:
|
'/etc/nagios3/nagios.cfg',
|
||||||
return DEFAULT_CMDFILE
|
# older debian
|
||||||
|
'/etc/nagios2/nagios.cfg',
|
||||||
|
# bsd, solaris
|
||||||
|
'/usr/local/etc/nagios/nagios.cfg',
|
||||||
|
# groundwork it monitoring
|
||||||
|
'/usr/local/groundwork/nagios/etc/nagios.cfg',
|
||||||
|
# open monitoring distribution
|
||||||
|
'/omd/sites/oppy/tmp/nagios/nagios.cfg',
|
||||||
|
# ???
|
||||||
|
'/usr/local/nagios/etc/nagios.cfg',
|
||||||
|
'/usr/local/nagios/nagios.cfg',
|
||||||
|
'/opt/nagios/etc/nagios.cfg',
|
||||||
|
'/opt/nagios/nagios.cfg'
|
||||||
|
]
|
||||||
|
|
||||||
|
for path in locations:
|
||||||
|
if os.path.exists(path):
|
||||||
|
for line in open(path):
|
||||||
|
if line.startswith('command_file'):
|
||||||
|
return line.partition('=')[2].strip()
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
######################################################################
|
######################################################################
|
||||||
|
|
||||||
|
@ -96,6 +102,7 @@ def main():
|
||||||
action = module.params['action']
|
action = module.params['action']
|
||||||
minutes = module.params['minutes']
|
minutes = module.params['minutes']
|
||||||
services = module.params['services']
|
services = module.params['services']
|
||||||
|
cmdfile = module.params['cmdfile']
|
||||||
|
|
||||||
##################################################################
|
##################################################################
|
||||||
# Required args per action:
|
# Required args per action:
|
||||||
|
@ -124,6 +131,10 @@ def main():
|
||||||
if not services:
|
if not services:
|
||||||
module.fail_json(msg='a service is required when setting alerts')
|
module.fail_json(msg='a service is required when setting alerts')
|
||||||
|
|
||||||
|
##################################################################
|
||||||
|
if not cmdfile:
|
||||||
|
module.fail_json('unable to locate nagios.cfg')
|
||||||
|
|
||||||
##################################################################
|
##################################################################
|
||||||
ansible_nagios = Nagios(module, **module.params)
|
ansible_nagios = Nagios(module, **module.params)
|
||||||
ansible_nagios.act()
|
ansible_nagios.act()
|
||||||
|
|
Loading…
Reference in a new issue