Ad Widget

Collapse

How to monitor a specific service

Collapse
This topic has been answered.
X
X
 
  • Time
  • Show
Clear All
new posts
  • cmartinez127
    Junior Member
    • Sep 2023
    • 14

    #1

    How to monitor a specific service

    Greetings,

    We need to monitor a specific service only in one host. In this case we want to monitor "mailgun" service.
    Click image for larger version

Name:	image.png
Views:	3175
Size:	26.8 KB
ID:	479657

    So we followed an old guide we found but didn't work. We did this:

    First of all, we created an Item with the following values and using 'system.run["systemctl status mailgun"]' key. (We don't know if 'system.run["systemctl is-active mailgun"]' would work too, we don't have preferences, just want it to work any possible way).
    Click image for larger version

Name:	image.png
Views:	3119
Size:	49.0 KB
ID:	479659

    However, it says "Unsopported item key".
    Click image for larger version

Name:	image.png
Views:	3136
Size:	23.9 KB
ID:	479660

    Then we created a Trigger​ which obviously won't work.
    Click image for larger version

Name:	image.png
Views:	3100
Size:	58.1 KB
ID:	479661
    Click image for larger version

Name:	image.png
Views:	3132
Size:	11.2 KB
ID:	479662

    Can anyone help us to monitor a specific service in a host like "mailgun"? We don't know if we were on the right track, so if the way to do this is completely different provide us a new way without any kind of problem.

    Best regards.​
    Attached Files
  • Answer selected by cmartinez127 at 28-02-2024, 14:45.
    cyber
    Senior Member
    Zabbix Certified SpecialistZabbix Certified Professional
    • Dec 2006
    • 4807

    I am pretty sure that "systemctl status mailgun.service | grep 'active (running)'" does not return 0 or 1 as answer (grep -c returns number of matches..) so trying to create a expression last()=0 does not work... First of all, identify, what it actually returns and then use that in your expression..

    And please.. use replies to answer, not comment... It makes impossible to quote you and looks like I am talking to myself here...

    Comment

    • cmartinez127
      Junior Member
      • Sep 2023
      • 14

      #2
      I didn't mention we are using Zabbix 5.4.6. version.

      Comment

      • cyber
        Senior Member
        Zabbix Certified SpecialistZabbix Certified Professional
        • Dec 2006
        • 4807

        #3
        system.run is by default disabled. You may need to enable it first... https://www.zabbix.com/documentation...estrict_checks

        By installing agent2, you could use built-in keys... systemd.unit.* https://www.zabbix.com/documentation.../zabbix_agent2

        Comment


        • cmartinez127
          cmartinez127 commented
          Editing a comment
          This is great help, thanks. This "systemd.unit.info[mailgun.service]" would solve my problem. Unfortunately the device I need to monitor only allows Agent 1. It's a Zabbix Server 5.4.6. and the device to monitor an Ubuntu 22.04 (Jammy), For example, with that Zabbix Server version the previous Ubuntu version 20.04 (Focal) is compatible with Agent 2.

          EDIT: I tried 'system.run["systemctl status mailgun.service"]' which works with Agent1. What's the Expression I should use to create the trigger that will warn me if service is not active?
          Last edited by cmartinez127; 27-02-2024, 14:33.
      • cyber
        Senior Member
        Zabbix Certified SpecialistZabbix Certified Professional
        • Dec 2006
        • 4807

        #4
        As I said, system.run is by default disabled.. try to enable it (Link above) and you may get things done with agent1 also.

        Comment


        • cmartinez127
          cmartinez127 commented
          Editing a comment
          Yes, I enabled it with the link above and works, now I just need the trigger Expression. I tried this:
          last(/host_name_example/system.run["systemctl status mailgun.service | grep 'active (running)'"])=0

          But it's not working.

          EDIT: If I run the following command from Zabbix Server it works, but it isn't working when applied in the trigger, it doesn't give error messages. I try to disable mailgun service to test and it never appears an alert about this on the dashboard.
          zabbix_get -s hostname_example -p 10050 -k system.run["systemctl status mailgun.service | grep 'active (running)'"]
          Last edited by cmartinez127; 27-02-2024, 15:07.
      • cyber
        Senior Member
        Zabbix Certified SpecialistZabbix Certified Professional
        • Dec 2006
        • 4807

        #5
        I am pretty sure that "systemctl status mailgun.service | grep 'active (running)'" does not return 0 or 1 as answer (grep -c returns number of matches..) so trying to create a expression last()=0 does not work... First of all, identify, what it actually returns and then use that in your expression..

        And please.. use replies to answer, not comment... It makes impossible to quote you and looks like I am talking to myself here...

        Comment

        • cmartinez127
          Junior Member
          • Sep 2023
          • 14

          #6
          Sorry for commenting instead of replying.

          Thanks to your suggestion about using "grep -c", now the following trigger expression works as expected:
          last(/hostname_example/system.run["systemctl status mailgun.service | grep -c 'active (running)'"])=0

          Comment

          Working...