Add API function to check daemon status of monitor

This replaces daemonStatus(), zmcStatus() and zmaStatus() from
the original includes/functions.php.

Can be accessed like:
/api/monitors/daemonStatus/id:2/daemon:zma.json
This commit is contained in:
Kyle Johnson 2014-11-26 03:38:41 +00:00
parent b0aeea262b
commit dcde5e16ad
1 changed files with 38 additions and 0 deletions

View File

@ -124,5 +124,43 @@ class MonitorsController extends AppController {
));
}
// Check if a daemon is running for the monitor id
public function daemonStatus() {
$id = $this->request->params['named']['id'];
$daemon = $this->request->params['named']['daemon'];
if (!$this->Monitor->exists($id)) {
throw new NotFoundException(__('Invalid monitor'));
}
$monitor = $this->Monitor->find('first', array(
'fields' => array('Id', 'Type', 'Device'),
'conditions' => array('Id' => $id)
));
// Clean up the returned array
$monitor = Set::extract('/Monitor/.', $monitor);
// Pass -d for local, otherwise -m
if ($monitor[0]['Type'] == 'Local') {
$args = "-d ". $monitor[0]['Device'];
} else {
$args = "-m ". $monitor[0]['Id'];
}
// Build the command, and execute it
$zm_path_bin = Configure::read('ZM_PATH_BIN');
$command = escapeshellcmd("$zm_path_bin/zmdc.pl status $daemon $args");
$status = exec( $command );
// If 'not' is present, the daemon is not running, so return false
$status = (strpos($status, 'not')) ? false : true;
$this->set(array(
'status' => $status,
'_serialize' => array('status')
));
}
}