mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
IRC bot - detect lost communication
Force reconnect if no data received from server for config['irc_conn_timeout'] seconds (that may happen when network/VPN goes down - in such case IRC bot won't get immediately notification that connection was lost, at least till it tries to send anything).
This commit is contained in:
17
irc.php
17
irc.php
@@ -28,7 +28,8 @@ require_once 'includes/discovery/functions.inc.php';
|
|||||||
error_reporting(E_ERROR);
|
error_reporting(E_ERROR);
|
||||||
|
|
||||||
class ircbot {
|
class ircbot {
|
||||||
|
private $last_activity = '';
|
||||||
|
|
||||||
private $data = '';
|
private $data = '';
|
||||||
|
|
||||||
private $authd = array();
|
private $authd = array();
|
||||||
@@ -149,6 +150,8 @@ class ircbot {
|
|||||||
$this->connect_alert();
|
$this->connect_alert();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->last_activity = time();
|
||||||
|
|
||||||
$this->j = 2;
|
$this->j = 2;
|
||||||
|
|
||||||
$this->connect();
|
$this->connect();
|
||||||
@@ -170,6 +173,17 @@ class ircbot {
|
|||||||
if ($this->config['irc_alert']) {
|
if ($this->config['irc_alert']) {
|
||||||
$this->alertData();
|
$this->alertData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($this->config['irc_conn_timeout']) {
|
||||||
|
$inactive_seconds = time() - $this->last_activity;
|
||||||
|
$max_inactive = $this->config['irc_conn_timeout'];
|
||||||
|
|
||||||
|
if( $inactive_seconds > $max_inactive) {
|
||||||
|
$this->log("No data from server since " . $max_inactive . " seconds. Restarting.");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
usleep($this->tick);
|
usleep($this->tick);
|
||||||
}
|
}
|
||||||
@@ -267,6 +281,7 @@ class ircbot {
|
|||||||
|
|
||||||
private function getData() {
|
private function getData() {
|
||||||
if (($data = $this->read('irc')) !== false) {
|
if (($data = $this->read('irc')) !== false) {
|
||||||
|
$this->last_activity = time();
|
||||||
$this->data = $data;
|
$this->data = $data;
|
||||||
$ex = explode(' ', $this->data);
|
$ex = explode(' ', $this->data);
|
||||||
if ($ex[0] == 'PING') {
|
if ($ex[0] == 'PING') {
|
||||||
|
Reference in New Issue
Block a user