Reports_Model Class Reference

Reports model Responsible for fetching data for avail and SLA reports. More...

Public Member Functions

 __construct (Report_options $options, $db_table='report_data')
 Constructor.
 _self_check ()
 Check that we have a valid database installed and usable.
 register_db_time ($t)
 Adjust report start and end time so that the provided timestamp is included.
 get_uptime ()
 Calculate uptime between two timestamps for host/service.
 get_last_shutdown ()
 Get latest (useful) process shutdown event.
 convert_state_table ($state, $conv)
 Calculate the time spent in different states as total and percentage.
 st_update ($end_time)
 Update the raw uptime array.
 check_st_sub_discrepancies ($row=false)
 Strictly for debugging purposes.
 st_parse_row ($row=false)
 Take a database row object, and parse it.
 st_worst ()
 Calculate worst state for either hosts or services.
 st_best ()
 Calculate best state for either hosts or services.
 calculate_object_state ($state=false)
 Calculate the object state, based on the chosen state calculator.
 st_init ()
 Initialize the the state machine for this report.
 uptime_query ()
 Get log details for host/service.
 get_initial_dt_depths ($type= 'host', $names=array())
 Fetch information about SCHEDULED_DOWNTIME status for multiple objects.
 get_initial_dt_depth ()
 Fetch information about SCHEDULED_DOWNTIME status.
 get_initial_states ($type= 'host', $names=array())
 Get inital states of a set of objects.
 get_initial_state ()
 Get initital state from db.
 test_summary_query ($query)
 Given a query, generate debug information.
 test_summary_queries ()
 Used by summary model to generate debug information for queries.
 top_alert_producers ()
 Get alert summary for "top (hard) alert producers".
 alert_totals ()
 Get alert totals.
 recent_alerts ()
 Find and return the latest $this->options['summary_items'] alert producers according to the search criteria.
 histogram ($slots=false)
 Fetch alert history for histogram report.
 histogram_data ($query, $date_str='j', $slots=false, $newstatesonly=false)
 Populate slots for histogram.

Static Public Member Functions

static event_type_to_string ($event_type, $object_type=null)
 Retrieve a user-friendly representation for nagios codes.
static add_event_comment ($timestamp, $event_type, $host_name, $service, $comment, $username)
 Add a new comment to the event pointed to by the timestamp/event_type/host_name/service.
static print_db_lines ($prefix, $table= 'report_data', $test, $db_start_time, $db_end_time)
 Fetch and print the SQL insert statements we need to run to duplicate the data-set the report used to generate its data.

Data Fields

const STATE_PENDING = -1
 Magical state for unchecked objects.
const STATE_OK = 0
 "Everything is fine"-state
const HOST_UP = 0
 Host is up.
const HOST_DOWN = 1
 Host is down.
const HOST_UNREACHABLE = 2
 Host is unreachable.
const HOST_PENDING = -1
 Magical state for unchecked hosts.
const HOST_EXCLUDED = -2
 Magical state when a host event falls outside of the specified timeperiod.
const HOST_ALL = 7
 Bitmask for any non-magical host state.
const SERVICE_OK = 0
 Service is up.
const SERVICE_WARNING = 1
 Service is warning.
const SERVICE_CRITICAL = 2
 Service is critical.
const SERVICE_UNKNOWN = 3
 Service is unknown.
const SERVICE_PENDING = -1
 Magical state for unchecked services.
const SERVICE_EXCLUDED = -2
 Magical state when a service event falls outside of the specified timeperiod.
const SERVICE_ALL = 15
 Bitmask for any non-magical service state.
const PROCESS_SHUTDOWN = 103
 Nagios code for when it is shut down.
const PROCESS_RESTART = 102
 Nagios code for when it is restarted - not normally added to report_data, check for stop and start instead.
const PROCESS_START = 100
 Nagios code for when it is started.
const SERVICECHECK = 701
 Nagios code for a service check.
const HOSTCHECK = 801
 Nagios code for a host check.
const DOWNTIME_START = 1103
 Nagios code for downtime start.
const DOWNTIME_STOP = 1104
 Nagios code for downtime stop, either because it ended or because it was deleted.
const PERC_DEC = 3
 Nr of decimals in returned percentage.
const DEBUG = true
 Debug bool - can't see this is ever false.
 $db_start_time = 0
 earliest database timestamp we look at
 $db_end_time = 0
 latest database timestamp we look at
 $debug = array()
 Array of the debug information that we print during unit tests.
 $completion_time = 0
 The time it took to generate the report.
 $st_raw = array()
 Mapping between the raw states and the time spent there.
 $st_log = false
 The log array.
 $st_prev_row = array()
 The last db row, so we can get duration.
 $st_running = 0
 Is nagios running?
 $st_last_dt_init = 1
 set to FALSE on nagios restart, and a timestamp on first DT start after restart, so we can exclude duplicate downtime_start
 $st_dt_depth = 0
 The downtime depth.
 $st_is_service = false
 Whether this is a service.
 $st_inactive = 0
 Time we have no information about.
 $st_text = array()
 Mapping between state integers and state text.
 $st_sub = array()
 Map of sub report [state => [downtime_status => [indexes]]].
 $st_sub_discrepancies = 0
 Sub report appears to be weirded out.
 $initial_dt_depth = false
 The initial downtime depth.
 $db_table = 'report_data'
 Report table name.
const db_table = 'report_data'
 Report table name, FIXME: again, 4 teh lulz.
 $sub_reports = array()
 An array of sub-reports for this report.
 $last_shutdown = false
 Last nagios shutdown event- 0 if we started it again.
 $states = array()
 The final array of report states.

Static Public Attributes

static $host_states
 A map of state ID => state name for hosts.
static $service_states
 A map of state ID => state name for services.

Protected Attributes

 $options = false
 The provided options.
 $timeperiod
 The timeperiod associated with this report.

Detailed Description

Reports model Responsible for fetching data for avail and SLA reports.

This class must be instantiated to work properly.

## State interaction in subreports Given two objects, assuming only two states per object type, would interact such that the non-OK state overrules the OK state completely as such: host UP | DOWN | scheduled | unscheduled | scheduled | unscheduled ------------+------------+-------------+------------+------------- scheduled | sched up | unsched up | sched down | unsched down UP ------------+------------+-------------+------------+------------- unscheduled| unsched up | unsched up | sched down | unsched down host ----------------+------------+-------------+------------+------------- scheduled | sched down | sched down | sched down | unsched down DOWN------------+------------+-------------+------------+------------- unscheduled|unsched down| unsched down|unsched down| unsched down

When two sub-objects have different non-OK states, the outcome depends on whether scheduleddowntimeasuptime is used or not. If the option is used, then the service with the worst non-scheduled state is used. If the option is not used, the worst state is used, prioritizing any non-scheduled state.

This applies to non-"cluster mode" reports. If you're in cluster mode, this applies backwards exactly.


Constructor & Destructor Documentation

Reports_Model::__construct ( Report_options $  options,
db_table = 'report_data' 
)

Constructor.

Parameters:
$options An instance of Report_options
$db_table Database name

The real state of the object

Will be overwritten at report start, if report object exist


Member Function Documentation

Reports_Model::alert_totals (  ) 

Get alert totals.

This is identical to the toplist in many respects, but the result array is different.

Returns:
Array of counts divided by object types and states
Reports_Model::calculate_object_state ( state = false  ) 

Calculate the object state, based on the chosen state calculator.

If there is sub reports, the argument will be ignored. Otherwise, use either the argument or the object's real state, according to magical properties inherent in the numbers themselves.

Parameters:
$state a nagios state, or not
Reports_Model::check_st_sub_discrepancies ( row = false  ) 

Strictly for debugging purposes.

Enable this if you get weird values from the reporting tool for some reason

Reports_Model::convert_state_table ( state,
conv 
)

Calculate the time spent in different states as total and percentage.

Parameters:
$state State times. Has the format:
array("X:Y:Z" => seconds, ...). Where X, Y and Z are numeric states and rhs argument is the number of seconds in that state
$conv State translation table. E.g. for hostgroups:
array(0 => 'UP', '1' => 'DOWN', '2' => 'UNREACHABLE', '-1' => 'PENDING')
Returns:
array A huge array with all possible states and time spent in that state. States called PERCENT_* contains percentages rather than a number of seconds.
static Reports_Model::event_type_to_string ( event_type,
object_type = null 
) [static]

