当前位置:网站首页>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)
边栏推荐
- Three layer switching ②
- Take you to master the formatter of visual studio code
- Question C: Huffman tree
- It's corrected. There's one missing < /script >, why doesn't the following template come out?
- Small program graduation design is based on wechat order takeout small program graduation design opening report function reference
- [leetcode daily question] a single element in an ordered array
- Rearrangement of tag number of cadence OrCAD components and sequence number of schematic page
- Intel's new GPU patent shows that its graphics card products will use MCM Packaging Technology
- How to view the computing power of GPU?
- Writeup (real questions and analysis of ciscn over the years) of the preliminary competition of national college students' information security competition
猜你喜欢
Maximum likelihood method, likelihood function and log likelihood function
Do you know the eight signs of a team becoming agile?
MySQL advanced (Advanced) SQL statement (I)
Use classname to modify style properties
Basic editing specifications and variables of shell script
A fan summed up so many interview questions for you. There is always one you need!
[leetcode daily question] a single element in an ordered array
High level application of SQL statements in MySQL database (I)
Learn these super practical Google browser skills, girls casually flirt
Rearrangement of tag number of cadence OrCAD components and sequence number of schematic page
随机推荐
IPv6 experiment
Pyrethroid pesticide intermediates - market status and future development trend
Day05 branch and loop (II)
[Yugong series] February 2022 attack and defense world advanced question misc-83 (QR easy)
What are the main investment products of bond funds and what are they
Servlet simple verification code generation
60 year old people buy medical insurance and recommend a better product
Global and Chinese market of box seals 2022-2028: Research Report on technology, participants, trends, market size and share
Iclr2022 | ontoprotein: protein pre training integrated with gene ontology knowledge
FRP intranet penetration
When tidb meets Flink: tidb efficiently enters the lake "new play" | tilaker team interview
Why can't it run (unresolved)
Writeup (real questions and analysis of ciscn over the years) of the preliminary competition of national college students' information security competition
Cancer biopsy instruments and kits - market status and future development trends
Advanced learning of MySQL -- Application -- index
Containerization technology stack
求esp32C3板子連接mssql方法
Jerry's watch information type table [chapter]
Setting function of Jerry's watch management device [chapter]
Human resource management online assignment