Se ha denunciado esta presentación.
Utilizamos tu perfil de LinkedIn y tus datos de actividad para personalizar los anuncios y mostrarte publicidad más relevante. Puedes cambiar tus preferencias de publicidad en cualquier momento.

Primeiros Passos na API do Zabbix com Python - 2º ZABBIX MEETUP DO INTERIOR-SP

1.109 visualizaciones

Publicado el

Apresentado por Luiz Sales

Publicado en: Tecnología
  • Sé el primero en comentar

  • Sé el primero en recomendar esto

Primeiros Passos na API do Zabbix com Python - 2º ZABBIX MEETUP DO INTERIOR-SP

  1. 1. Primeiros Passos na API do Zabbix com Python
  2. 2. Grupos from zabbix_api import ZabbixAPI zapi = ZabbixAPI(server=http://caminho-do-web-Zabbix) zapi.login(“login”,”pass”) grupos = zapi.hostgroup.get({“output”:”extend”}) for q in grupos: GroupID = q[u’groupid’] GroupName = q[u’name’] print “Grupo: %s “ % (GroupName)
  3. 3. Grupos: Grupo: Templates Grupo: Linux servers Grupo: Zabbix servers Grupo: Discovered hosts Grupo: Virtual machines Grupo: Hypervisors Grupo: Templates/Modules Grupo: Templates/Network Devices Grupo: Templates/Operating Systems Grupo: Templates/Servers Hardware Grupo: Templates/Applications Grupo: Templates/Databases Grupo: Templates/Virtualization Grupo: oi Grupo: BrewPub Grupo: Humberto
  4. 4. Hosts: from zabbix_api import ZabbixAPI zapi = ZabbixAPI(server=http://caminho-do-web-Zabbix) zapi.login(“login”,”pass”) grupos = zapi.hostgroup.get({“output”:”extend”}) for q in grupos: GroupID = q[u’groupid’] GroupName = q[u’name’] hosts = zapi.host.get({“ouput”: “extend”, “groupids”: GroupID }) for w in hosts: print w
  5. 5. Hosts: {u'available': u'1', u'tls_connect': u'1', u'maintenance_type': u'0', u'ipmi_errors_from': u'0', u'ipmi_username': u'', u'snmp_disable_until': u'0', u'ipmi_authtype': u'-1', u'ipmi_disable_until': u'0', u'lastaccess': u'0', u'snmp_error': u'', u'tls_psk': u'', u'ipmi_privilege': u'2', u'jmx_error': u'', u'jmx_available': u'0', u'maintenanceid': u'0', u'snmp_available': u'0', u'tls_psk_identity': u'', u'status': u'0', u'description': u'', u'tls_accept': u'1', u'host': u'Zabbix server', u'disable_until': u'0', u'ipmi_password': u'', u'templateid': u'0', u'tls_issuer': u'', u'ipmi_available': u'0', u'maintenance_status': u'0', u'snmp_errors_from': u'0', u'ipmi_error': u'', u'proxy_hostid': u'0', u'hostid': u'10084', u'name': u'Zabbix server', u'jmx_errors_from': u'0', u'jmx_disable_until': u'0', u'flags': u'0', u'error': u'', u'maintenance_from': u'0', u'tls_subject': u'', u'errors_from': u'0'} {u'available': u'0', u'tls_connect': u'1', u'maintenance_type': u'0', u'ipmi_errors_from': u'0', u'ipmi_username': u'', u'snmp_disable_until': u'0', u'ipmi_authtype': u'-1', u'ipmi_disable_until': u'0', u'lastaccess': u'0', u'snmp_error': u'', u'tls_psk': u'', u'ipmi_privilege': u'2', u'jmx_error': u'', u'jmx_available': u'0', u'maintenanceid': u'0', u'snmp_available': u'0', u'tls_psk_identity': u'', u'status': u'0', u'description': u'', u'tls_accept': u'1', u'host': u'Soul', u'disable_until': u'0', u'ipmi_password': u'', u'templateid': u'0', u'tls_issuer': u'', u'ipmi_available': u'0', u'maintenance_status': u'0', u'snmp_errors_from': u'0', u'ipmi_error': u'', u'proxy_hostid': u'0', u'hostid': u'10256', u'name': u'Soul', u'jmx_errors_from': u'0', u'jmx_disable_until': u'0', u'flags': u'0', u'error': u'', u'maintenance_from': u'0', u'tls_subject': u'', u'errors_from': u'0'}
  6. 6. Hosts -> IP from zabbix_api import ZabbixAPI zapi = ZabbixAPI(server=http://caminho-do-web-Zabbix) zapi.login(“login”,”pass”) grupos = zapi.hostgroup.get({“output”:”extend”}) for q in grupos: GroupID = q[u’groupid’] GroupName = q[u’name’] hosts = zapi.host.get({“ouput”: “extend”, “selectInterfaces”: “extend”, “groupids”: GroupID }) for w in hosts: HostIfaces = w[u’interfaces’] for e in HostIfaces: print e
  7. 7. Hosts -> IP {u'interfaceid': u'1', u'hostid': u'10084', u'ip': u'127.0.0.1', u'useip': u'1', u'bulk': u'1', u'dns': u'', u'main': u'1', u'type': u'1', u'port': u'10050’} {u'interfaceid': u'3', u'hostid': u'10256', u'ip': u'127.0.0.1', u'useip': u'1', u'bulk': u'1', u'dns': u'', u'main': u'1', u'type': u'1', u'port': u'10050'}
  8. 8. Items: from zabbix_api import ZabbixAPI zapi = ZabbixAPI(server=http://caminho-do-web-Zabbix) zapi.login(“login”,”pass”) grupos = zapi.hostgroup.get({“output”:”extend”}) for q in grupos: GroupID = q[u’groupid’] GroupName = q[u’name’] hosts = zapi.host.get({“ouput”: “extend”, “selectInterfaces”: “extend”, “groupids”: GroupID }) for w in hosts: HostID = w[u’hostids’] items = zapi.item.get({"output": "extend", "hostids": HostID }) for e in items: print e
  9. 9. Items: {u'itemid': u'23276', u'username': u'', u'snmpv3_contextname': u'', u'inventory_link': u'0', u'mtime': u'0', u'authtype': u'0', u'trends': u'365d', u'snmpv3_authpassphrase': u'', u'snmp_oid': u'', u'snmpv3_securitylevel': u'0', u'port': u'', u'lastns': u'239127401', u'master_itemid': u'0', u'logtimefmt': u'', u'jmx_endpoint': u'', u'delay': u'1m', u'publickey': u'', u'state': u'0', u'params': u'', u'snmpv3_securityname': u'', u'formula': u'', u'type': u'5', u'snmpv3_authprotocol': u'0', u'prevvalue': u'99.7898', u'status': u'0', u'lastlogsize': u'0', u'lastclock': u'1536985376', u'snmp_community': u'', u'description': u'', u'evaltype': u'0', u'trapper_hosts': u'', u'lastvalue': u'99.7898', u'units': u'%', u'value_type': u'0', u'templateid': u'22185', u'snmpv3_privprotocol': u'0', u'password': u'', u'interfaceid': u'0', u'snmpv3_privpassphrase': u'', u'hostid': u'10084', u'key_': u'zabbix[wcache,trend,pfree]', u'name': u'Zabbix $2 write cache, % free', u'privatekey': u'', u'lifetime': u'0', u'valuemapid': u'0', u'flags': u'0', u'error': u'', u'ipmi_sensor': u'', u'history': u'1w'}
  10. 10. Items -> Name, Key_, LastValue grupos = zapi.hostgroup.get({“output”:”extend”}) for q in grupos: GroupID = q[u’groupid’] GroupName = q[u’name’] hosts = zapi.host.get({“ouput”: “extend”, “selectInterfaces”: “extend”, “groupids”: GroupID }) for w in hosts: HostID = w[u’hostids’] items = zapi.item.get({"output": "extend", "hostids": HostID }) for e in items: ItemName = e[u'name’] ItemKey = e[u'key_’] ItemLastV = e[u'lastvalue’] print "Name: %s , Key: %s , Lastvalue: %s " % (ItemName,ItemKey,ItemLastV)
  11. 11. Items -> Name, Key_, LastValue Name: Host name of zabbix_agentd running , Key: agent.hostname , Lastvalue: Zabbix server Name: Agent ping , Key: agent.ping , Lastvalue: 1 Name: Version of zabbix_agent(d) running , Key: agent.version , Lastvalue: 3.4.13 Name: Maximum number of opened files , Key: kernel.maxfiles , Lastvalue: 26368281 Name: Maximum number of processes , Key: kernel.maxproc , Lastvalue: 40960 Name: Incoming network traffic on $1 , Key: net.if.in[eth0] , Lastvalue: 968968 Name: Outgoing network traffic on $1 , Key: net.if.out[eth0] , Lastvalue: 4664 Name: Number of running processes , Key: proc.num[,,run] , Lastvalue: 1 Name: Number of processes , Key: proc.num[] , Lastvalue: 65 Name: Host boot time , Key: system.boottime , Lastvalue: 1532223025
  12. 12. Triggers: grupos = zapi.hostgroup.get({“output”:”extend”}) for q in grupos: GroupID = q[u’groupid’] GroupName = q[u’name’] hosts = zapi.host.get({“ouput”: “extend”, “selectInterfaces”: “extend”, “groupids”: GroupID }) for w in hosts: HostID = w[u’hostids’] items = zapi.item.get({"output": "extend", "hostids": HostID }) for e in items: ItemName = e[u'name’] ItemKey = e[u'key_’] ItemLastV = e[u'lastvalue’] ItemID = e[u’itemid’] triggers = zapi.trigger.get({“output”:”extend”, “itemids”: ItemID }) for r in triggers: print r
  13. 13. Triggers: {u'status': u'0', u'recovery_mode': u'0', u'description': u'Host name of zabbix_agentd was changed on {HOST.NAME}', u'state': u'0', u'url': u'', u'type': u'0', u'templateid': u'13508', u'correlation_tag': u'', u'lastchange': u'0', u'value': u'0', u'priority': u'1', u'triggerid': u'13509', u'flags': u'0', u'comments': u'', u'error': u'', u'correlation_mode': u'0', u'expression': u'{12938}>0', u'recovery_expression': u'', u'manual_close': u'0’} {u'status': u'0', u'recovery_mode': u'0', u'description': u'Zabbix agent on {HOST.NAME} is unreachable for 5 minutes', u'state': u'0', u'url': u'', u'type': u'0', u'templateid': u'10047', u'correlation_tag': u'', u'lastchange': u'0', u'value': u'0', u'priority': u'3', u'triggerid': u'13491', u'flags': u'0', u'comments': u'', u'error': u'', u'correlation_mode': u'0', u'expression': u'{12900}=1', u'recovery_expression': u'', u'manual_close': u'0'} {u'status': u'0', u'recovery_mode': u'0', u'description': u'Version of zabbix_agent(d) was changed on {HOST.NAME}', u'state': u'0', u'url': u'', u'type': u'0', u'templateid': u'10045', u'correlation_tag': u'', u'lastchange': u'0', u'value': u'0', u'priority': u'1', u'triggerid': u'13492', u'flags': u'0', u'comments': u'', u'error': u'', u'correlation_mode': u'0', u'expression': u'{12928}>0', u'recovery_expression': u'', u'manual_close': u'0'}
  14. 14. Triggers -> Nome,Severidade, Status grupos = zapi.hostgroup.get({“output”:”extend”}) for q in grupos: GroupID = q[u’groupid’] hosts = zapi.host.get({“ouput”: “extend”, “selectInterfaces”: “extend”, “groupids”: GroupID }) for w in hosts: HostID = w[u’hostids’] items = zapi.item.get({"output": "extend", "hostids": HostID }) for e in items: ItemID = e[u’itemid’] triggers = zapi.trigger.get({“output”:”extend”, “itemids”: ItemID }) for r in triggers: TrgName = r[u'description'] TrgPrio = r[u'priority'] TrgStat = r[u'status'] if TrgStat == '0': print "Nome: %s , Severidade: %s " % (TrgName,TrgPrio)
  15. 15. Triggers -> Nome,Severidade, Status Nome: Host name of zabbix_agentd was changed on {HOST.NAME} , Severidade: 1 Nome: Zabbix agent on {HOST.NAME} is unreachable for 5 minutes , Severidade: 3 Nome: Version of zabbix_agent(d) was changed on {HOST.NAME} , Severidade: 1 Nome: Configured max number of opened files is too low on {HOST.NAME} , Severidade: 1 Nome: Configured max number of processes is too low on {HOST.NAME} , Severidade: 1 Nome: Too many processes running on {HOST.NAME} , Severidade: 2 Nome: Too many processes on {HOST.NAME} , Severidade: 2 Nome: Processor load is too high on {HOST.NAME} , Severidade: 2 Nome: Disk I/O is overloaded on {HOST.NAME} , Severidade: 2 Nome: Hostname was changed on {HOST.NAME} , Severidade: 1 Nome: Lack of free swap space on {HOST.NAME} , Severidade: 2 Nome: Host information was changed on {HOST.NAME} , Severidade: 1 Nome: {HOST.NAME} has just been restarted , Severidade: 1
  16. 16. Report Geral: grupos = zapi.hostgroup.get({"output": "extend"}) for q in grupos: GroupID = q[u'groupid’] GroupName = q[u'name’] print "Grupo: %s" % (GroupName) hosts = zapi.host.get({"output": "extend", "selectInterfaces": "extend","groupids" : GroupID }) for w in hosts: HostID = w[u'hostid’] Items = zapi.item.get({"output": "extend", "hostids": HostID }) for e in items: ItemID = e[u'itemid’] ItemName = e[u'name’] ItemKey = e[u'key_’] ItemLastV = e[u'lastvalue’] print "Item: %s Key: %s Valor: %s" % (ItemName,ItemKey,ItemLastV) triggers = zapi.trigger.get({"output":"extend", "itemids": ItemID }) for r in triggers: TrgName = r[u'description’] TrgPrio = r[u'priority’] TrgStat = r[u'status’] if TrgStat == '0’: print "Trigger: %s , Severidade: %s " % (TrgName,TrgPrio)
  17. 17. Report Geral: Grupo: Templates Grupo: Linux servers Grupo: Zabbix servers Item: Host name of zabbix_agentd running Key: agent.hostname Valor: Zabbix server Trigger: Host name of zabbix_agentd was changed on {HOST.NAME} , Severidade: 1 Item: Agent ping Key: agent.ping Valor: 1 Trigger: Zabbix agent on {HOST.NAME} is unreachable for 5 minutes , Severidade: 3 Item: Version of zabbix_agent(d) running Key: agent.version Valor: 3.4.13 Trigger: Version of zabbix_agent(d) was changed on {HOST.NAME} , Severidade: 1 Item: Maximum number of opened files Key: kernel.maxfiles Valor: 26368281 Trigger: Configured max number of opened files is too low on {HOST.NAME} , Severidade: 1
  18. 18. Metodos Usados Metodos https://www.zabbix.com/documentation/3.4/manual/api/reference/hostgroup https://www.zabbix.com/documentation/3.4/manual/api/reference/host https://www.zabbix.com/documentation/3.4/manual/api/reference/item https://www.zabbix.com/documentation/3.4/manual/api/reference/trigger
  19. 19. Luiz Sales Managing Partner at ServiceMonit Specialist and Professional Zabbix luiz.sales@servicemonit.com.br https://github.com/lsa1es/ https://www.linkedin.com/in/lsa1es/

×