Retrieve a user-friendly representation for nagios codes.

Parameters:
$event_type 
$object_type = null (host or service)
Returns:
string
Exceptions:
InvalidArgumentException 
Reports_Model::get_initial_dt_depth (  ) 

Fetch information about SCHEDULED_DOWNTIME status.

Returns:
Depth of initial downtime.
Reports_Model::get_initial_dt_depths ( type = 'host',
names = array() 
)

Fetch information about SCHEDULED_DOWNTIME status for multiple objects.

Returns:
array of Depth of initial downtime.
Reports_Model::get_initial_state (  ) 

Get initital state from db.

This is usually required when selecting states for a host/service when the selected start time doesn't exactly match a record in db. Note that initial state can only be obtained for a single object.

Returns:
FALSE on error. Record from database on success.
Reports_Model::get_initial_states ( type = 'host',
names = array() 
)

Get inital states of a set of objects.

Returns:
array of initial states
Reports_Model::get_last_shutdown (  ) 

Get latest (useful) process shutdown event.

Returns:
Timestamp when of last shutdown event prior to $start_time
Reports_Model::get_uptime (  ) 

Calculate uptime between two timestamps for host/service.

Returns:
array or false on error
Reports_Model::histogram ( slots = false  ) 

Fetch alert history for histogram report.

Parameters:
$slots array with slots to fill with data
Returns:
array with keys: min, max, avg, data
Reports_Model::histogram_data ( query,
date_str = 'j',
slots = false,
newstatesonly = false 
)

Populate slots for histogram.

Parameters:
$query sql
$date_str string for use in PHP date()
$slots array with slots to fill with data
$newstatesonly bool Used to decide if to ignore repated events or not
Returns:
array Populated slots array with found data
Reports_Model::register_db_time ( t  ) 

Adjust report start and end time so that the provided timestamp is included.

Parameters:
$t A timestamp
Reports_Model::st_parse_row ( row = false  ) 

Take a database row object, and parse it.

Parameters:
$row Database row
Reports_Model::st_update ( end_time  ) 

Update the raw uptime array.

Parameters:
$end_time When the event ends - start time is taken from st_prev_row
Reports_Model::test_summary_query ( query  ) 

Given a query, generate debug information.

While it's made for testing summary queries, it's completely generic

Reports_Model::top_alert_producers (  ) 

Get alert summary for "top (hard) alert producers".

Returns:
Array in the form { rank => array() }
Reports_Model::uptime_query (  ) 

Get log details for host/service.

Returns:
PDO result object on success. FALSE on error.

Field Documentation

Reports_Model::$host_states [static]
Initial value:
 array(
                self::HOST_UP => 'up',
                self::HOST_DOWN => 'down',
                self::HOST_UNREACHABLE => 'unreachable',
                self::HOST_PENDING => 'pending',
                self::HOST_EXCLUDED => 'excluded')

A map of state ID => state name for hosts.

FIXME: one of a gazillion

Reports_Model::$initial_dt_depth = false

The initial downtime depth.

NOTE: this is scary, what if there's a dozen 365 day long downtimes active at once or bugs caused us to forget to end downtimes?

Reports_Model::$service_states [static]
Initial value:
 array(
                self::SERVICE_OK => 'ok',
                self::SERVICE_WARNING => 'warning',
                self::SERVICE_CRITICAL => 'critical',
                self::SERVICE_UNKNOWN => 'unknown',
                self::SERVICE_PENDING => 'pending',
                self::SERVICE_EXCLUDED => 'excluded')

A map of state ID => state name for services.

FIXME: one of a gazillion

Magical state for unchecked hosts.

In other parts of ninja, 6 is used for this

Magical state for unchecked services.

In other parts of ninja, 6 is used for this

Magical state for unchecked objects.

In other parts of ninja, 6 is used for this


The documentation for this class was generated from the following file:
 All Data Structures Functions Variables

Generated on 22 Nov 2012 for ninja by  doxygen 1.6.1