Added NOW() to dbUpdate calls to sensors #2592

Merged
merged 1 commit into from Dec 20, 2015

Projects

None yet

5 participants

@laf
Member
laf commented Dec 9, 2015

Needed for #2493 and #2590

@laf laf Added NOW() to dbUpdate calls to sensors
8953e26
@laf laf added the Polling label Dec 9, 2015
@f0o
Member
f0o commented Dec 10, 2015

I think that attempts a verbatim update 'NOW()' string, doesnt it?

@paulgear
Member

Yeah - don't think functions can be passed as parameters. But if it's an autoupdate field, we can just leave it off and MySQL will fill it in. MIB-based polling does that.

@f0o
Member
f0o commented Dec 10, 2015

Like discussed on IRC, MySQL only updates the auto-update field if the new values are different than the old ones. For a sensor like bat0 voltage thats very stable it will nearly never update and librenms will always assume something is wrong.

Bpaste with test in IRC backlog at about 9pm UTC

On 10 December 2015 07:46:26 CET, Paul Gear notifications@github.com wrote:

Yeah - don't think functions can be passed as parameters. But if it's
an autoupdate field, we can just leave it off and MySQL will fill it
in. MIB-based polling does that.


Reply to this email directly or view it on GitHub:
#2592 (comment)

@f0o
Member
f0o commented Dec 10, 2015

For the log:

MariaDB [librenms]> select sensor_id,lastupdate from sensors;                                                                                                            
+-----------+---------------------+
| sensor_id | lastupdate          |
+-----------+---------------------+
|         1 | 2015-12-09 21:54:03 |
+-----------+---------------------+
1 row in set (0.00 sec)

MariaDB [librenms]> select NOW();
+---------------------+
| NOW()               |
+---------------------+
| 2015-12-09 21:57:16 |
+---------------------+
1 row in set (0.00 sec)

MariaDB [librenms]> update sensors set sensor_id = 1 where sensor_id = 1;
Query OK, 0 rows affected (0.00 sec)
Rows matched: 1  Changed: 0  Warnings: 0

MariaDB [librenms]> select NOW();
+---------------------+
| NOW()               |
+---------------------+
| 2015-12-09 21:57:21 |
+---------------------+
1 row in set (0.00 sec)

MariaDB [librenms]> select sensor_id,lastupdate from sensors;                                                                                                            
+-----------+---------------------+
| sensor_id | lastupdate          |
+-----------+---------------------+
|         1 | 2015-12-09 21:54:03 |
+-----------+---------------------+
1 row in set (0.00 sec)
@laf
Member
laf commented Dec 10, 2015

We use it in includes/discovery/functions.inc.php:

dbUpdate(array('last_discovered' => array('NOW()'), 'type' => $device['type'], 'last_discovered_timetaken' => $device_time), 'devices', '`device_id` = ?', array($device['device_id']));

And that seems to work ok.

@laf
Member
laf commented Dec 10, 2015

Bump

@f0o
Member
f0o commented Dec 11, 2015

Giving it a whirl at home today

@Rosiak
Contributor
Rosiak commented Dec 13, 2015

👍

@laf
Member
laf commented Dec 18, 2015

bump

@f0o f0o merged commit 4262d7f into librenms:master Dec 20, 2015

2 checks passed

Auto-Deploy Build finished. No test results found.
Details
Scrutinizer No new issues
Details
@laf laf deleted the laf:issue-2493-1 branch Dec 20, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment