Commit 71c446a4 authored by Côme Chilliet's avatar Côme Chilliet

feat(systems): Add a menu action to ping systems

This goes through argonaut-server and result may depend on which modules
 are installed.
We may want to add some special Ping module on argonaut-server side for
 using ping directly instead of argonaut-client/OPSI, or as a fallback.

issue #1311
parent e9d42054
...@@ -93,9 +93,11 @@ class systemManagement extends simpleManagement ...@@ -93,9 +93,11 @@ class systemManagement extends simpleManagement
'label' => $data['name'], 'label' => $data['name'],
); );
} }
$this->registerAction('ping', 'pingSystems');
} else { } else {
unset($this->headpage->xmlData['actionmenu']['action'][2]); unset($this->headpage->xmlData['actionmenu']['action'][2]);
unset($this->headpage->xmlData['actionmenu']['action'][3]); unset($this->headpage->xmlData['actionmenu']['action'][3]);
unset($this->headpage->xmlData['actionmenu']['action'][4]);
$this->headpage->xmlData['actionmenu']['action'] = array_values($this->headpage->xmlData['actionmenu']['action']); $this->headpage->xmlData['actionmenu']['action'] = array_values($this->headpage->xmlData['actionmenu']['action']);
} }
$this->registerAction('saveEvent', 'saveEventDialog'); $this->registerAction('saveEvent', 'saveEventDialog');
...@@ -187,6 +189,57 @@ class systemManagement extends simpleManagement ...@@ -187,6 +189,57 @@ class systemManagement extends simpleManagement
} }
} }
/*! \brief Ping those systems and show the result in the list
*/
function pingSystems($action, array $target)
{
if (!$this->siActive) {
return;
}
$headpage = $this->getHeadpage();
$macs = array();
// Collect target mac addresses
foreach ($target as $dn) {
$obj = $headpage->getEntry($dn);
if (isset($obj['macAddress'][0])) {
$macs[$dn] = $obj['macAddress'][0];
} else {
msg_dialog::display(_('Action canceled'), sprintf(_('System %s has no mac address defined, cannot trigger action'), $dn), ERROR_DIALOG);
}
}
if (count($macs) == 0) {
return;
}
$o_queue = new supportDaemon();
$res = $o_queue->append_call('ping', array_values($macs), array('fullresult' => 1));
if ($o_queue->is_error()) {
msg_dialog::display(_('Infrastructure service'), msgPool::siError($o_queue->get_error()), ERROR_DIALOG);
} else {
$dns = array_flip($macs);
$msg = '';
if (!empty($res['results'])) {
$msg .= '<ul>'."\n";
foreach ($res['results'] as $mac => $on) {
$msg .= '<li style="list-style-type:'.($on ? 'disk':'circle').';">'.objects::link($dns[$mac], $this->getType($dns[$mac])).' - '.($on ? 'On':'Off').'</li>'."\n";
}
$msg .= "</ul>\n";
}
if (!empty($res['errors'])) {
$msg .= '<ul style="list-style-type:square;">'."\n";
foreach ($res['errors'] as $mac => $error) {
$msg .= '<li>'.objects::link($dns[$mac], $this->getType($dns[$mac])).' - '.$error.'</li>'."\n";
}
$msg .= "</ul>\n";
}
msg_dialog::display(_('Ping results'), $msg, INFO_DIALOG);
}
}
/*! \brief Save event dialogs. /*! \brief Save event dialogs.
* And append the new Argonaut event. * And append the new Argonaut event.
*/ */
......
...@@ -108,6 +108,14 @@ ...@@ -108,6 +108,14 @@
<depends>argonautAction</depends> <depends>argonautAction</depends>
</action> </action>
<action>
<name>ping</name>
<type>entry</type>
<image>geticon.php?context=actions&amp;icon=task-start&amp;size=16</image>
<label>Ping</label>
<depends>argonautAction</depends>
</action>
<action> <action>
<type>separator</type> <type>separator</type>
</action> </action>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment