'''
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"

'''
Monit service module. This module will create a monit type 
service watcher.
'''

import os

def start(name):
    '''
   
    CLI Example::
    salt '*' monit.start <service name>
    '''
    cmd = "monit start {0}".format(name)

    return not __salt__['cmd.retcode'](cmd)


def stop(name):
    '''
    Stops service via monit

    CLI Example::

        salt '*' monit.stop <service name>
    '''
    cmd = "monit stop {0}".format(name)


    return not __salt__['cmd.retcode'](cmd)


def restart(name):
    '''
    Restart service via monit

    CLI Example::

        salt '*' monit.restart <service name>
    '''
    cmd = "monit restart {0}".format(name)

    return not __salt__['cmd.retcode'](cmd)


Check to see if we are going donw the right path
Check to see if we are going donw the right path

  '''
- 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.start <service name>
+     '''
+     cmd = "monit start {0}".format(name)
  
-     Cli Example::
- 
-         salt '*' monit.version
-     '''
- 
-     cmd = 'monit -V'
-     res = __salt__['cmd.run'](cmd)
+     return not __salt__['cmd.retcode'](cmd)
-     return res.split("\n")[0]
  
  
- def status():
+ def stop(name):
      '''
-     Monit status
+     Stops service via monit
  
      CLI Example::
  
-         salt '*' monit.status
+         salt '*' monit.stop <service name>
      '''
+     cmd = "monit stop {0}".format(name)
-     cmd = 'monit status'
-     res = __salt__['cmd.run'](cmd)
-     return res.split("\n")
  
  
+     return not __salt__['cmd.retcode'](cmd)
+ 
+ 
- def start():
+ def restart(name):
      '''
-     Starts monit
+     Restart service via monit
  
      CLI Example::
  
-         salt '*' monit.start
+         salt '*' monit.restart <service name>
-     *Note need to add check to insure its running*
-     `ps ax | grep monit | grep -v grep or something`
      '''
-     cmd = 'monit'
+     cmd = "monit restart {0}".format(name)
+ 
-     res = __salt__['cmd.run'](cmd)
+     return not __salt__['cmd.retcode'](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"
- 
Check to see if we are going donw the right path
## Code Before:
'''
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"

## Instruction:
Check to see if we are going donw the right path
## Code After:
'''
Monit service module. This module will create a monit type 
service watcher.
'''

import os

def start(name):
    '''
   
    CLI Example::
    salt '*' monit.start <service name>
    '''
    cmd = "monit start {0}".format(name)

    return not __salt__['cmd.retcode'](cmd)


def stop(name):
    '''
    Stops service via monit

    CLI Example::

        salt '*' monit.stop <service name>
    '''
    cmd = "monit stop {0}".format(name)


    return not __salt__['cmd.retcode'](cmd)


def restart(name):
    '''
    Restart service via monit

    CLI Example::

        salt '*' monit.restart <service name>
    '''
    cmd = "monit restart {0}".format(name)

    return not __salt__['cmd.retcode'](cmd)

