-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaudit.py
52 lines (38 loc) · 1.19 KB
/
audit.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# System imports
import datetime
import logging
import os
import pprint
# External imports
import pynetbox
import pyzabbix
# Local imports
import utils
logger = logging.getLogger(__name__)
def audit() -> None:
'''Run audit tasks
'''
# Get CLI args
arguments = utils.parse_args()
utils.setup_logging(logger, arguments, 'audit')
config = utils.fetch_sync_config()
# Connect to netbox & zabbix
zabbix = utils.connect_zabbix(config)
netbox = utils.connect_netbox(config)
# Get hosts with 'Not Available' status
hosts = zabbix.host.get(
output=['active_available','hostid', 'name', 'status'],
selectTags=['tag', 'value'],
selectInterfaces=['available','type']
)
for host in hosts:
interface_statuses = set(map(lambda x: x['available'], host['interfaces']))
if interface_statuses == set('2'):
logger.error(f"Unavailable host ID: {host['hostid']}, Host Name: {host['name']}")
continue
if 'tags' in host:
tags_dict = utils.parse_tags(host['tags'])
logger.error(f"Host: {host}\nTags: {tags_dict}")
#print(f"")
if __name__ == '__main__':
audit()