1 <?php
defined('SYSPATH') OR die('No direct access allowed.');
3 * Helper class for nacoma
5 * Copyright 2009 op5 AB
6 * op5, and the op5 logo are trademarks, servicemarks, registered servicemarks
7 * or registered trademarks of op5 AB.
8 * All other trademarks, servicemarks, registered trademarks, and registered
9 * servicemarks mentioned herein may be the property of their respective owner(s).
10 * The information contained herein is provided AS IS with NO WARRANTY OF ANY
11 * KIND, INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY, AND FITNESS FOR A
17 * Check if a link to Nacoma should be displayed
18 * This depends on if Nacoma is actually available
19 * and if the user is authorized to use it.
21 public static function link($path=false, $img=false, $title=false)
23 # don't try this if user isn't logged in
24 if (!Auth
::instance()->logged_in()) {
27 if (!Auth
::instance()->authorized_for('configuration_information') || Kohana
::config('config.nacoma_path')===false) {
32 if (!empty($path) && !empty($img)) {
33 $link = html
::anchor($path, html
::image(ninja
::add_path($img),array('alt' => $title, 'title' => $title)), array('style' => 'border: 0px'));
35 # helper only used to decide if the link should be displayed at all
42 * Check if the current user is allowed to use Nacoma
46 public static function allowed() {
47 if (!Auth
::instance()->logged_in()) {
51 if (!Auth
::instance()->authorized_for('configuration_information') || Kohana
::config('config.nacoma_path')===false) {
59 * Delete host (and associated services) using monitor CLI api
61 * @param $host string host to be deleted
63 public static function delHost ($host) {
64 if (!nacoma
::allowed())
67 exec('php /opt/monitor/op5/nacoma/api/monitor.php -u ' . Auth
::instance()->get_user()->username
. ' -t host -n ' . escapeshellarg($host) . ' -a delete', $out, $retval);
73 * Given a service name, returns the name of the hostgroup this service
74 * belongs to, or false if it is a host service.
76 public static function getHostgroupForService($service) {
77 if (!nacoma
::allowed())
80 exec('php /opt/monitor/op5/nacoma/api/monitor.php -u ' . Auth
::instance()->get_user()->username
. ' -t service -a show_object -n ' . escapeshellarg($service), $out, $retval);
83 foreach ($out as $line) {
84 list($key, $val) = explode("=", $line);
85 if ($key == 'hostgroup_name')
92 * Delete the service using monitor CLI api
94 * @param $service string service to be deleted, format HOST;SERVICE
96 public static function delService ($service) {
97 if (!nacoma
::allowed())
100 exec('php /opt/monitor/op5/nacoma/api/monitor.php -u ' . Auth
::instance()->get_user()->username
. ' -t service -n ' . escapeshellarg($service) . ' -a delete', $out, $retval);
102 return $retval === 0;