Hello all!
Finally we finish the API configuration to create a lot of items into a defined host, it's so usefull for us cause we generate a lot of data for our apps.
The api creates the items, another script sends the values to the Items but it recives data randomly, for example, we create 112 items and only 70 of them can storage the data, the another ones appears like bad configuration.
Here it's all the sctripts:
API:
from zabbix_api import ZabbixAPI
import logging
import zabbix_api
username='api'
password='apipass'
zapi = zabbix_api.ZabbixAPI('172.xx.xx.xxx','/zabbix/','http')
zapi.login(username,password)
hostapi = zapi.host
#We know the hostid about a query to database
hostid = '10141'
f = open("estadisticas.dat", "r")
while True:
linea = f.readline()
if not linea: break
a = linea
b = "MTM"
description = b + '.' + a[:-1]
key = linea[:-1]
oid = "interfaces.ifTable.ifEntry.ifInOctets.1"
print hostid
print key
print description
zapi.item.create({ 'hostid' : (hostid),'description' : (description),'key_' : key, 'snmp_oid' : oid , 'type' : "2", 'value_type' : "3", 'formula' : "1", 'snmp_community' : "public" })
The API creates all the lines from the estadisticas.dat file to items into zabbix, an example lines:
Estadisticas.dat
SCA_WAS6INT_MSGS_RESPONDIDOS
SCA_WAS6INT_TIEMPO_MIN_RESPUESTA
SCA_WAS6INT_TIEMPO_MAX_RESPUESTA
SCA_WAS6INT_TIEMPO_MED_RESPUESTA
SCA_WAS6INT_NUM_CLI_AHORA
SCA_WAS6INT_NUM_MAX_CLI_START
After this, we runs a script which send data to those items (112):
Send_data.sh
/home/zabbix/bin/zabbix_sender -c /home/zabbix/conf/zabbix_agentd.conf -k SCA_WAS6INT_MSGS_RESPONDIDOS -o 14736
/home/zabbix/bin/zabbix_sender -c /home/zabbix/conf/zabbix_agentd.conf -k SCA_WAS6INT_TIEMPO_MIN_RESPUESTA -o 0.000
/home/zabbix/bin/zabbix_sender -c /home/zabbix/conf/zabbix_agentd.conf -k SCA_WAS6INT_TIEMPO_MAX_RESPUESTA -o 2.696
/home/zabbix/bin/zabbix_sender -c /home/zabbix/conf/zabbix_agentd.conf -k SCA_WAS6INT_TIEMPO_MED_RESPUESTA -o 0.013
/home/zabbix/bin/zabbix_sender -c /home/zabbix/conf/zabbix_agentd.conf -k SCA_WAS6INT_NUM_CLI_AHORA -o 3
/home/zabbix/bin/zabbix_sender -c /home/zabbix/conf/zabbix_agentd.conf -k SCA_WAS6INT_NUM_MAX_CLI_START -o 127214547
The .conf file have the same Hostname than zabbix host configured, and I think is more ellegant to put -c than all the configuration values (and more easy).
The output of the Send_data.sh:
./zabbix_sender -vv -c /home/monaf/zabbix/conf/zabbix_agentd.conf -s bos -k SCA_WAS6INT_NUM_MAX_CLI_START -o 1
zabbix_sender [1778104]: DEBUG: Answer [{
"response":"success",
"info":"Processed 0 Failed 1 Total 1 Seconds spent 0.000019"}]
Info from server: "Processed 0 Failed 1 Total 1 Seconds spent 0.000019"
sent: 1; skipped: 0; total: 1
Of course the firewalls are open to the 10051 and 10050 ports.
Any idea?

Thanks all!
Finally we finish the API configuration to create a lot of items into a defined host, it's so usefull for us cause we generate a lot of data for our apps.
The api creates the items, another script sends the values to the Items but it recives data randomly, for example, we create 112 items and only 70 of them can storage the data, the another ones appears like bad configuration.
Here it's all the sctripts:
API:
from zabbix_api import ZabbixAPI
import logging
import zabbix_api
username='api'
password='apipass'
zapi = zabbix_api.ZabbixAPI('172.xx.xx.xxx','/zabbix/','http')
zapi.login(username,password)
hostapi = zapi.host
#We know the hostid about a query to database
hostid = '10141'
f = open("estadisticas.dat", "r")
while True:
linea = f.readline()
if not linea: break
a = linea
b = "MTM"
description = b + '.' + a[:-1]
key = linea[:-1]
oid = "interfaces.ifTable.ifEntry.ifInOctets.1"
print hostid
print key
print description
zapi.item.create({ 'hostid' : (hostid),'description' : (description),'key_' : key, 'snmp_oid' : oid , 'type' : "2", 'value_type' : "3", 'formula' : "1", 'snmp_community' : "public" })
The API creates all the lines from the estadisticas.dat file to items into zabbix, an example lines:
Estadisticas.dat
SCA_WAS6INT_MSGS_RESPONDIDOS
SCA_WAS6INT_TIEMPO_MIN_RESPUESTA
SCA_WAS6INT_TIEMPO_MAX_RESPUESTA
SCA_WAS6INT_TIEMPO_MED_RESPUESTA
SCA_WAS6INT_NUM_CLI_AHORA
SCA_WAS6INT_NUM_MAX_CLI_START
After this, we runs a script which send data to those items (112):
Send_data.sh
/home/zabbix/bin/zabbix_sender -c /home/zabbix/conf/zabbix_agentd.conf -k SCA_WAS6INT_MSGS_RESPONDIDOS -o 14736
/home/zabbix/bin/zabbix_sender -c /home/zabbix/conf/zabbix_agentd.conf -k SCA_WAS6INT_TIEMPO_MIN_RESPUESTA -o 0.000
/home/zabbix/bin/zabbix_sender -c /home/zabbix/conf/zabbix_agentd.conf -k SCA_WAS6INT_TIEMPO_MAX_RESPUESTA -o 2.696
/home/zabbix/bin/zabbix_sender -c /home/zabbix/conf/zabbix_agentd.conf -k SCA_WAS6INT_TIEMPO_MED_RESPUESTA -o 0.013
/home/zabbix/bin/zabbix_sender -c /home/zabbix/conf/zabbix_agentd.conf -k SCA_WAS6INT_NUM_CLI_AHORA -o 3
/home/zabbix/bin/zabbix_sender -c /home/zabbix/conf/zabbix_agentd.conf -k SCA_WAS6INT_NUM_MAX_CLI_START -o 127214547
The .conf file have the same Hostname than zabbix host configured, and I think is more ellegant to put -c than all the configuration values (and more easy).
The output of the Send_data.sh:
./zabbix_sender -vv -c /home/monaf/zabbix/conf/zabbix_agentd.conf -s bos -k SCA_WAS6INT_NUM_MAX_CLI_START -o 1
zabbix_sender [1778104]: DEBUG: Answer [{
"response":"success",
"info":"Processed 0 Failed 1 Total 1 Seconds spent 0.000019"}]
Info from server: "Processed 0 Failed 1 Total 1 Seconds spent 0.000019"
sent: 1; skipped: 0; total: 1
Of course the firewalls are open to the 10051 and 10050 ports.
Any idea?


Thanks all!

Comment