Skip to content
This repository has been archived by the owner on May 30, 2023. It is now read-only.

Commit

Permalink
Add logs to track Shinken restart orders
Browse files Browse the repository at this point in the history
  • Loading branch information
mohierf committed Dec 10, 2015
1 parent 6f6e64f commit 43a7064
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions inc/shinkenwebservice.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,24 +147,31 @@ function sendRestartArbiter($force=0, $tag=0, $command='reload') {
$pmTag = new PluginMonitoringTag();
$pmLog = new PluginMonitoringLog();

Toolbox::logInFile("pm-restart", "sendRestartArbiter, command : $command, tag: $tag, force: $force\n");
if (!$pmLog->isRestartLessThanFiveMinutes()
|| $force) {
if ($tag > 0) {
$pmTag->getFromDB($tag);

Toolbox::logInFile("pm-restart", "sendRestartArbiter, tag specified: " . $pmTag->fields['tag'] . "\n");
$url = 'http://'.$pmTag->fields['ip'].':'.$pmTag->fields['port'].'/';
Toolbox::logInFile("pm-restart", "sendRestartArbiter, shinken url: $url\n");

$auth = $pmTag->getAuth($pmTag->fields['tag']);
if ($this->sendCommand($url, $command, array(), '', $auth)) {
Toolbox::logInFile("pm-restart", "sendRestartArbiter, command sent to shinken\n");
$input = array();
$input['user_name'] = $_SESSION['glpifirstname'].' '.$_SESSION['glpirealname'].
' ('.$_SESSION['glpiname'].')';
$input['action'] = $command . "_planned";
$input['date_mod'] = date("Y-m-d H:i:s");
$input['value'] = $pmTag->fields['tag'];
$pmLog->add($input);
} else {
Toolbox::logInFile("pm-restart", "sendRestartArbiter, failed sending command to shinken!\n");
}
} else {
Toolbox::logInFile("pm-restart", "sendRestartArbiter, no tag specified\n");
$a_tagsBrut = $pmTag->find();

$a_tags = array();
Expand All @@ -176,19 +183,25 @@ function sendRestartArbiter($force=0, $tag=0, $command='reload') {
foreach ($a_tags as $data) {
// TODO : should be parameters ... Shinken arbiter may use another port and may use HTTPS !
$url = 'http://'.$data['ip'].':'.$data['port'].'/';
Toolbox::logInFile("pm-restart", "sendRestartArbiter, shinken url: $url\n");

$auth = $pmTag->getAuth($data['tag']);
if ($this->sendCommand($url, $command, array(), '', $auth)) {
Toolbox::logInFile("pm-restart", "sendRestartArbiter, command sent to shinken\n");
$input = array();
$input['user_name'] = $_SESSION['glpifirstname'].' '.$_SESSION['glpirealname'].
' ('.$_SESSION['glpiname'].')';
$input['action'] = $command . "_planned";
$input['date_mod'] = date("Y-m-d H:i:s");
$input['value'] = $data['tag'];
$pmLog->add($input);
} else {
Toolbox::logInFile("pm-restart", "sendRestartArbiter, failed sending command to shinken!\n");
}
}
}
} else {
Toolbox::logInFile("pm-shinken", "sendRestartArbiter, no restart sent to Shinken, previous was too recent!\n");
}
}

Expand Down

0 comments on commit 43a7064

Please sign in to comment.