jbfavre / python-protobix

Very simple python module implementing Zabbix Sender protocol.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unnecessary division / multiplication in senderprotocol.py ' clock' method

opened this issue · comments

In file senderprotocol.py, line 106

@Property
def clock(self):
return int((time.time())/60*60)

Looks like you want divide time by 3600, but for now it multiply by 60 and than multiply by 60. Please correct me if i'm wrong

@HumanUser actually you're right :)

Python time.time() method returns an epoch time in seconds, ie the number of seonds since the 1st of january 1970.
Zabbix requires also an epoch timestamp.

What I wanted to get as default clock value is the current minute, not second, ie 18:34:00 and not 18:34:35, which is more convenient for Zabbix graphs.
That said, I figured out I should use int(time.time()/60)*60 to get the right result :-/

> python
Python 2.7.10 (default, Sep 13 2015, 20:30:50) 
[GCC 5.2.1 20150911] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import time
>>> print time.time()
1443458075.61
>>> print time.time()/60
24057634.5935
>>> print time.time()/60*60
1443458075.61
>>> print int(time.time()/60*60)
1443458075
>>> print int(time.time()/60)*60
1443458040
>>> print time.ctime(1443458075)
Mon Sep 28 18:34:35 2015
>>> print time.ctime(1443458040)
Mon Sep 28 18:34:00 2015

Thanks for pointing that out, will fix it asap

Please leave it open till it's fixed.
Thanks