Ejemplo n.º 1
0
        out = zapi.host.delete(host['hostid'])
    bar.finish()
    logger.echo = args.verbose

total = hosts_no_match.__len__()
logger.info("Other hosts without timestamp to remove: %d" % total)
if args.run and total > 0 and args.matches:
    x = 0
    bar = ProgressBar(
        maxval=total,
        widgets=[Percentage(),
                 ReverseBar(),
                 ETA(),
                 RotatingMarker(),
                 Timer()]).start()
    logger.echo = False
    for host in hosts_no_match:
        x += 1
        bar.update(x)
        logger.debug("(%d/%d) >> Removing >> %s" % (x, total, host))
        out = zapi.host.delete(host['hostid'])
    bar.finish()
    logger.echo = args.verbose

if args.run:
    exit(0)

logger.warning("Not removing.. script ran with --no-run")
zapi.user.logout()
exit(0)
Ejemplo n.º 2
0
	bar = ProgressBar(maxval=total,widgets=[Percentage(), ReverseBar(), ETA(), RotatingMarker(), Timer()]).start()
	logger.echo = False
	for host in hosts_exclude:
		x += 1
		bar.update(x)
		logger.debug("(%d/%d) >> Removing >> %s" % (x, total, host))
		out = zapi.host.delete(host['hostid'])
	bar.finish()
	logger.echo = args.verbose

total = hosts_no_match.__len__()
logger.info("Other hosts without timestamp to remove: %d" % total)
if args.run and total > 0 and args.matches:
	x = 0
	bar = ProgressBar(maxval=total,widgets=[Percentage(), ReverseBar(), ETA(), RotatingMarker(), Timer()]).start()
	logger.echo = False
	for host in hosts_no_match:
		x += 1
		bar.update(x)
		logger.debug("(%d/%d) >> Removing >> %s" % (x, total, host))
		out = zapi.host.delete(host['hostid'])
	bar.finish()
	logger.echo = args.verbose

if args.run:
	exit(0)

logger.warning("Not removing.. script ran with --no-run")
zapi.user.logout()
exit(0)
Ejemplo n.º 3
0
LOGFILE = "/tmp/%s.log" % path.basename(argv[0])
logger = LogPrint(echo=args.verbose, logfile=LOGFILE, loglevel=args.loglevel.upper())
try:
	zapi = ZabbixAPI(args.url,timeout=TIMEOUT)
	zapi.login(args.user,args.password)
except Exception, e:
	logger.error("Unable to login: %s" % (e))
	exit(1)

# Filtra do hostgroup _DELETED_ os hosts com status 0.
a = zapi.host.get(groupids=[ args.groupid ],selectInterfaces='extend',output=['name','hostid'],filter={"status": 0})
#,templateids=['10069'])

for host in a:
	logger.debug("Doing host %s" % host['name'])
	ok = 0
	for ip in host['interfaces']:
		if ip['main'] == '1':
			zapi.host.update(hostid=host['hostid'],status=1)
			# Verifico se pareco linux. Poderia verificar pelo template... Mas ai seriam multiplas buscas
			if ( 'lf' in host['name'] or 'ls' in host['name'] or 'lb' in host['name'] ):
				if args.sshkey:
					exe = "ssh -i %s root@%s \"/etc/init.d/snmpd stop\"" % (ip['ip'],args.sshkey)
				else:
					exe = "ssh root@%s \"/etc/init.d/snmpd stop\"" % (ip['ip'])
				(status,out) = commands.getstatusoutput(exe)
				logger.warning("Failed on %s" % ip['ip'])
	if ok == 0:
		logger.warning("Failed for %s" % host['name'])
zapi.user.logout()
Ejemplo n.º 4
0
except Exception, e:
    logger.error("Unable to login: %s" % (e))
    exit(1)

# Filtra do hostgroup _DELETED_ os hosts com status 0.
a = zapi.host.get(groupids=[args.groupid],
                  selectInterfaces='extend',
                  output=['name', 'hostid'],
                  filter={"status": 0})
#,templateids=['10069'])

for host in a:
    logger.debug("Doing host %s" % host['name'])
    ok = 0
    for ip in host['interfaces']:
        if ip['main'] == '1':
            zapi.host.update(hostid=host['hostid'], status=1)
            # Verifico se pareco linux. Poderia verificar pelo template... Mas ai seriam multiplas buscas
            if ('lf' in host['name'] or 'ls' in host['name']
                    or 'lb' in host['name']):
                if args.sshkey:
                    exe = "ssh -i %s root@%s \"/etc/init.d/snmpd stop\"" % (
                        ip['ip'], args.sshkey)
                else:
                    exe = "ssh root@%s \"/etc/init.d/snmpd stop\"" % (ip['ip'])
                (status, out) = commands.getstatusoutput(exe)
                logger.warning("Failed on %s" % ip['ip'])
    if ok == 0:
        logger.warning("Failed for %s" % host['name'])
zapi.user.logout()
	zapi = ZabbixAPI(args.url,timeout=TIMEOUT)
	zapi.login(args.user,args.password)
except:
	logger.error('Unable to login. Check your credentials.')
	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)
Ejemplo n.º 6
0
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(