mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Snmpsim fail when it fails (#8392)
* Update snmpsim to fail better if it can't be started. The main issue is the isRunning() check was done too soon after forking, the sh process was still running. * increase default delay to 2s * Pull this back, all we need is the sleep really. * Remove removed exception
This commit is contained in:
committed by
Neil Lathwood
parent
ca09cf61ac
commit
cc377353f3
@@ -45,7 +45,13 @@ class Snmpsim
|
||||
$this->snmprec_dir = Config::get('install_dir') . "/tests/snmpsim/";
|
||||
}
|
||||
|
||||
public function fork()
|
||||
/**
|
||||
* Run snmpsimd and fork it into the background
|
||||
* Captures all output to the log
|
||||
*
|
||||
* @param int $wait Wait for x seconds after starting before returning
|
||||
*/
|
||||
public function fork($wait = 2)
|
||||
{
|
||||
if ($this->isRunning()) {
|
||||
echo "Snmpsim is already running!\n";
|
||||
@@ -61,11 +67,18 @@ class Snmpsim
|
||||
|
||||
$this->proc = new Proc($cmd);
|
||||
|
||||
if ($wait) {
|
||||
sleep($wait);
|
||||
}
|
||||
|
||||
if (isCli() && !$this->proc->isRunning()) {
|
||||
echo `tail -5 $this->log` . PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop and start the running snmpsim process
|
||||
*/
|
||||
public function restart()
|
||||
{
|
||||
$this->stop();
|
||||
@@ -82,6 +95,11 @@ class Snmpsim
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Run snmpsimd but keep it in the foreground
|
||||
* Outputs to stdout
|
||||
*
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
echo "Starting snmpsim listening on {$this->ip}:{$this->port}... \n";
|
||||
@@ -121,6 +139,12 @@ class Snmpsim
|
||||
return $this->port;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the command for snmpsimd
|
||||
*
|
||||
* @param bool $with_log
|
||||
* @return string
|
||||
*/
|
||||
private function getCmd($with_log = true)
|
||||
{
|
||||
$cmd = "snmpsimd.py --data-dir={$this->snmprec_dir} --agent-udpv4-endpoint={$this->ip}:{$this->port}";
|
||||
|
@@ -23,7 +23,6 @@
|
||||
* @author Tony Murray <murraytony@gmail.com>
|
||||
*/
|
||||
|
||||
use LibreNMS\Proc;
|
||||
use LibreNMS\Util\Snmpsim;
|
||||
|
||||
global $config;
|
||||
|
Reference in New Issue
Block a user