def disableAlarms(host): exist = hostExists(host) if exist is not False: return _disableAlarms(exist['hostid']) else: raise InvalidParamsError('Host "{0}" not found.'.format(host))
def enableAlarms(host): exist = hostExists(host) if exist is not False: trigger_get = fowardZ.sendToZabbix(method='trigger.get', params={'hostids': exist['hostid'], 'output': 'triggerid'}) triggerPrototype_get = fowardZ.sendToZabbix(method='triggerprototype.get', params={'hostids': exist['hostid'], 'output': 'triggerid'}) triggers = list() triggersPrototype = list() for trigger_host in trigger_get['result']: triggers.append({'triggerid': trigger_host['triggerid'], 'status': '0'}) enabled = fowardZ.sendToZabbix(method='trigger.update', params=triggers) enabledPrototype = dict(result = True) if triggerPrototype_get: for triggerPrototype in triggerPrototype_get['result']: triggersPrototype.append({'triggerid': triggerPrototype['triggerid'], 'status':'0'}) enabledPrototype = fowardZ.sendToZabbix(method='triggerprototype.update', params=triggersPrototype) if 'result' in enabled and 'result' in enabledPrototype: return 'Enable operation was successful.' else: raise InvalidParamsError('It wasnt able to enable alarms on host "{0}"'.format(host)) else: raise InvalidParamsError('Host "{0}" doesnt exist.'.format(host))
def enableMonitors(host): exist = hostExists(host) if exist is not False: update = fowardZ.sendToZabbix(method='host.update', params={'hostid': exist['hostid'], 'status': '0'}) if 'result' in update: return 'Enable operation was successful.' else: raise InvalidParamsError('It wasnt able to enable monitors on host "{0}"'.format(host)) else: raise InvalidParamsError('Host "{0}" doesnt exist.'.format(host))
def disableMonitors(host): exist = hostExists(host) if exist is not False: update = fowardZ.sendToZabbix(method='host.update', params={ 'hostid': exist['hostid'], 'status': '1' }) if 'result' in update: return 'Disable operation was successful.' else: raise InvalidParamsError( 'It wasnt able to disable monitors on host "{0}"'.format(host)) else: raise InvalidParamsError('Host "{0}" doesnt exist.'.format(host))
def enableAlarms(host): exist = hostExists(host) if exist is not False: trigger_get = fowardZ.sendToZabbix(method='trigger.get', params={ 'hostids': exist['hostid'], 'output': 'triggerid' }) triggerPrototype_get = fowardZ.sendToZabbix( method='triggerprototype.get', params={ 'hostids': exist['hostid'], 'output': 'triggerid' }) triggers = list() triggersPrototype = list() for trigger_host in trigger_get['result']: triggers.append({ 'triggerid': trigger_host['triggerid'], 'status': '0' }) enabled = fowardZ.sendToZabbix(method='trigger.update', params=triggers) enabledPrototype = dict(result=True) if triggerPrototype_get: for triggerPrototype in triggerPrototype_get['result']: triggersPrototype.append({ 'triggerid': triggerPrototype['triggerid'], 'status': '0' }) enabledPrototype = fowardZ.sendToZabbix( method='triggerprototype.update', params=triggersPrototype) if 'result' in enabled and 'result' in enabledPrototype: return 'Enable operation was successful.' else: raise InvalidParamsError( 'It wasnt able to enable alarms on host "{0}"'.format(host)) else: raise InvalidParamsError('Host "{0}" doesnt exist.'.format(host))
def deleteMonitors(host): exist = hostExists(host) date = datetime.today().strftime('%y%m%d%H%M%S') if exist is not False: deleted_name = '_' + date + '_' + exist['name'] deleted_host = '_' + date + '_' + exist['host'] update = fowardZ.sendToZabbix(method="host.update", params={'hostid': exist['hostid'], 'host': deleted_host, 'name': deleted_name, 'status': '1', 'groups': [ {'groupid': n2i.hostgroup(GROUP_NOT_EXIST)} ]}) if 'result' in update: return 'Delete operation was successful' else: raise InvalidParamsError('It wasnt able to delete Host "{0}"'.format(host)) else: raise InvalidParamsError('Host "{0}" doesnt exist.'.format(host))
def createMonitor(returning_graphs, monitor_type, hostname, visible_name, ip, proxy=None, groups=None, templates=None, macros=None, inventory=None): if groups is None: groups = [] if templates is None: templates = [] if macros is None: macros = {} templates_structure = [] groups_structure = [] macros_structure = [] for template in templates: templates_structure.append({'templateid': n2i.template(template)}) for group in sorted(set(groups)): groups_structure.append({'groupid': n2i.hostgroup(group)}) for macro, value in macros.iteritems(): if value is not None: macros_structure.append({'macro': macro, 'value': value}) if monitor_type == 'snmp': interfaces_structure = [{'type': '2', # snmp 'main': '1', 'useip': '1', 'ip': ip, 'dns': '', 'port': SNMP_PORT }] elif monitor_type == 'agent': if re.match("^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$", ip) is not None: interfaces_structure = [{'type': '1', # agent 'main': '1', 'useip': '1', 'ip': ip, 'dns': '', 'port': AGENT_PORT }] else: interfaces_structure = [{'type': '1', # agent 'main': '1', 'useip': '0', 'ip': '', 'dns': ip, 'port': AGENT_PORT }] else: raise InvalidParamsError('Monitoring type \'{0}\' not supported.'.format(monitor_type)) exist = hostExists(visible_name) if visible_name else hostExists(hostname) # exist = hostExists(visible_name) proxy = n2i.proxy(proxy) if not exist: create = fowardZ.sendToZabbix(method="host.create", params={ 'host': hostname, 'name': visible_name, 'interfaces': interfaces_structure, 'proxy_hostid': proxy, 'groups': groups_structure, 'templates': templates_structure, 'macros': macros_structure, 'inventory': inventory} ) else: raise InvalidParamsError('"{0}" already exists in Zabbix Database.'.format(hostname)) if 'result' in create: if returning_graphs == 'returnallgraphs': graphs = generateGraphs(visible_name) if visible_name else generateGraphs(hostname) if graphs: return graphs else: return 'Create operation was successful, but there are no graphs to show.' elif returning_graphs == 'defaultreturn': return 'Create operation was successful' else: return create else: raise InvalidParamsError(create['error']['data'])