Hi,
using the excellent API for PHP by Denis Basta, I have an script which is called every 15 minutes by Cacti in order to retrieve UPS status. The scripts works correctly but from time to time (every several weeks) it doesn’t retrieve more data and requires a router reboot. I have defined an specific user “monitor” with read only access which is being used by this script. I have also enabled the API service.
I have been investigating and in the winbox: System > Users > Active Users, there hare thousands of active instances of user “monitor”; one each 15 minutes…
It seems like the script is not doing logout of the connection and routeros thinks the connection is still active?
Has anybody noticed something similar?
Thank you for any idea,
Antonio
#!/usr/bin/php
<?php require('routeros_api.class.php'); $API = new routeros_api(); //$API->debug = true; if ($API->connect($argv[1], 'monitor', 'XXXXXX')) { $API->write('/system/ups/monitor',false); $API->write('=numbers=ups1',false); $API->write('=once='); $READ = $API->read(false); $ARRAY = $API->parse_response($READ); $minutos = strtok($ARRAY[0]['runtime-left'], " ") * 60.0; $minutos += strtok(" "); echo "line_volt:" . $ARRAY[0]['line-voltage']/100.0 . " load_pct:" . $ARRAY[0]['load'] . " b_charge:" . $ARRAY[0]['battery-charge'] . " int_temp:" . $ARRAY[0]['temperature']/100.0 . " bat_volt:" . $ARRAY[0]['battery-voltage']/100.0 . " line_freq:" . $ARRAY[0]['frequency'] . " time_left:" . $minutos; $API->disconnect(); } ?>