parser.add_argument('--max-age', dest = 'max_age', default = 31, help = 'Max age in days for host to be in there') parser.add_argument('--no-run', dest = 'run', action = 'store_false', help = 'Dont remove any host, just count') parser.add_argument('--run', dest = 'run', action = 'store_true', help = 'Remove all hosts that expired') parser.add_argument('--no-matches', dest = 'matches', action = 'store_false', help = 'Dont remove any host that has no prefix') parser.add_argument('--matches', dest = 'matches', action = 'store_true', help = 'Remove all hosts that has no prefix') args = parser.parse_args() TIMEOUT = 30.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) call = { "output": [ "name", "hostid", ], "groupids": [ 72 ], } hosts = zapi.host.get(**call) hosts_exclude = [] hosts_no_match = [] date_curr = datetime.now() """ Find all hosts that match the expired period """ for host in hosts:
dest='matches', action='store_true', help='Remove all hosts that has no prefix') args = parser.parse_args() TIMEOUT = 30.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) call = { "output": [ "name", "hostid", ], "groupids": [72], } hosts = zapi.host.get(**call) hosts_exclude = [] hosts_no_match = [] date_curr = datetime.now() """ Find all hosts that match the expired period
parser.add_argument('--no-verbose', dest = 'verbose', action = 'store_false', help = 'Dont show any logs on screen') parser.add_argument('--verbose', dest = 'verbose', action = 'store_true') parser.set_defaults(verbose=False) parser.add_argument('--loglevel', dest = 'loglevel', default = 'ERROR', help = 'Debug level. DEBUG/INFO/WARNING/ERROR/CRITICAL') args = parser.parse_args() TIMEOUT = 5.0 LOGFILE = '/tmp/%s.log' % path.basename(argv[0]) logger = LogPrint(echo=args.verbose, logfile=LOGFILE, loglevel=args.loglevel.upper()) HGS = [ 'Operacao', 'Operacao::Servico' ] try: zapi = ZabbixAPI(args.url,timeout=TIMEOUT) zapi.login(args.user,args.password) except Exception, e: logger.error('Unable to login: {0}'.format(e)) exit(1) def hg_cache(): return zapi.hostgroup.get(output=['name']) def hg_search(name): for hgx in hg_names: if ( hgx['name'] == name ): return hgx['groupid'] return False def hg_find(name): ret = [] for hgx in hg_names: if ( name in hgx['name'] ):
default='ERROR', help='Debug level. DEBUG/INFO/WARNING/ERROR/CRITICAL') args = parser.parse_args() TIMEOUT = 5.0 LOGFILE = '/tmp/%s.log' % path.basename(argv[0]) logger = LogPrint(echo=args.verbose, logfile=LOGFILE, loglevel=args.loglevel.upper()) HGS = ['Operacao', 'Operacao::Servico'] try: zapi = ZabbixAPI(args.url, timeout=TIMEOUT) zapi.login(args.user, args.password) except Exception, e: logger.error('Unable to login: {0}'.format(e)) exit(1) def hg_cache(): return zapi.hostgroup.get(output=['name']) def hg_search(name): for hgx in hg_names: if (hgx['name'] == name): return hgx['groupid'] return False def hg_find(name):
parser.add_argument('--no-discovery', dest = 'discovery', action = 'store_false', help = 'Keep state of all network discovery rules') parser.set_defaults(discovery=True) parser.add_argument('--mail', dest = 'mail', action = 'store_true', help = 'Change email source address to [email protected]') parser.add_argument('--no-mail', dest = 'mail', action = 'store_false', help = 'Keep current email source address') parser.set_defaults(mail=True) args = parser.parse_args() TIMEOUT = 180.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) # Grupos a manter ativo apos desabilitar todos. Usar IDs. groupids = [ 4 ] # Zabbix Servers def hosts_disable_all(): """ status de host 0 = enabled status de host 1 = disabled """ logger.info('Disabling all hosts, in blocks of 1000') hosts = zapi.host.get(output=[ 'hostid' ], search={ 'status': 0 }) maxval = int(ceil(hosts.__len__())/1000+1) bar = ProgressBar(maxval=maxval,widgets=[Percentage(), ReverseBar(), ETA(), RotatingMarker(), Timer()]).start() i = 0
fake = args.fake LOGFILE = '/tmp/zbx_discovery-manager.log' logger = LogPrint(echo=args.verbose, logfile=LOGFILE, loglevel=args.loglevel.upper()) loglevels = { 'CRITICAL' : 50, 'ERROR' : 40, 'WARNING' : 30, 'INFO' : 20, 'DEBUG' : 10 } try: zapi = ZabbixAPI(args.url,timeout=TIMEOUT) zapi.login(args.user,args.password) except Exception, e: logger.error('Unable to login: {0}'.format(e)) exit(1) # CUSTOM FUNCTIONS def discovery_checks(): """ retornar o formato json com os discovery checks essa entrada eh manual """ dchecks = [ { 'uniq': '1', 'snmp_community': '{$SNMP_COMMUNITY}', 'type': '11', 'ports': '161', 'key_': 'sysName.0' }, { 'uniq': '0', 'snmp_community': '{$SNMP_COMMUNITY}', 'type': '11', 'ports': '161', 'key_': 'sysDescr.0' }, { 'uniq': '0', 'snmp_community': '{$SNMP_COMMUNITY}', 'type': '11', 'ports': '161', 'key_': 'sysContact.0' }, { 'uniq': '0', 'snmp_community': '{$SNMP_COMMUNITY}', 'type': '11', 'ports': '161', 'key_': 'MIB-Dell-10892::chassisModelName.1' }, { 'uniq': '0', 'snmp_community': '{$SNMP_COMMUNITY}', 'type': '11', 'ports': '161', 'key_': 'LSI-MegaRAID-SAS-MIB::productName.0' }, { 'uniq': '0', 'snmp_community': '{$SNMP_COMMUNITY}', 'type': '11', 'ports': '161', 'key_': 'F5-BIGIP-SYSTEM-MIB::sysProductName.0' },
parser.add_argument('--verbose',dest='verbose',action='store_true') parser.set_defaults(verbose=False) parser.add_argument('--loglevel',dest='loglevel',default='ERROR',help='Debug level. DEBUG/INFO/WARNING/ERROR/CRITICAL') args=parser.parse_args() tmp_dir='../tmp' move_items_file='%s/move_items.txt' % tmp_dir TIMEOUT=30.0 LOGFILE='/tmp/%s.log' % os.path.basename(sys.argv[0]) logger=LogPrint(echo=args.verbose,logfile=LOGFILE,loglevel=args.loglevel.upper()) # Connects to zabbix api to get hostid's,verify itemid's and item type (maybe?) try: zapi=ZabbixAPI(args.url,timeout=TIMEOUT) zapi.login(args.zabbixuser,args.zabbixpassword) except Exception,e: logger.error('Unable to login to Zabbix: %s' % (e)) sys.exit(1) if not os.path.exists(tmp_dir): os.makedirs(tmp_dir) # Connects to production database (read and write) try: dblive=pymysql.connect(host=args.dblivehost,port=3306,user=args.dbuser,passwd=args.dbpassword,db='zabbix_staging') except Exception,e: logger.error('Unable to login to LIVE database (%s): %s' % (args.dblivehost,e)) sys.exit(1) # Connection to backup database,where our backup history lies try: dbbkp=pymysql.connect(host=args.dbbkphost,port=3306,user=args.dbuser,passwd=args.dbpassword,db='zabbix')
parser.add_argument('--no-verbose', dest = 'verbose', action = 'store_false', help = 'Dont show any logs on screen') parser.add_argument('--verbose', dest = 'verbose', action = 'store_true') parser.set_defaults(verbose=False) parser.add_argument('--no-run', dest = 'run', action = 'store_false', help = 'Work') parser.add_argument('--run', dest = 'run', action = 'store_true', help = 'Dont perform any operation') parser.set_defaults(run=False) parser.add_argument('--status', dest = 'status', type = int, required = True, help = 'Status to change trigger to. [0|1]') parser.add_argument('--loglevel', dest = 'loglevel', default = 'ERROR', help = 'Debug level. DEBUG/INFO/WARNING/ERROR/CRITICAL') args = parser.parse_args() TIMEOUT = 5.0 LOGFILE = '/tmp/%s.log' % path.basename(argv[0]) logger = LogPrint(echo=args.verbose, logfile=LOGFILE, loglevel=args.loglevel.upper()) if args.status != 0 and args.status != 1: logger.error('--status should be either 0[enabled] or 1[disabled]') try: 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:
required=True, help='Status to change trigger to. [0|1]') parser.add_argument('--loglevel', dest='loglevel', default='ERROR', help='Debug level. DEBUG/INFO/WARNING/ERROR/CRITICAL') args = parser.parse_args() TIMEOUT = 5.0 LOGFILE = '/tmp/%s.log' % path.basename(argv[0]) logger = LogPrint(echo=args.verbose, logfile=LOGFILE, loglevel=args.loglevel.upper()) if args.status != 0 and args.status != 1: logger.error('--status should be either 0[enabled] or 1[disabled]') try: 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',
action='store_false', help='Keep current email source address') parser.set_defaults(mail=True) args = parser.parse_args() TIMEOUT = 180.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) # Grupos a manter ativo apos desabilitar todos. Usar IDs. groupids = [4] # Zabbix Servers def hosts_disable_all(): """ status de host 0 = enabled status de host 1 = disabled """ logger.info('Disabling all hosts, in blocks of 1000') hosts = zapi.host.get(output=['hostid'], search={'status': 0}) maxval = int(ceil(hosts.__len__()) / 1000 + 1) bar = ProgressBar(
help='Don\'t remove anything, just count (works only with hostgroup)') parser.add_argument('--run', dest='run', action='store_true', help='Remove every match (works only with hostgroup)') args = parser.parse_args() TIMEOUT = 30.0 LOGFILE = "/tmp/%s.log" % path.basename(argv[0]) logger = LogPrint(echo=args.verbose, logfile=LOGFILE, loglevel=args.loglevel.upper()) if not args.hostname and not args.groupname: logger.error('You MUST use at least one of --hostname or --groupname.') exit(1) 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) def deleteHostByName(hostname): logger.print_json(zapi.globo.deleteMonitors(host=hostname)) return
parser.add_argument('--verbose', dest = 'verbose', action = 'store_true') parser.set_defaults(verbose=False) parser.add_argument('--loglevel', dest = 'loglevel', default = 'ERROR', help = 'Debug level. DEBUG/INFO/WARNING/ERROR/CRITICAL') parser.add_argument('--hostname', dest = 'hostname', help = 'Host name to be removed') parser.add_argument('--groupname', dest = 'groupname', help = 'Hostgroup name to be cleaned (all hosts DELETED)! USE WITH CAUTION') parser.add_argument('--no-run', dest = 'run', action = 'store_false', help = 'Don\'t remove anything, just count (works only with hostgroup)') parser.add_argument('--run', dest = 'run', action = 'store_true', help = 'Remove every match (works only with hostgroup)') args = parser.parse_args() TIMEOUT = 30.0 LOGFILE = "/tmp/%s.log" % path.basename(argv[0]) logger = LogPrint(echo=args.verbose, logfile=LOGFILE, loglevel=args.loglevel.upper()) if not args.hostname and not args.groupname: logger.error('You MUST use at least one of --hostname or --groupname.') exit(1) 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) def deleteHostByName(hostname): logger.print_json(zapi.globo.deleteMonitors(host=hostname)) return def deleteHostsByHostgroup(groupname): hostgroup = zapi.hostgroup.get(output=['groupid'],filter={'name': groupname})
help='Debug level. DEBUG/INFO/WARNING/ERROR/CRITICAL') args = parser.parse_args() tmp_dir = '../tmp' move_items_file = '%s/move_items.txt' % tmp_dir TIMEOUT = 30.0 LOGFILE = '/tmp/%s.log' % os.path.basename(sys.argv[0]) logger = LogPrint(echo=args.verbose, logfile=LOGFILE, loglevel=args.loglevel.upper()) # Connects to zabbix api to get hostid's,verify itemid's and item type (maybe?) try: zapi = ZabbixAPI(args.url, timeout=TIMEOUT) zapi.login(args.zabbixuser, args.zabbixpassword) except Exception, e: logger.error('Unable to login to Zabbix: %s' % (e)) sys.exit(1) if not os.path.exists(tmp_dir): os.makedirs(tmp_dir) # Connects to production database (read and write) try: dblive = pymysql.connect(host=args.dblivehost, port=3306, user=args.dbuser, passwd=args.dbpassword, db='zabbix_staging') except Exception, e: logger.error('Unable to login to LIVE database (%s): %s' % (args.dblivehost, e))