Ad Widget

Collapse

Start windows service from zabbix console via script?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • louis-m
    Member
    • Nov 2013
    • 70

    #1

    Start windows service from zabbix console via script?

    Anybody know how to start a windows service from the zabbix console ie a trigger has gone off saying service x has stopped.
    Right click > script which starts the service?
    I know the script will have C:\windows\system32\sc start <servicename> but how do you get the <servicename> from the trigger? eg {TRIGGER.VALUE}
  • icol
    Member
    • Aug 2014
    • 31

    #2
    Maintenance

    Hi
    Why would you like to do that?
    Normaly a service window is created for a planned work, like patching, upfgrades and so on. So before you do your work you creare a maintenance in zabbix
    If you don't want to creat it manually you clould use the api https://www.zabbix.com/documentation...tenance/create

    Comment

    • louis-m
      Member
      • Nov 2013
      • 70

      #3
      Hi,
      it's just an option really. Sometimes we might want to restart a windows service and if we are in the zabbix gui and we have a list of those services, we might want to restart them manually rather than go to the server itself etc

      Comment

      • icol
        Member
        • Aug 2014
        • 31

        #4
        Actions

        To do that you need to go to Configuration/Actions and configure one action

        Write the name and the conditions to trigger an actions like:

        Maintenance status not on manatenance
        Trigger name like <trigger name>

        Go o next tab and configure a operation.
        click new for a new operation

        There you can configure a Remote command (in field operation type)
        In target list write the host you want to execute the operation
        Execute in Zabbix Agent
        Command: net start "<service name>"

        Comment

        • louis-m
          Member
          • Nov 2013
          • 70

          #5
          Hi,
          yes I'm aware that can be done. I don't want to have to write the service name in particular into the script but rather get a variable passed eg from a trigger
          For instance, let's just say a trigger has come up with "Print Spooler" stopped on HOST A
          Now I know I could go into the host itself and start it etc but it would be handy if I could do this from the Zabbix GUI by net start {TRIGGER.VALUE}

          It's a nice to have that's all.

          Comment

          • zimeon
            Junior Member
            • Mar 2015
            • 10

            #6
            Has anyone found a possible solution to this? I've tried with tags but they are not available when running a script from the GUI dropdown.

            Comment

            • CristianR
              Junior Member
              • Apr 2023
              • 12

              #7
              Hello,

              Is there any solution for making available the name of the service when running the script from the problem dashboard?

              Thank you.

              Cristian

              Comment

              • markosa
                Senior Member
                Zabbix Certified SpecialistZabbix Certified ProfessionalZabbix Certified Expert
                • Aug 2022
                • 104

                #8
                So {ITEM.VALUE} isn't working? Atleast for me it's working, I've created script for manual event action and from there i do get value which is assigned to event. Script used for testing: echo {ITEM.VALUE} {TRIGGER.NAME} >> /tmp/test_dummy.txt

                Comment

                • CristianR
                  Junior Member
                  • Apr 2023
                  • 12

                  #9
                  markosa , thank you very much for your input. It works with the {TRIGGER.NAME}. Previously I was trying on the host menu instead of event menu that's why it did not work.

                  Though I am still not able to extract a piece of information from the {TRIGGER.NAME}.
                  This is my code:
                  Code:
                  c:/windows/system32/WindowsPowerShell/v1.0/powershell.exe {TRIGGER.NAME}.Split('"')[0] | Start-Service
                  The {TRIGGER.NAME} returns the text in this form: "abc-cloud-config-server" (ABC Cloud Config Server) is not running (startup type automatic) . What I need is to get only the first part of the string which in our example is abc-cloud-config-server

                  Any ideas?

                  Thank you.
                  Attached Files
                  Last edited by CristianR; 25-04-2023, 09:54.

                  Comment

                  • markosa
                    Senior Member
                    Zabbix Certified SpecialistZabbix Certified ProfessionalZabbix Certified Expert
                    • Aug 2022
                    • 104

                    #10
                    How about {ITEM.VALUE} or {ITEM.VALUE1} or {ITEM.VALUE2} ? What does those return? I think that you should have within some value that service name, trigger name is partly built from item values/names

                    Comment

                    • CristianR
                      Junior Member
                      • Apr 2023
                      • 12

                      #11
                      markosa {ITEM.VALUE} returns "Stopped (6)" while {ITEM.VALUE1} and {ITEM.VALUE2} return null.

                      I was able to make it work though by putting {TRIGGER.NAME} under quotes.

                      This is the working code:

                      Code:
                      c:/windows/system32/WindowsPowerShell/v1.0/powershell.exe '{TRIGGER.NAME}'.Split('"')[0] | Start-Service
                      Thanks again for your help.

                      Cristian

                      Comment

                      Working...