当前位置:网站首页>ZABBIX API batch delete a template of the host
ZABBIX API batch delete a template of the host
2022-07-04 02:11:00 【Xiaobo】
example : Unlink and clean up the same template for all hosts in a host group
What needs to be revised :
1. Variable Groupid : Define the host group that needs to delete the template id
2. Variable Templateid : Define the template to unlink and clean up id
3. The initialization information is modified according to the personal environment
import json
import urllib.request
Hostids = []
Groupid = 4
Templateid = 10001
class ZabbixApi:
def __init__(self): # Initialization information modify
self.url = 'http://192.10.xx.xx/api_jsonrpc.php'
self.user = 'Admin'
self.passwd = 'zabbix'
self.header = {"Content-Type": "application/json-rpc"}
# self.auth = self.UserLogin()
def UserLogin(self): # api Login operation
data = {
"jsonrpc": "2.0",
"method": "user.login",
"params": {
"user": self.user,
"password": self.passwd
},
"id": 0
}
return self.UrlRequest(data)
def UrlRequest(self, data): ##
request = urllib.request.Request(self.url, json.dumps(data).encode('utf-8'), self.header)
result = urllib.request.urlopen(request)
response = json.loads(result.read().decode('utf-8'))
return response
def GetHostsid(self): # Get all of the host group hostid
data = {
"jsonrpc": "2.0",
"method": "hostgroup.get",
"params": {
"groupids": Groupid,
"selectHosts": "hostid"
},
"auth": token,
"id": 1
}
return self.UrlRequest(data)
def DeleteTemplate(self): # Unlink and clean up the template
data = {
"jsonrpc": "2.0",
"method": "host.massremove",
"params": {
"hostids": Hostids,
"templateids_clear": Templateid
},
"auth": token,
"id": 1
}
self.UrlRequest(data)
return " Template cleanup completed !"
if __name__ == '__main__':
response = ZabbixApi().UserLogin()
token = response['result']
print(f' Identity token is "{token}"')
info = ZabbixApi().GetHostsid()
hostids = info['result'][0]['hosts']
num = len(hostids)
for i in range(num):
Hostids.append(hostids[i]['hostid'])
txt = ZabbixApi().DeleteTemplate()
print(txt)边栏推荐
- Keep an IT training diary 054- opening and closing
- The automatic control system of pump station has powerful functions and diverse application scenarios
- Chapter 3.4: starrocks data import - Flink connector and CDC second level data synchronization
- Small program graduation project based on wechat examination small program graduation project opening report function reference
- Yyds dry goods inventory override and virtual of classes in C
- When tidb meets Flink: tidb efficiently enters the lake "new play" | tilaker team interview
- Hunan University | robust Multi-Agent Reinforcement Learning in noisy environment
- 2022 R2 mobile pressure vessel filling certificate examination and R2 mobile pressure vessel filling simulation examination questions
- C learning notes: C foundation - Language & characteristics interpretation
- 12. Gettimeofday() and time()
猜你喜欢

Life cycle of instance variables, static variables and local variables

Small program graduation design is based on wechat order takeout small program graduation design opening report function reference

MPLS③

C language black Technology: Archimedes spiral! Novel, interesting, advanced~

Rearrangement of tag number of cadence OrCAD components and sequence number of schematic page

High level application of SQL statements in MySQL database (I)

Yyds dry goods inventory override and virtual of classes in C

From the 18th line to the first line, the new story of the network security industry

中電資訊-信貸業務數字化轉型如何從星空到指尖?
![[software implementation series] software implementation interview questions with SQL joint query diagram](/img/8b/8718fea82f83a6169ea5d8c2e5b645.jpg)
[software implementation series] software implementation interview questions with SQL joint query diagram
随机推荐
在尋求人類智能AI的過程中,Meta將賭注押向了自監督學習
Applet graduation project based on wechat selection voting applet graduation project opening report function reference
Question d: Haffman coding
Key knowledge of C language
Bacteriostatic circle scanning correction template
Learn these super practical Google browser skills, girls casually flirt
MySQL advanced (Advanced) SQL statement (I)
Global and Chinese market of box seals 2022-2028: Research Report on technology, participants, trends, market size and share
Human resource management online assignment
After listening to the system clear message notification, Jerry informed the device side to delete the message [article]
Ceramic metal crowns - current market situation and future development trend
Jerry's watch information type table [chapter]
Force buckle day32
It's corrected. There's one missing < /script >, why doesn't the following template come out?
LV1 Roche limit
All ceramic crowns - current market situation and future development trend
Hamburg University of Technology (tuhh) | intelligent problem solving as integrated hierarchical reinforcement learning
The requests module uses
Keep an IT training diary 055- moral bitch
High level application of SQL statements in MySQL database (I)