1 <?php
defined('SYSPATH') OR die('No direct access allowed.');
4 * Handle comments for hosts and services
6 class Scheduling_queue_Model
extends Model
{
12 * Sets how many objects show_schduling_queue should return
17 public function set_range( $limit, $offset ) {
18 $this->limit
= $limit;
19 $this->offset
= $offset;
23 * Fetch scheduled events
25 * @param $service_filter string = null
26 * @param $host_filter string = null
27 * @return Database result object or false if none if $count is false or unset, otherwise the number of result rows
29 public function show_scheduling_queue($service_filter = null, $host_filter = null)
32 $ls = Livestatus
::instance();
34 $max_objects = $this->limit +
$this->offset
; /* At most object needed to be fetched */
36 $service_options = array(
42 'check_type', // 0 == active, 1 == passive
43 'active_checks_enabled'
45 'filter' => array( 'should_be_scheduled' => 1 ),
46 'limit' => $max_objects,
47 'order' => array( 'next_check' => 'asc' )
51 $service_options['filter']['description'] = array("~~" => ".*$service_filter.*");
54 $service_options['filter']['host_name'] = array("~~" => ".*$host_filter.*");
56 $service_checks = $ls->getServices($service_options);
58 $host_options = $service_options;
60 $host_options['columns'] = array(
64 'check_type', // 0 == active, 1 == passive
65 'active_checks_enabled'
67 $host_options['filter'] = array(
68 'filter' => array( 'should_be_scheduled' => 1 )
72 $host_options['filter']['host_name'] = array("~~" => ".*$host_filter.*");
74 $host_checks = $ls->getHosts($host_options);
75 if(!$host_checks && !$service_checks) {
83 for( $i=0; $i<$this->limit +
$this->offset
; $i++
) {
84 $host = isset($host_checks[$host_ptr]) ?
$host_checks[$host_ptr] : false;
85 $service = isset($service_checks[$service_ptr]) ?
$service_checks[$service_ptr] : false;
88 if( $host === false && $service === false ) break;
90 if( $host === false ||
($service !== false && $host['next_check'] > $service['next_check'] )) {
92 if( $i >= $this->offset
) {
93 $output[] = (object)$service;
98 if( $i >= $this->offset
)
99 $output[] = (object)$host;