Zabbix adding web monitoring in bulk via API

Source: Internet
Author: User

Zabbix adding web monitoring is always a big problem and cannot be automatically found only by manually adding


wrote a py script.

#!/usr/bin/env python# -*- coding: utf-8 -*-import jsonimport urllib2import  sysclass zabbixtools:    def __init__ (self):         self.url =  "Zabbixserver"          self.header = {"Content-type":  "Application/json"}         self.authid = self.user_login ()     def user_login (self):         data = json.dumps (                 {                         "Jsonrpc":  "2.0",                       "Method":  "User.lOgin ",                      "params": {                           "User":  "user",                           "password":  "password"                          },                      "id":  0                     })         request = urllib2. Request (Self.url,data)         for key in self.header:             request.add_header (Key,self.header[key])          try:            result =  Urllib2.urlopen (Request)         except urlerror as e:             print  "auth failed,  Please check your name and password: ",e.code         else:            response =  Json.loads (Result.read ())             result.close ( )             authid = response[' result '     &nbsP;       return authid    def get_data (Self, Data,hostip= ""):         request = urllib2. Request (self.url,data)         for key in self.header:             request.add_header (Key,self.header[key ])         try:             result = urllib2.urlopen (Request)          Except urlerror as e:            if  hasattr (e,  ' reason '):                 print  ' We failed to reach a server. '                 print  ' reason:  ', e.reason             elif hasattr (e,  ' code '):                 print  ' the server could  Not fulfill the request. '                 print  ' error code:  ', e.code             return 0        else:             response = json.loads (Result.read ())              result.close ()              return response    def host_create (self):  &NBsp;      data = json.dumps (                     {                           "JSONRPC":  "2.0",                          "Method":  "Httptest.create",                           "params": {                              " HostID ": " 10788 ",                              "Name":  "homepage",                               "Steps": [                                  {                                       "Name":  "1",                                       "url":  "http://mycompany.com",                                       "No": 1                                  }                             ]                     },                           "Auth": self.authid,                          "id": 1,                          })         res = self.get_data (data)          print resdef main ():    test =  Zabbixtools ()     test.host_create () if __name__ ==  "__main__":     main ()


Zabbix adding web monitoring in bulk via API

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.