###############################################################################
## Monit Cr@ns Config !
###############################################################################
##
## Start Monit in the background (run as a daemon):
#
set daemon  60              # check services at 1-minute intervals
    with start delay 30     # optional: delay the first check by 4-minutes (by 
#                           # default Monit check immediately after Monit start)

set logfile syslog facility log_daemon                       
#set logfile /tmp/monit_log  # Test logging
#
## Set the location of the Monit id file which stores the unique id for the
## Monit instance. The id is generated and stored on first Monit start. By 
## default the file is placed in $HOME/.monit.id.
#
set idfile /var/.monit.id

# Bind and authorize only to localhost:
set httpd port 2812 and
    use address localhost
    allow localhost

#
## Set the location of the Monit state file which saves monitoring states
## on each cycle. By default the file is placed in $HOME/.monit.state. If
## the state file is stored on a persistent filesystem, Monit will recover
## the monitoring state across reboots. If it is on temporary filesystem, the
## state will be lost on reboot which may be convenient in some situations.
#
set statefile /var/.monit.state

## Check hostapd
check process hostapd-0 with pidfile /var/run/wifi-phy0.pid
	start program = "/usr/sbin/hostapd -P /var/run/wifi-phy0.pid -B /var/run/hostapd-phy0.conf" with timeout 60 seconds
	stop program = "/usr/bin/killall hostapd"
	if 5 restarts within 5 cycles then timeout

check process hostapd-1 with pidfile /var/run/wifi-phy1.pid
        start program = "/usr/sbin/hostapd -P /var/run/wifi-phy1.pid -B /var/run/hostapd-phy1.conf" with timeout 60 seconds
        stop program = "/usr/bin/killall hostapd"
        if 5 restarts within 5 cycles then timeout

check process sshd with pidfile /var/run/dropbear.1.pid
    start program  "/etc/init.d/dropbear start"
    stop program  "/etc/init.d/dropbear stop"
    if failed port 22 protocol ssh then restart
    if 5 restarts within 5 cycles then timeout

check program watch_net with path "/usr/share/watch_net/watch_net.sh"
       if status != 0 then alert

check process logread with pidfile /var/run/logread.2.pid
    start program  "/etc/init.d start"                                                                                   
    stop program  "/etc/init.d stop"                                   
    if 5 restarts within 5 cycles then timeout
