2011-09-20 09:55:11 +00:00
<? php
2011-09-14 13:38:01 +00:00
2015-07-13 20:10:26 +02:00
$pagetitle [] = 'Services' ;
2011-10-18 14:41:19 +00:00
2011-09-14 13:38:01 +00:00
print_optionbar_start ();
2010-05-03 16:20:32 +00:00
2016-03-22 07:35:39 +10:00
require_once 'includes/modal/new_service.inc.php' ;
require_once 'includes/modal/delete_service.inc.php' ;
2015-07-13 20:10:26 +02:00
echo "<span style='font-weight: bold;'>Services</span> » " ;
2011-04-29 23:09:35 +00:00
2015-07-13 20:10:26 +02:00
$menu_options = array (
'basic' => 'Basic' ,
);
if ( ! $vars [ 'view' ]) {
$vars [ 'view' ] = 'basic' ;
}
2016-03-15 22:16:08 +10:00
$status_options = array (
'all' => 'All' ,
'ok' => 'Ok' ,
'warning' => 'Warning' ,
'critical' => 'Critical' ,
);
if ( ! $vars [ 'state' ]) {
$vars [ 'state' ] = 'all' ;
}
// The menu option - on the left
2015-07-13 20:10:26 +02:00
$sep = '' ;
foreach ( $menu_options as $option => $text ) {
if ( empty ( $vars [ 'view' ])) {
$vars [ 'view' ] = $option ;
}
echo $sep ;
if ( $vars [ 'view' ] == $option ) {
echo "<span class='pagemenu-selected'>" ;
}
echo generate_link ( $text , $vars , array ( 'view' => $option ));
if ( $vars [ 'view' ] == $option ) {
echo '</span>' ;
}
$sep = ' | ' ;
2011-04-09 15:20:07 +00:00
}
unset ( $sep );
2010-05-03 16:20:32 +00:00
2016-03-15 22:16:08 +10:00
// The status option - on the right
echo '<div class="pull-right">' ;
$sep = '' ;
foreach ( $status_options as $option => $text ) {
if ( empty ( $vars [ 'state' ])) {
$vars [ 'state' ] = $option ;
}
echo $sep ;
if ( $vars [ 'state' ] == $option ) {
echo "<span class='pagemenu-selected'>" ;
}
echo generate_link ( $text , $vars , array ( 'state' => $option ));
if ( $vars [ 'state' ] == $option ) {
echo '</span>' ;
}
$sep = ' | ' ;
}
unset ( $sep );
echo '</div>' ;
2010-05-03 16:20:32 +00:00
print_optionbar_end ();
2016-03-15 22:16:08 +10:00
$sql_param = array ();
if ( isset ( $vars [ 'state' ])) {
if ( $vars [ 'state' ] == 'ok' ) {
2016-03-29 17:11:21 +10:00
$state = '0' ;
2016-08-18 20:28:22 -05:00
} elseif ( $vars [ 'state' ] == 'critical' ) {
2016-03-29 17:11:21 +10:00
$state = '2' ;
2016-08-18 20:28:22 -05:00
} elseif ( $vars [ 'state' ] == 'warning' ) {
2016-03-29 17:11:21 +10:00
$state = '1' ;
2016-03-15 22:16:08 +10:00
}
}
if ( isset ( $state )) {
$where .= " AND service_status= ? AND service_disabled='0' AND `service_ignore`='0'" ;
$sql_param [] = $state ;
}
?>
2016-03-22 07:35:39 +10:00
<div class="row col-sm-12"><span id="message"></span></div>
<table class="table table-hover table-condensed table-striped">
<tr>
<th>Device</th>
<th>Service</th>
<th>Changed</th>
<th>Message</th>
<th>Description</th>
<th> </th>
</tr>
2016-03-15 22:16:08 +10:00
<?php
2015-07-13 20:10:26 +02:00
if ($_SESSION['userlevel'] >= '5') {
$host_sql = 'SELECT * FROM devices AS D, services AS S WHERE D.device_id = S.device_id GROUP BY D.hostname ORDER BY D.hostname';
$host_par = array();
2016-08-18 20:28:22 -05:00
} else {
2015-07-13 20:10:26 +02:00
$host_sql = 'SELECT * FROM devices AS D, services AS S, devices_perms AS P WHERE D.device_id = S.device_id AND D.device_id = P.device_id AND P.user_id = ? GROUP BY D.hostname ORDER BY D.hostname';
$host_par = array($_SESSION['user_id']);
}
$shift = 1;
foreach (dbFetchRows($host_sql, $host_par) as $device) {
$device_id = $device['device_id'];
2012-04-26 13:05:52 +00:00
$device_hostname = $device['hostname'];
2016-08-18 20:28:22 -05:00
$devlink = generate_device_link($device, null, array('tab' => 'services'));
2015-06-02 13:55:53 +02:00
if ($shift == 1) {
array_unshift($sql_param, $device_id);
$shift = 0;
2016-08-18 20:28:22 -05:00
} else {
2015-07-13 20:10:26 +02:00
$sql_param[0] = $device_id;
2007-04-03 14:10:23 +00:00
}
2015-07-13 20:10:26 +02:00
foreach (dbFetchRows("SELECT * FROM `services` WHERE `device_id` = ? $where", $sql_param) as $service) {
2016-03-29 17:11:21 +10:00
if ($service['service_status'] == '2') {
2016-03-15 22:16:08 +10:00
$status = "<span class='red'><b>".$service['service_type']."</b></span>";
2016-08-18 20:28:22 -05:00
} elseif ($service['service_status'] == '0') {
2016-03-15 22:16:08 +10:00
$status = "<span class='green'><b>".$service['service_type']."</b></span>";
2016-08-18 20:28:22 -05:00
} else {
2016-03-15 22:16:08 +10:00
$status = "<span class='grey'><b>".$service['service_type']."</b></span>";
}
?>
2016-05-02 18:43:06 +00:00
<tr id="row_<?php echo $service['service_id']?>">
<td><?php echo $devlink?></td>
<td><?php echo $status?></td>
<td><?php echo formatUptime(time() - $service['service_changed'])?></td>
2016-11-01 11:20:12 -06:00
<td><span class='box-desc'><?php echo nl2br(display($service['service_message']))?></span></td>
<td><span class='box-desc'><?php echo nl2br(display($service['service_desc']))?></span></td>
2016-03-22 07:35:39 +10:00
<td>
2016-09-22 10:44:17 -04:00
<button type='button' class='btn btn-primary btn-sm' aria-label='Edit' data-toggle='modal' data-target='#create-service' data-service_id='<?php echo $service['service_id']?>' name='edit-service'><i class='fa fa-pencil' aria-hidden='true'></i></button>
<button type='button' class='btn btn-danger btn-sm' aria-label='Delete' data-toggle='modal' data-target='#confirm-delete' data-service_id='<?php echo $service['service_id']?>' name='delete-service'><i class='fa fa-trash' aria-hidden='true'></i></button>
2016-03-22 07:35:39 +10:00
</td>
</tr>
2016-03-15 22:16:08 +10:00
<?php
2015-07-13 20:10:26 +02:00
}//end foreach
unset($samehost);
}//end foreach
2016-03-15 22:16:08 +10:00
?>
2016-03-22 07:35:39 +10:00
</table>