Ad Widget

Collapse

Restart service automatically

Collapse
This topic has been answered.
X
X
 
  • Time
  • Show
Clear All
new posts
  • MuRo
    Junior Member
    • Nov 2022
    • 4

    #1

    Restart service automatically

    Hi everyone and thanks in advance to everybody will answer my question, that is:

    the Systemd by Zabbix agent 2 template contains the following trigger: Systemd by Zabbix agent 2: {#UNIT.NAME}: Service is not running.

    If for instance the chrony service will be down the problem "chrony.service: Service is not running" will be notice.

    What I would like to do is create a one time script for restarting any service, not create a script for every single service.

    What I would like to do is create a one time script for restarting any service, not create a script for every single service. So what I would like is the following command:
    sudo /usr/bin/systemctl restart 'service to restart'​​​.

    I tried
    sudo /usr/bin/systemctl restart {TRIGGER.DESCRIPTION}
    ​sudo /usr/bin/systemctl restart {ITEM.VALUE1}
    but they don't work.

    How can I get the first chunk of the trigger name?
  • Answer selected by MuRo at 02-01-2023, 10:56.
    Semiadmin
    Senior Member
    • Oct 2014
    • 1625

    You may edit an item prototype tag a bit (for example, Systemd service: {#UNIT.NAME} instead of Application: Systemd service: {#UNIT.NAME})
    and use the {EVENT.TAGS."Systemd service"} macro in the script.​

    Comment


    • MuRo
      MuRo commented
      Editing a comment
      Great, it works!
      Thank you so much!
  • Semiadmin
    Senior Member
    • Oct 2014
    • 1625

    #2
    You may edit an item prototype tag a bit (for example, Systemd service: {#UNIT.NAME} instead of Application: Systemd service: {#UNIT.NAME})
    and use the {EVENT.TAGS."Systemd service"} macro in the script.​

    Comment


    • MuRo
      MuRo commented
      Editing a comment
      Great, it works!
      Thank you so much!
  • cyber
    Senior Member
    Zabbix Certified SpecialistZabbix Certified Professional
    • Dec 2006
    • 4807

    #3
    None of those you tried contain actual service name I think... Treiger description may or may not exist and item value is either 0 or 1 or something...
    IIRC someone suggested here lately to use tags for this. You should create an tag in trigger during discovery a la Service => {#UNIT.NAME} and later use that tag value via {EVENT.TAGS.Service} macro in yout script.

    EDIT> and while I wrote it, same thing was sugested..

    Comment


    • MuRo
      MuRo commented
      Editing a comment
      Thanks a lot for the answer, it works!
Working...