exit(1)

lista = [
	{ 'host': 'HOST A', 'trigger': 'eth0' },
	{ 'host': 'HOST B', 'trigger': 'eth0' },
]
maintenance_triggers_ids = []

for host in lista:
	h = zapi.host.get(output=['hostid','name'],search={'name': host['host']})
	if h.__len__() == 0:
		logger.warning('Host {0} not found!'.format(host['host']))
		continue
	triggers = zapi.trigger.get(output=['description','triggerid'],hostids=[h[0]['hostid']],expandDescription=1,search={'description': ': {0}'.format(host['trigger'])})
	logger.info('Found {0} triggers for host {1}'.format(triggers.__len__(),host['host']))
	logger.print_json(triggers)
	for t in triggers:
		maintenance_triggers_ids.append(t['triggerid'])

i = 0
logger.info('Found {0} triggers'.format(maintenance_triggers_ids.__len__()))
bar = ProgressBar(maxval=maintenance_triggers_ids.__len__(),widgets=[Percentage(), ReverseBar(), ETA(), RotatingMarker(), Timer()]).start()
for t in maintenance_triggers_ids:
	if args.run == True:
		out = zapi.trigger.update(triggerid=t,status=args.status)
		i += 1
		bar.update(i)
	else:
		logger.warning('Should change triggerid {0} to status {1}'.format(t,args.status))
bar.finish()
#5) Migrar esses hosts
logger.info('5) Migrar esses hosts')
if ( args.move ):
	hosts_to_proxies()
else:
	logger.info('\t--no-move utilizado. Nao necessario.')

#6) Sync dos dados (reload)
logger.info('6) Reload zabbix server e esperar pelo sync dos proxies')
logger.info('\tfuncao desligada')
#zabbix_server_reload()

#7) Ativar os discoveries
logger.info('7) Ativar todos os discoveries')
discovery_change_status(0)

#8) Mostrar resumo dos pesos dos proxies
logger.info('8) Resumo dos proxies')
logger.info('\tLocal || Proxy\t\t|| Redes || Peso')
for local in proxies:
	for prx in proxies[local]:
		logger.info('\t{0} || {1} || {2} || {3}'.format(local,prx['host'],len(prx['ranges']),prx['total_weight']))

#9) Finish!
logger.debug('finished.. debug log')
logger.print_json(proxies)

logger.info('Terminei.. gastei alguns segundos preciosos..')
zapi.user.logout()
exit(0)
예제 #3
0
]
maintenance_triggers_ids = []

for host in lista:
    h = zapi.host.get(output=['hostid', 'name'], search={'name': host['host']})
    if h.__len__() == 0:
        logger.warning('Host {0} not found!'.format(host['host']))
        continue
    triggers = zapi.trigger.get(
        output=['description', 'triggerid'],
        hostids=[h[0]['hostid']],
        expandDescription=1,
        search={'description': ': {0}'.format(host['trigger'])})
    logger.info('Found {0} triggers for host {1}'.format(
        triggers.__len__(), host['host']))
    logger.print_json(triggers)
    for t in triggers:
        maintenance_triggers_ids.append(t['triggerid'])

i = 0
logger.info('Found {0} triggers'.format(maintenance_triggers_ids.__len__()))
bar = ProgressBar(
    maxval=maintenance_triggers_ids.__len__(),
    widgets=[Percentage(),
             ReverseBar(),
             ETA(),
             RotatingMarker(),
             Timer()]).start()
for t in maintenance_triggers_ids:
    if args.run == True:
        out = zapi.trigger.update(triggerid=t, status=args.status)