Ad Widget

Collapse

Zabbix add/remove Maintenance Script

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ranveer
    Junior Member
    • Dec 2016
    • 8

    #1

    Zabbix add/remove Maintenance Script

    I am looking for script by which i can unable or disable Maintenance for my hosts groups .

    Till now i have tried below scripts but all having some issue or might be i am doing wrong some ware .

    Join the friendly and open Zabbix community on our forums and social media platforms.

    Join the friendly and open Zabbix community on our forums and social media platforms.

    Join the friendly and open Zabbix community on our forums and social media platforms.


    When i run these script ERROR - hostname not found in zabbix. Make sure you're using the FQDN .

    host name is present in my zabbix GUI .

    Please help me to understand this issue .
  • SBO
    Zabbix Certified Specialist
    Zabbix Certified Specialist
    • Sep 2015
    • 226

    #2
    Hi,

    Please show us the output of your script, with the command line you used, and put a screenshot of the host's configuration you're trying to put in maintenance mode

    Comment

    • Ranveer
      Junior Member
      • Dec 2016
      • 8

      #3
      Originally posted by SBO
      Hi,

      Please show us the output of your script, with the command line you used, and put a screenshot of the host's configuration you're trying to put in maintenance mode
      Thanks for you replay .
      If i take the example of this script http://zabbix.org/wiki/Perl_script_t...ve_Maintenance

      i have modify this lines
      my $url = "http://ip/zabbix/api_jsonrpc.php"; # change <zabbix server> to your zabbix server
      my $apiuser="Admin"; # API User's Username
      my $apipassword="zabbix"; # API User's password

      Then i have test the script by running list this on console :
      # ./za1.pl -s jenkins -d 3600 -n backup
      WARNING - jenkins not found in maintenance for Zabbix.

      Where jenkins is my host name which is present in zabbix GUI .

      Comment

      • Ranveer
        Junior Member
        • Dec 2016
        • 8

        #4
        i have modify this lines
        my $url = "http://ip/zabbix/api_jsonrpc.php"; # change <zabbix server> to your zabbix server
        my $apiuser="Admin"; # API User's Username
        my $apipassword="zabbix"; # API User's password

        Then i have test the script by running list this on console :
        # ./za1.pl -s jenkins -d 3600 -n backup
        WARNING - jenkins not found in maintenance for Zabbix.

        Where jenkins is my host name which is present in zabbix GUI .
        Can anyone HELP me on this critical case !!!!!

        Comment

        • Bercko21
          Junior Member
          • Dec 2015
          • 7

          #5
          I have the same problem

          Any chance you solved it by now?

          Comment

          • Ranveer
            Junior Member
            • Dec 2016
            • 8

            #6
            NO !!!!
            I am looking a script which can enable or disable group of server maintenance .

            Please advice me

            Comment

            • Bercko21
              Junior Member
              • Dec 2015
              • 7

              #7
              I'll try to debug it, I'll post here the solution if I'll manage.

              Comment

              • Bercko21
                Junior Member
                • Dec 2015
                • 7

                #8
                Well, I can tell the script is not working since the method host.getobjects has been deprecated....
                Since I'm not a Perl programmer, I'm not sure I'll actually solve it...
                I'm trying to get some help from someone else.

                Comment

                • Ranveer
                  Junior Member
                  • Dec 2016
                  • 8

                  #9
                  Do you have any other script which can perform same task

                  I just need a script which can remotely execute and enable and disable group of server in maintenance with no data collection .

                  Comment

                  • Bercko21
                    Junior Member
                    • Dec 2015
                    • 7

                    #10
                    That's exactly what I need too...
                    So far I don't think I'll manage to fix the Perl script, but I took the curl part from it and I'm trying to write a bash script to do it.
                    I'll update as soon as I'll get somewhere

                    Comment

                    • Bercko21
                      Junior Member
                      • Dec 2015
                      • 7

                      #11
                      Finally!

                      After a long long time, I've managed to do it using Zabbix-CLI, here are the instructions:

                      Install Zabbix-CLI:
                      1. wget https://github.com/usit-gd/zabbix-cl....7.0-1_all.deb
                      2. apt-get install python-requests python-ipaddr
                      3. dpkg -i zabbix-cli_1.7.0-1_all.deb

                      Configure Zabbix-CLI with the Zabbix API URL:
                      1. zabbix-cli-init --zabbix-url http://<server ip>/zabbix/api_jsonrpc.php

                      The scripts:
                      1. add_maintenance.sh
                      #!/bin/bash
                      export ZABBIX_USERNAME=<zabbix user>
                      export ZABBIX_PASSWORD=<zabbix password>
                      zabbix-cli -C "create_maintenance_definition 'Name-$1' 'Description' '$1' '1 hour' '1'"

                      2. remove_maintenance.sh
                      #!/bin/bash
                      export ZABBIX_USERNAME=<zabbix user>
                      export ZABBIX_PASSWORD=<zabbix password>
                      mid=$(zabbix-cli -C "show_maintenance_definitions '*' '*' '$1'" | tail -n 3 | head -n 1 | awk '{print $2}')
                      zabbix-cli -C "remove_maintenance_definition '$mid'"

                      Examples:
                      1. ./add_maintenance.sh pc-name-01
                      2. ./remove_maintenance.sh pc-name-01

                      Thats about it for now

                      Comment

                      Working...