Array of states
This commit is contained in:
7
hook.php
7
hook.php
@@ -21,7 +21,12 @@
|
||||
--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
function plugin_remotesupport_install(){
|
||||
function plugin_remotesupport_install()
|
||||
{
|
||||
global $DB;
|
||||
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -48,6 +48,7 @@ declare(ticks=1);
|
||||
global $DB,$agents;
|
||||
|
||||
$check_arr = [];
|
||||
$comps = [];
|
||||
$pfInventoryComputerComputer = new PluginFusioninventoryInventoryComputerComputer();
|
||||
foreach (getAllDataFromTable(PluginFusioninventoryAgent::getTable()) as $a) {
|
||||
|
||||
@@ -60,6 +61,7 @@ global $DB,$agents;
|
||||
$check["status"] = "unknown";
|
||||
|
||||
$check_arr[] = $check;
|
||||
$comps[$a["computers_id"]] = $check;
|
||||
//print_r($agent->getAgentStatusURLs());
|
||||
}
|
||||
|
||||
@@ -73,7 +75,7 @@ $descriptorspec = array(
|
||||
$cwd = '/tmp';
|
||||
$env = array('debug' => 'false');
|
||||
|
||||
$process = proc_open(__DIR__.'/bench_urls', $descriptorspec, $pipes, $cwd, $env);
|
||||
$process = proc_open(__DIR__.'/check_status', $descriptorspec, $pipes, $cwd, $env);
|
||||
|
||||
if (is_resource($process)) {
|
||||
// $pipes now looks like this:
|
||||
@@ -94,8 +96,18 @@ if (is_resource($process)) {
|
||||
echo "command returned $return_value\n";
|
||||
}
|
||||
|
||||
$req = $DB->request('glpi_states', ['FIELDS' => ['glpi_states' => ['id', 'name']]], [ 'OR' => [ 'name' => 'Online', 'name' => 'Offline']]);
|
||||
|
||||
$ret = $req->next();
|
||||
$states_ids[$ret['name']] = $ret['id'];
|
||||
$ret = $req->next();
|
||||
$states_ids[$ret['name']] = $ret['id'];
|
||||
print_r($states_ids);
|
||||
|
||||
|
||||
|
||||
$DB->update("glpi_computers", [
|
||||
'states_id' => NULL ] ,
|
||||
'states_id' => $states_ids["Offline"] ] ,
|
||||
[ '1' => '1' ]
|
||||
);
|
||||
|
||||
@@ -105,7 +117,7 @@ foreach ($checked as $s) {
|
||||
|
||||
$comp = new Computer();
|
||||
$comp->getFromDB($s->computers_id);
|
||||
$comp->fields["states_id"] = 2;
|
||||
$comp->fields["states_id"] = $states_ids["Online"];
|
||||
$DB->update("glpi_computers", [
|
||||
'states_id' => $comp->fields["states_id"] ],
|
||||
[ 'id' => $s->computers_id ]
|
||||
|
||||
@@ -40,15 +40,32 @@ class PluginRemotesupportRemotesupport extends CommonDBTM {
|
||||
|
||||
}
|
||||
|
||||
static function getStatesIds() {
|
||||
global $DB;
|
||||
|
||||
$states_ids = [];
|
||||
|
||||
$req = $DB->request('glpi_states', ['FIELDS' => ['glpi_states' => ['id', 'name']]], [ 'OR' => [ 'name' => 'Online', 'name' => 'Offline']]);
|
||||
|
||||
$ret = $req->next();
|
||||
$states_ids[$ret['name']] = $ret['id'];
|
||||
$ret = $req->next();
|
||||
$states_ids[$ret['name']] = $ret['id'];
|
||||
|
||||
return $states_ids;
|
||||
}
|
||||
|
||||
static function cronRemotesupport($task) {
|
||||
global $DB;
|
||||
|
||||
Toolbox::logInFile("remotsupport","Starting search of agents\n");
|
||||
Toolbox::logInFile("remotsupport","Starting search of agents\n");
|
||||
|
||||
$agents = [];
|
||||
$data_set = [];
|
||||
|
||||
$stids = self::getStatesIds();
|
||||
|
||||
|
||||
foreach (getAllDataFromTable(PluginFusioninventoryAgent::getTable()) as $a) {
|
||||
|
||||
$data_set[] = $a["id"];
|
||||
@@ -67,9 +84,9 @@ class PluginRemotesupportRemotesupport extends CommonDBTM {
|
||||
$comp = new Computer();
|
||||
$comp->getFromDB($agents[$id]["computers_id"]);
|
||||
if ($st["message"] == "noanswer")
|
||||
$comp->fields["states_id"] = NULL;
|
||||
$comp->fields["states_id"] = $stids["Offline"];
|
||||
else
|
||||
$comp->fields["states_id"] = 2;
|
||||
$comp->fields["states_id"] = $stids["Online"];
|
||||
$DB->update("glpi_computers", [
|
||||
'states_id' => $comp->fields["states_id"] ],
|
||||
[ 'id' => $agents[$id]["computers_id"] ]
|
||||
|
||||
Reference in New Issue
Block a user