{"action":"closed","issue":{"url":"https://api.github.com/repos/jpmens/mqttwarn/issues/248","repository_url":"https://api.github.com/repos/jpmens/mqttwarn","labels_url":"https://api.github.com/repos/jpmens/mqttwarn/issues/248/labels{/name}","comments_url":"https://api.github.com/repos/jpmens/mqttwarn/issues/248/comments","events_url":"https://api.github.com/repos/jpmens/mqttwarn/issues/248/events","html_url":"https://github.com/jpmens/mqttwarn/issues/248","id":235652001,"number":248,"title":"rrdtool service will always use \"now\" as timestamp ","user":{"login":"otdftr","id":1713611,"avatar_url":"https://avatars2.githubusercontent.com/u/1713611?v=3","gravatar_id":"","url":"https://api.github.com/users/otdftr","html_url":"https://github.com/otdftr","followers_url":"https://api.github.com/users/otdftr/followers","following_url":"https://api.github.com/users/otdftr/following{/other_user}","gists_url":"https://api.github.com/users/otdftr/gists{/gist_id}","starred_url":"https://api.github.com/users/otdftr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/otdftr/subscriptions","organizations_url":"https://api.github.com/users/otdftr/orgs","repos_url":"https://api.github.com/users/otdftr/repos","events_url":"https://api.github.com/users/otdftr/events{/privacy}","received_events_url":"https://api.github.com/users/otdftr/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2017-06-13T18:42:05Z","updated_at":"2017-06-22T10:09:52Z","closed_at":"2017-06-22T10:09:52Z","body":"Great idea to link mqtt and rrd, but my use case involves using **retained data** (mosquitto_pub -r option) for a \"last known good\" appoach and **manually submitting older data with distinct timestamps**. As rrdtool simply drops / ignores updates with a timestamp encountered before, replays and duplicate submission will not cause any harm to the rrd database.\r\n\r\nUnfortunately, mqttwarn's rrd service always adds an N: in front of the submitted data, which will break all my above use cases. I would need a rrdtool call like\r\n`rrdtool.update(item.addrs + text.split())`\r\nfor the update. This would require the 'N:' to be present in the format= parameter of mqttwarn.ini if needed - which would break existing configurations.\r\n\r\nSo I suggest the following amendment / enhacement to the rrdtool service (patch is here: [rrdtool.py.patch.zip](https://github.com/jpmens/mqttwarn/files/1072479/rrdtool.py.patch.zip)):\r\n````\r\n-        rrdtool.update(item.addrs, \"N:\" + text)\r\n+       # mofified by otfdr @ github to accept abitray arguments with\r\n+       # the payload and to not always add the 'N' in front\r\n+       # 2017-06-05\r\n+       if re.match( \"^\\d+$\", text ):\r\n+               rrdtool.update(item.addrs, \"N:\" + text)\r\n+       else:\r\n+               rrdtool.update(item.addrs + text.split())\r\n````\r\n\r\nThis will treat plain numeric msg/text as before - prefixing it with 'N:' - but will also provide for passing timestamed data such as `1497375249:68` and would leave it to the configurator's discretion whether to place extra parameters in the `[config:rrdtool]` section _or_ in the `format =` of the event config.\r\n\r\n### Use case / application note\r\n\r\n![battery gauges through owntracks mqtt mqttwarn rrdtool](https://user-images.githubusercontent.com/1713611/27098184-f9f32cfe-5076-11e7-8410-268fd2721085.png)\r\n\r\nWith the amendment, my mqttwarn.ini for a hook-up owntracks > mqtt > rrd goes like\r\n````\r\n; [...]\r\n\r\n[config:mqttpub]\r\ntargets = {\r\n    'batt' : [ 'datalog/sensors/batt/{device}', 0, True ],\r\n    }\r\n\r\n; now, batt gauge writing to - as we will have retained = old data, the standard N:<message> of\r\n; the standard rrdtool service will not help -> tweak rrdtool to not add the N: and thus allow \r\n; timestamps for historic data. duplicates are no problem, because rrdtool will discard them\r\n\r\n[config:rrdtool]\r\ntargets = {\r\n        # 'battsensor': [ '/srv/rrd/sensors/{sensor_id}.rrd', '-t', 'batt' ],\r\n        # -> aah, no: use the format= an put everything there\r\n        'battsensor': [ ],\r\n        }\r\n\r\n; [...]\r\n\r\n[owntracks-battery-log]\r\ntopic = owntracks/+/+\r\ntargets = log:info, mqttpub:batt\r\ndatamap = OwnTracksTopic2Data()\r\nfilter  = OwnTracksBattFilterOS()\r\nformat  = OwnTracksBattFormatOS()\r\n; extract mobile device's batt info from owntracks messages,\r\n; create payload containing {sensor_id} {ts} {batt} ( timestamp / battery \r\n; gauge ) publish as topic datalog/sensors/batt/{device}\r\n; !! function params must be function() w/o params, called with dictionary of data\r\n\r\n[datalog-battery-log]\r\ntopic = datalog/sensors/batt/+\r\ntargets = log:info,rrdtool:battsensor\r\nformat = /srv/rrd/sensors/{sensor_id}.rrd -t batt {ts}:{batt}\r\n; push battery gauge data to rrd\r\n\r\n; [...]\r\n````\r\n\r\n"}}
{"actor":{"display_login":"jpmens"}}