# Monit - don't alert at certain times



## xy16644 (May 10, 2015)

I have Monit monitoring my spamassasin and spamass-milter. When it finds it has stopped it restarts them as per the /usr/local/etc/monitrc:


```
# Spamassasin - spamd
check process sa-spamd with pidfile /var/run/spamd/spamd.pid
  start program = "/usr/local/etc/rc.d/sa-spamd start"
  stop program = "/usr/local/etc/rc.d/sa-spamd stop"

# Spamassasin - milter
check process spamass-milter
  matching "spamass-milter"
  start program = "/usr/local/etc/rc.d/spamass-milter start"
  stop program = "/usr/local/etc/rc.d/spamass-milter stop"
  if failed unixsocket /var/run/spamass-milter/spamass-milter.sock then restart
  if 3 restarts within 5 cycles then timeout
```

I also have a cron job that updates the spamassasin rules each day at 6am:


```
#!/bin/sh

# Update Spamassasin rules:
/usr/local/bin/sa-update

# Restart Spamassasin:
service sa-spamd restart

# Restart spamass-milter:
service spamass-milter restart
```

After the cron job runs to update the Spamassasin rules Monit alerts me that the service does not exist and restarts it and I receive 4 emails: One each for sa-spamd and spamass-milter stopping and then for the starting again.

Is it possible to NOT receive these emails at 6am when these daemons are restarted to apply the new spamassasin rules? ie: I want to be alerted via email when these daemons are stopped/restarted EXCEPT when it happens at 6am.

Is this possible? Maybe I could set a timeout that says: Only alert via email if sa-spamd or spamass-milter don't respond for 60 (or whatever) seconds?


----------



## junovitch@ (May 10, 2015)

monit(1) mentions some stuff you can do under "SERVICE POLL TIME".  Perhaps a configuration similar to example 3 regarding excluding MySQL monitoring during backup windows would be appropriate in your situation.


----------



## xy16644 (May 10, 2015)

Thats so weird, I was just reading up on the service poll time.

I have tried:


```
check process sa-spamd with pidfile /var/run/spamd/spamd.pid
  every 2 cycles
  start program = "/usr/local/etc/rc.d/sa-spamd start"
  stop program = "/usr/local/etc/rc.d/sa-spamd stop"
```

but I'm still receiving an alert email!


----------



## junovitch@ (May 10, 2015)

With the every 2 cycles all it would take is timing to have the check hit during the same time the cron entry runs.   Excluding a short window for when that runs may be the best option.


----------



## xy16644 (May 10, 2015)

I have tried adding:


```
not every "0-5 6 * * *"
```

to say that I don't want monitoring/alerting between 6:00 to 6:05 so I'll see how that goes tomorrow. Seems to work if I put in the current time! 

Thanks for the assistance!


----------



## SirDice (May 11, 2015)

You can change your update scripts to do something like this:

```
monit stop sa-spamd
{run your updates}
monit start sa-spamd
```
The `monit stop` will stop the service but will also stop monitoring it (so you don't get an alert), a `monit start` will start the service again and start monitoring. You can also do something like this:

```
monit unmonitor sa-spamd
{run your update code}
service sa-spamd restart
monit monitor sa-spamd
```

The added bonus of doing it this way is that you can run the script at any time without generating an alert.


----------



## junovitch@ (May 11, 2015)

Thanks SirDice.  Good thinking.

xy16644, I would go with the above solution.  The schedule solution may work but is fragile since any deviation from that window would break things.


----------

