From 0e1773b28c47f9e48e04b49ddc7a6ba83d32ad9b Mon Sep 17 00:00:00 2001 From: Kurtis Velarde Date: Fri, 8 Jun 2012 14:32:07 -0700 Subject: [PATCH 1/2] First monit module commit --- salt/modules/monit.py | 86 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 salt/modules/monit.py diff --git a/salt/modules/monit.py b/salt/modules/monit.py new file mode 100644 index 0000000000..a8f2d10291 --- /dev/null +++ b/salt/modules/monit.py @@ -0,0 +1,86 @@ +''' +Salt module to manage monit +''' + +def version(): + ''' + List monit version + + Cli Example:: + + salt '*' monit.version + ''' + + cmd = 'monit -V' + res = __salt__['cmd.run'](cmd) + return res.split("\n")[0] + + +def status(): + ''' + Monit status + + CLI Example:: + + salt '*' monit.status + ''' + cmd = 'monit status' + res = __salt__['cmd.run'](cmd) + return res.split("\n") + + +def start(): + ''' + Starts monit + + CLI Example:: + + salt '*' monit.start + *Note need to add check to insure its running* + `ps ax | grep monit | grep -v grep or something` + ''' + cmd = 'monit' + res = __salt__['cmd.run'](cmd) + return "Monit started" + + +def stop(): + ''' + Stop monit + + CLI Example:: + + salt '*' monit.stop + *Note Needs check as above* + ''' + def _is_bsd(): + return True if __grains__['os'] == 'FreeBSD' else False + + if _is_bsd(): + cmd = "/usr/local/etc/rc.d/monit stop" + else: + cmd = "/etc/init.d/monit stop" + res = __salt__['cmd.run'](cmd) + return "Monit Stopped" + + +def monitor_all(): + ''' + Initializing all monit modules. + ''' + cmd = 'monit monitor all' + res = __salt__['cmd.run'](cmd) + if res: + return "All Services initaialized" + return "Issue starting monitoring on all services" + + +def unmonitor_all(): + ''' + unmonitor all services. + ''' + cmd = 'monit unmonitor all' + res = __salt__['cmd.run'](cmd) + if res: + return "All Services unmonitored" + return "Issue unmonitoring all services" From 28353efe2802059c1da8b1c81b157dc6e773032e Mon Sep 17 00:00:00 2001 From: Kurtis Velarde Date: Sun, 10 Jun 2012 21:06:23 -0700 Subject: [PATCH 2/2] Check to see if we are going donw the right path --- salt/modules/monit.py | 86 +++++++++++-------------------------------- 1 file changed, 22 insertions(+), 64 deletions(-) diff --git a/salt/modules/monit.py b/salt/modules/monit.py index a8f2d10291..4eb8c53632 100644 --- a/salt/modules/monit.py +++ b/salt/modules/monit.py @@ -1,86 +1,44 @@ ''' -Salt module to manage monit +Monit service module. This module will create a monit type +service watcher. ''' -def version(): +import os + +def start(name): ''' - List monit version - - Cli Example:: - - salt '*' monit.version + + CLI Example:: + salt '*' monit.start ''' + cmd = "monit start {0}".format(name) - cmd = 'monit -V' - res = __salt__['cmd.run'](cmd) - return res.split("\n")[0] + return not __salt__['cmd.retcode'](cmd) -def status(): +def stop(name): ''' - Monit status + Stops service via monit CLI Example:: - salt '*' monit.status + salt '*' monit.stop ''' - cmd = 'monit status' - res = __salt__['cmd.run'](cmd) - return res.split("\n") + cmd = "monit stop {0}".format(name) -def start(): + return not __salt__['cmd.retcode'](cmd) + + +def restart(name): ''' - Starts monit + Restart service via monit CLI Example:: - salt '*' monit.start - *Note need to add check to insure its running* - `ps ax | grep monit | grep -v grep or something` + salt '*' monit.restart ''' - cmd = 'monit' - res = __salt__['cmd.run'](cmd) - return "Monit started" + cmd = "monit restart {0}".format(name) + return not __salt__['cmd.retcode'](cmd) -def stop(): - ''' - Stop monit - - CLI Example:: - - salt '*' monit.stop - *Note Needs check as above* - ''' - def _is_bsd(): - return True if __grains__['os'] == 'FreeBSD' else False - - if _is_bsd(): - cmd = "/usr/local/etc/rc.d/monit stop" - else: - cmd = "/etc/init.d/monit stop" - res = __salt__['cmd.run'](cmd) - return "Monit Stopped" - - -def monitor_all(): - ''' - Initializing all monit modules. - ''' - cmd = 'monit monitor all' - res = __salt__['cmd.run'](cmd) - if res: - return "All Services initaialized" - return "Issue starting monitoring on all services" - - -def unmonitor_all(): - ''' - unmonitor all services. - ''' - cmd = 'monit unmonitor all' - res = __salt__['cmd.run'](cmd) - if res: - return "All Services unmonitored" - return "Issue unmonitoring all services"