Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import sys
- import logging
- from pyzabbix import ZabbixAPI
- URL = 'http://127.0.0.1/zabbix'
- DEBUG=False
- if DEBUG:
- stream = logging.StreamHandler(sys.stdout)
- stream.setLevel(logging.DEBUG)
- log = logging.getLogger('pyzabbix')
- log.addHandler(stream)
- log.setLevel(logging.DEBUG)
- # init the API and Authenticate
- zapi = ZabbixAPI(URL, timeout=5)
- zapi.login("YOUR_API_USERNAME", "YOUR_API_PASSWORD")
- #template ids
- # 10327 = Cisco Meraki Access Points
- # 10250 = Template Net HP Enterprise Switch SNMPv2
- # 10227 = Template Net HP Comware HH3C SNMPv2
- # 10852 = ZBX-DELL-POWERCONNECT-HARDWARE
- # 10923 = 3com 4500 extras
- # 10204 = Template Module Generic SNMPv2
- # 10223 = Template Net D-Link DES_DGS Switch SNMPv2
- # 10226 = Template Net Network Generic Device SNMPv2
- #UPDATE VISIBLE HOST NAMES FROM INVENTORY NAME FOR SWITCHES AND APs
- for hosts in zapi.host.get(output='extend', templateids=[10327, 10250, 10227, 10852, 10923, 10204, 10223, 10226], selectInventory=['name']):
- #print hosts['hostid'], "-", hosts['inventory']['name']
- inv_name = hosts['inventory']['name']
- inv_name = inv_name.strip().replace("_", " ")
- if (hosts['name'] != inv_name and inv_name != ''):
- print hosts['name'], "=>", inv_name
- try:
- zapi.host.update(
- hostid=hosts['hostid'],
- name=inv_name
- )
- except:
- print 'Error updating host', hosts['hostid'], '=>', hosts['inventory']['name'], ' ...reverting name'
- try:
- #name=hosts['host']
- zapi.host.update(
- hostid=hosts['hostid'],
- name=''
- )
- except:
- print 'ERROR REVERTING NAME'
- # RETRIEVE ALL SWITCHES
- all_switch_hostids = zapi.host.get(output=['hostid'], templateids=[10250, 10227, 10852, 10923, 10204, 10223, 10226])
- if all_switch_hostids:
- list_host_ids = []
- for id in all_switch_hostids: list_host_ids.append(int(id['hostid']))
- if list_host_ids:
- #DISABLE VLAN INTERFACE POLLERS
- for items in zapi.item.get(output='extend', hostids=list_host_ids, searchWildcardsEnabled=True, search={'name':'Int*VLAN*:*'}, filter={'status':0}):
- #print items
- print 'Disabling', items['name'], 'on host', items['hostid']
- zapi.item.update(
- itemid=items['itemid'],
- status=1
- )
- #DISABLE INTERFACE LINK DOWN TRIGGERS
- for triggers in zapi.trigger.get(output='extend', hostids=list_host_ids, searchWildcardsEnabled=True, search={'description':'Int*Link Down'}, filter={'status':0}):
- print 'Disabling', triggers['description']
- zapi.trigger.update(
- triggerid=triggers['triggerid'],
- status=1
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement