Config generrator/templating

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Config generrator/templating

David Jones
Anyone know of a config file generator or templating system for monit?  I created my own scripts to run from cron that would detect items to be monitored dynamically.

For example, if someone installs a new package like mariadb on a server, the script would detect the PID file or use "monit procmatch" to create/update /etc/monit.d/mariadb.cfg.  Or if someone creates a new /etc/swatch.d/example.conf then add/update the /etc/monit.d/swatch.cfg.

This dynamic updating capability is very useful.  Maybe this could be done with a simple verb option that would allow for something like "depends on" but doesn't cause an error.  This would simple not load sections and their dependents when a check fails.

check process mariadb_proc with path /var/run/mariadb.pid
    active when exec "/bin/rpm -q mariadb-server"

check file mariadb_my_cnf with path /etc/my.cnf
    depends on mariadb_proc

Then the first process won't load when the package isn't installed and the second file won't error because it depends on the first.  I don't want to use the unmonitor and have a hundred items in the "monitor summary" output.

Also, I scripted a generator for /etc/monit.d/filesystems.cfg that will automatically monitor all local filesystems with different thresholds based on the size of the volume.  Smaller filesystems will get the standard 90% used threshold but larger ones in the hundreds of GBs  or TBs will hae a 95% or 98% threshold

Thanks,
Dave

--
To unsubscribe:
https://lists.nongnu.org/mailman/listinfo/monit-general
Reply | Threaded
Open this post in threaded view
|

Re: Config generrator/templating

Lutz Mader
Hello David,
I use m4 to generate my Monit config files based on some more or less
complex macro files, like this one.

dnl
dnl Monit configuration file.
dnl Check the Glassfish program status.
dnl
ifdef(`CF_HOMEDIR',`',`define(`CF_HOMEDIR',`syscmd(`printf "%s"
"$HOME"')')')dnl
dnl
ifdef(`CF_HOST',`',`define(`CF_HOST',`syscmd(`printf "%s"
"$(hostname)"')')')dnl
ifdef(`CF_PORT',`',`define(`CF_PORT',`8080')')dnl
ifdef(`CF_APPL',`',`define(`CF_APPL',`domain1')')dnl
ifdef(`CF_SOFTDIR',`',`define(`CF_SOFTDIR',`/usr/local')')dnl
dnl
#
## Check the Glassfish program status.
#
check process Domain1 with matching "CF_SOFTDIR()/.*/bin/java
.*glassfish.jar .*CF_APPL()*"
  start program "CF_HOMEDIR()/monit/scripts/glassfish start" with
timeout 300 seconds
  stop program "CF_HOMEDIR()/monit/scripts/glassfish stop" with timeout
300 seconds
  if failed host CF_HOST() port CF_PORT() then restart
  if 3 restarts within 50 cycles then unmonitor
  group AppDynamics
#

And I create the Monit config file by calling m4 with some additional
names and values.

m4 -DCF_SOFTDIR=/usr/local -DCF_HOMEDIR=/home/glassfish glassfish.m4

#
## Check the Glassfish program status.
#
check process Domain1 with matching "/usr/local/.*/bin/java
.*glassfish.jar .*domain1.*"
  start program "/home/glassfish/monit/scripts/glassfish start" with
timeout 300 seconds
  stop program "/home/glassfish/monit/scripts/glassfish stop" with
timeout 300 seconds
  if failed host macmini.local port 8080 then restart
  if 3 restarts within 50 cycles then unmonitor
  group Glassfish
#

This is my way to configure Monit.
I use some automatic Monit configurations updates based on detecting
application folder updates only.

A suggestion only,
m4 is old, but nice,
Lutz

--
To unsubscribe:
https://lists.nongnu.org/mailman/listinfo/monit-general