Ad Widget

Collapse

Monitor cronjobs

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Preexo
    Junior Member
    • Apr 2016
    • 7

    #1

    Monitor cronjobs

    I have installed a Zabbix 3.0.1 server and I'm now monitoring my whole internal network with it, all VM's an servers running here. It's working really nice and saving me some headache already.

    Every one of those machines has some cronjobs running, some more frequent like 6 times a day, others only once a day or every other day.
    Some cronjobs are actually making backups. Currently I am still sending out emails after every successful backup, but I thought if the following might be possible:

    - every time a cronjob is being executed, the cronjob tells the agent that it was successful
    - the agent tells the server
    - only if the server hasn't heard about a successful cronjob execution in a while, it will send an email to me.

    I am pretty sure this is something that I can do with zabbix, but I have trouble finding an example or a starting point for this.

    Thanks for any help in advance!
  • efiala
    Junior Member
    • Apr 2016
    • 1

    #2
    Monitoring cronjobs

    Preexo,
    I too was frustrated with having all this noise from positive cron emails on successful runs from my servers.

    After exhaustively trying to figure out a native Zabbix solution for this problem (this involved watching modified time one some file that was written to on tailend of the cron run)... it worked but felt very fragile especially for more exotic schedules like you describe.

    I opted to go externally and use a service called watchdog timer http://wdt.io it does exactly what you describe, you only see alerts when the cron fails to run or does not execute, very flexible schedules and alerting options.

    I am long time zabbix user and I'm interested what else the community has to say on this topic.

    Comment

    • Preexo
      Junior Member
      • Apr 2016
      • 7

      #3
      Thanks for your input. The service on http://wdt.io makes a friendly impression, I will keep it in mind.
      But I am not ready to give up yet, I want to try to get this running with zabbix at least for one server.

      I am also hoping for some more feedback, to me this is a very common problem, I have been monitoring backup cronjobs like this for the last 10 years lol, but I thought there might be a better alternative and zabbix looked like it could do anything if you know the right recipe...
      So I am looking for the recipe at the moment

      Comment

      • Preexo
        Junior Member
        • Apr 2016
        • 7

        #4
        Thanks a lot for your input,
        the wdt.io makes a user friendly impression, I will keep this in mind for future projects.

        But I am not ready to give up on doing this with zabbix yet.
        I have been monitoring my backups that way forever and seen others do it that way too, but I am sure that zabbix can do it too, it just depends on the right recipe, so I am looking for the right recipe at the moment, but it got too complex too quickly for me to do this without any help.

        I am also wondering what the community says about this topic.
        Looking forward for more feedback thanks

        Comment

        • Preexo
          Junior Member
          • Apr 2016
          • 7

          #5
          I managed it following those instructions here: http://stackoverflow.com/a/34952605/1011116

          My backup cron script contains:
          statusfile="/var/lib/shared/websites/newsletter/backup/status.log"
          set -e
          echo "FAIL" > "$statusfile"
          [backup procedure]
          echo "OK" > "$statusfile"
          echo $(( ( RANDOM % 100000 ) + 1 )) >> "$statusfile"

          Item 1 Key:
          vfs.file.time[/var/lib/shared/websites/newsletter/backup/status.log,modify]
          Item 2 Key:
          vfs.file.regmatch[/var/lib/shared/websites/newsletter/backup/status.log,OK]

          Trigger:
          {msa-web:vfs.file.time[/var/lib/shared/websites/newsletter/backup/status.log,modify].fuzzytime(1d)}=0
          or
          {msa-web:vfs.file.regmatch[/var/lib/shared/websites/newsletter/backup/status.log,OK].last()}=0

          Comment

          • pc99096
            Senior Member
            • Oct 2011
            • 193

            #6
            why don't you simply use zabbix_sender?

            Comment

            • Preexo
              Junior Member
              • Apr 2016
              • 7

              #7
              Originally posted by pc99096
              why don't you simply use zabbix_sender?
              https://www.zabbix.com/documentation...oncepts/sender
              Intersting... I didn't know about that yet... But so far I am not seeing how this would make anything easier. Why would you recommend that over the way I did it in the end?
              Thanks for the reply, best regards

              Comment

              • pc99096
                Senior Member
                • Oct 2011
                • 193

                #8
                it seems more elegant to me, instead of generating random numbers and
                echo STATUS > "$statusfile"

                you send the status directly to zabbix server via zabbix_sender - either OK or NOT OK. based on the string received, zabbix can trigger an alert.
                or it can also trigger an alert if there is nothing received in some predefined period (zabbix nodata (sec) function).

                Comment

                • Preexo
                  Junior Member
                  • Apr 2016
                  • 7

                  #9
                  Originally posted by pc99096
                  it seems more elegant to me, instead of generating random numbers and
                  echo STATUS > "$statusfile"

                  you send the status directly to zabbix server via zabbix_sender - either OK or NOT OK. based on the string received, zabbix can trigger an alert.
                  or it can also trigger an alert if there is nothing received in some predefined period (zabbix nodata (sec) function).
                  Thanks for the explanation! I agree, it seems more elegant. I think this approach would also only require one item (instead of two) in the host.
                  Since I have already finished the monitor setup, I will do it with the next server that is being added to the system.
                  Thanks a lot!

                  Comment

                  • Preexo
                    Junior Member
                    • Apr 2016
                    • 7

                    #10
                    Originally posted by pc99096
                    it seems more elegant to me, instead of generating random numbers and
                    echo STATUS > "$statusfile"

                    you send the status directly to zabbix server via zabbix_sender - either OK or NOT OK. based on the string received, zabbix can trigger an alert.
                    or it can also trigger an alert if there is nothing received in some predefined period (zabbix nodata (sec) function).
                    I ended up redoing it the way you proposed and it is much more straight forward! It's much easier to comprehend by everyone else and it provides a pretty reliably system of monitoring my cron jobs.
                    Thanks!

                    Comment

                    • Edwin Eefting
                      Junior Member
                      • Oct 2015
                      • 4

                      #11
                      I've created a script + LLD template to do flexible cronjob monitoring:

                      Random stuff and scripts. Contribute to psy0rz/stuff development by creating an account on GitHub.


                      Edwin

                      Comment

                      • kolele
                        Junior Member
                        • Nov 2016
                        • 11

                        #12
                        Originally posted by Edwin Eefting
                        I've created a script + LLD template to do flexible cronjob monitoring:

                        Random stuff and scripts. Contribute to psy0rz/stuff development by creating an account on GitHub.


                        Edwin
                        How to use this script ?

                        Comment

                        Working...