Skip to content

Commit 0d16840

Browse files
author
alexander popov
committed
fix and added check line's metric
1 parent 86c7d26 commit 0d16840

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

mamonsu/lib/parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@
121121
Export metrics to zabbix server
122122
Command: --send-data-zabbix
123123
Example:
124-
{prog} --send-data-zabbix --zabbix-file=localhost.log --zabbix-addres=licalhost
124+
{prog} --send-data-zabbix --zabbix-file=localhost.log --zabbix-address=localhost
125125
Options:
126126
--zabbix-address <name of the Zabbix host to send metrics>
127127
--zabbix-port <port of Zabbix server to send metrics> by default 10051

mamonsu/lib/senders/zbx.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,19 @@ def send_file_to_zabbix (self,path):
7373
while True:
7474
lines=list(islice(f, 100))
7575
for line in lines:
76-
split_line = line.rstrip('\n').split('\t')
77-
metric = {
78-
'host': zabbix_client,
79-
'key': split_line[2],
80-
'value': split_line[1],
81-
'clock': int(split_line[0])}
82-
metrics.append(metric)
76+
try:
77+
split_line = line.rstrip('\n').split('\t')
78+
if len(split_line) == 3:
79+
metric = {
80+
'host': zabbix_client,
81+
'key': split_line[2],
82+
'value': split_line[1],
83+
'clock': int(split_line[0])}
84+
metrics.append(metric)
85+
else:
86+
self.log.error('Can\'t load metric in line: "{0}". The line must have the format: time <tab> value <tab> metric\'s name.'.format(line.rstrip('\n')))
87+
except Exception as e:
88+
self.log.error('Can\'t load metric in line: "{0}". Error : {1} '.format(line.rstrip('\n'),e,))
8389

8490
data = json.dumps({
8591
'request': 'sender data',

0 commit comments

Comments
 (0)