2 #Copyright (C) 2009 Gabes Jean, naparuba@gmail.com
4 #This file is part of Shinken.
6 #Shinken is free software: you can redistribute it and/or modify
7 #it under the terms of the GNU Affero General Public License as published by
8 #the Free Software Foundation, either version 3 of the License, or
9 #(at your option) any later version.
11 #Shinken is distributed in the hope that it will be useful,
12 #but WITHOUT ANY WARRANTY; without even the implied warranty of
13 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 #GNU Affero General Public License for more details.
16 #You should have received a copy of the GNU Affero General Public License
17 #along with Shinken. If not, see <http://www.gnu.org/licenses/>.
20 #File for a Livestatus class which can be used by the status-dat-broker
29 import simplejson
as json
34 import pysqlite2
.dbapi2
as sqlite3
36 import sqlite
as sqlite3
38 from shinken
.bin
import VERSION
39 from shinken
.objects
import Service
40 from shinken
.external_command
import ExternalCommand
41 from shinken
.macroresolver
import MacroResolver
42 from shinken
.util
import from_bool_to_int
,from_list_to_split
,from_float_to_int
,to_int
,to_split
,get_customs_keys
,get_customs_values
45 LOGCLASS_INFO
= 0 # all messages not in any other class
46 LOGCLASS_ALERT
= 1 # alerts: the change service/host state
47 LOGCLASS_PROGRAM
= 2 # important programm events (restart, ...)
48 LOGCLASS_NOTIFICATION
= 3 # host/service notifications
49 LOGCLASS_PASSIVECHECK
= 4 # passive checks
50 LOGCLASS_COMMAND
= 5 # external commands
51 LOGCLASS_STATE
= 6 # initial or current states
52 LOGCLASS_INVALID
= -1 # never stored
60 def get_livestatus_full_name(prop
, ref
, request
):
61 """Returns a host's or a service's name in livestatus notation.
63 This function takes either a host or service object as it's first argument.
64 The third argument is a livestatus request object. The important information
65 in the request object is the separators array. It contains the character
66 that separates host_name and service_description which is used for services'
67 names with the csv output format. If the output format is json, services' names
68 are lists composed of host_name and service_description.
70 cls_name
= prop
.__class
__.my_type
71 if request
.response
.outputformat
== 'csv':
72 if cls_name
== 'service':
73 return prop
.host_name
+ request
.response
.separators
[3] + prop
.service_description
76 elif request
.response
.outputformat
== 'json' or request
.response
.outputformat
== 'python':
77 if cls_name
== 'service':
78 return [prop
.host_name
, prop
.service_description
]
84 def from_svc_hst_distinct_lists(dct
):
85 """Transform a dict with keys hosts and services to a list."""
87 for h
in dct
['hosts']:
89 for s
in dct
['services']:
94 def worst_host_state(state_1
, state_2
):
95 """Return the worst of two host states."""
96 #lambda x: reduce(lambda g, c: c if g == 0 else (c if c == 1 else g), (y.state_id for y in x), 0),
104 def worst_service_state(state_1
, state_2
):
105 """Return the worst of two service states."""
106 #reduce(lambda g, c: c if g == 0 else (c if c == 2 else (c if (c == 3 and g != 2) else g)), (z.state_id for y in x for z in y.services if z.state_type_id == 1), 0),
111 if state_1
== 3 and state_2
!= 2:
116 def find_pnp_perfdata_xml(name
, ref
, request
):
117 """Check if a pnp xml file exists for a given host or service name."""
118 if request
.pnp_path_readable
:
121 if os
.access(request
.pnp_path
+ '/' + name
+ '.xml', os
.R_OK
):
125 if os
.access(request
.pnp_path
+ '/' + name
+ '/_HOST_.xml', os
.R_OK
):
127 # If in doubt, there is no pnp file
132 def __init__(self
, source
, impacts
):
134 self
.impacts
= impacts
139 """A class which represents a line from the logfile
142 fill -- Attach host and/or service objects to a Logline object
146 def __init__(self
, cursor
, row
):
147 for idx
, col
in enumerate(cursor
.description
):
148 setattr(self
, col
[0], row
[idx
])
151 def fill(self
, hosts
, services
, hostname_lookup_table
, servicename_lookup_table
, columns
):
152 """Attach host and/or service objects to a Logline object
154 Lines describing host or service events only contain host_name
155 and/or service_description. This method finds the corresponding
156 objects and adds them to the line as attributes log_host
160 if self
.logobject
== LOGOBJECT_HOST
:
161 if self
.host_name
in hostname_lookup_table
:
162 setattr(self
, 'log_host', hosts
[hostname_lookup_table
[self
.host_name
]])
163 elif self
.logobject
== LOGOBJECT_SERVICE
:
164 if self
.host_name
in hostname_lookup_table
:
165 setattr(self
, 'log_host', hosts
[hostname_lookup_table
[self
.host_name
]])
166 if self
.host_name
+ self
.service_description
in servicename_lookup_table
:
167 setattr(self
, 'log_service', services
[servicename_lookup_table
[self
.host_name
+ self
.service_description
]])
172 class MyLifoQueue(Queue
.Queue
):
173 """A class that implements a Fifo.
175 Python versions < 2.5 do not have the Queue.LifoQueue class.
176 MyLifoQueue overwrites methods of the Queue.Queue class and
177 then behaves like Queue.LifoQueue.
181 def _init(self
, maxsize
):
182 self
.maxsize
= maxsize
186 def _qsize(self
, len=len):
187 return len(self
.queue
)
190 def _put(self
, item
):
191 self
.queue
.append(item
)
195 return self
.queue
.pop()
199 class LiveStatusStack
:
200 """A Lifo queue for filter functions.
202 This class inherits either from MyLifoQueue or Queue.LifoQueue
203 whatever is available with the current python version.
206 and_elements -- takes a certain number (given as argument)
207 of filters from the stack, creates a new filter and puts
208 this filter on the stack. If these filters are lambda functions,
209 the new filter is a boolean and of the underlying filters.
210 If the filters are sql where-conditions, they are also concatenated
211 with and to form a new string containing a more complex where-condition.
213 or_elements --- the same, only that the single filters are
214 combined with a logical or.
218 def __init__(self
, *args
, **kw
):
220 self
.__class
__.__bases
__[0].__init
__(self
, *args
, **kw
)
223 def and_elements(self
, num
):
224 """Take num filters from the stack, and them and put the result back"""
228 filters
.append(self
.get())
229 # Take from the stack:
230 # Make a combined anded function
231 # Put it on the stack
232 if self
.type == 'sql':
233 # Must be a SQL filter
234 and_clause
= '(' + (' AND ').join([ x()[0] for x
in filters
]) + ')'
235 and_values
= reduce(lambda x
, y
: x
+y
, [ x()[1] for x
in filters
])
236 and_filter
= lambda : [and_clause
, and_values
]
238 # List of functions taking parameter ref
242 for filter in myfilters
:
252 def or_elements(self
, num
):
253 """Take num filters from the stack, or them and put the result back"""
257 filters
.append(self
.get())
258 if self
.type == 'sql':
259 or_clause
= '(' + (' OR ').join([ x()[0] for x
in filters
]) + ')'
260 or_values
= reduce(lambda x
, y
: x
+y
, [ x()[1] for x
in filters
])
261 or_filter
= lambda : [or_clause
, or_values
]
266 for filter in myfilters
:
277 """Return the top element from the stack or a filter which is always true"""
278 if self
.qsize() == 0:
279 if self
.type == 'sql':
280 return lambda : ["1 = ?", [1]]
282 return lambda x
: True
289 LiveStatusStack
.__bases
__ = (Queue
.LifoQueue
,)
290 except AttributeError:
291 # Ptyhon 2.4 and 2.5 do not have it.
292 # Use our own implementation.
293 LiveStatusStack
.__bases
__ = (MyLifoQueue
,)
297 """A class that represents the status of all objects in the broker
300 # description (optional): no need to explain this
301 # prop (optional): the property of the object. If this is missing, the key is the property
302 # type (mandatory): int, float, string, list
303 # depythonize : use it if the property needs to be post-processed.
304 # fulldepythonize : the same, but the postprocessor takes three arguments. property, object, request
305 # delegate : get the property of a different object
306 # as : use it together with delegate, if the property of the other object has another name
309 'accept_passive_checks' : {
310 'depythonize' : from_bool_to_int
,
311 'description' : 'Wether passive host checks are accepted (0/1)',
312 'prop' : 'passive_checks_enabled',
316 'depythonize' : from_bool_to_int
,
317 'description' : 'Wether the current host problem has been acknowledged (0/1)',
318 'prop' : 'problem_has_been_acknowledged',
321 'acknowledgement_type' : {
322 'description' : 'Type of acknowledgement (0: none, 1: normal, 2: stick)',
326 'description' : 'An optional URL to custom actions or information about this host',
329 'action_url_expanded' : {
330 'fulldepythonize' : lambda p
, e
, r
: MacroResolver().resolve_simple_macros_in_string(p
, e
.get_data_for_checks()),
331 'description' : 'The same as action_url, but with the most important macros expanded',
332 'prop' : 'action_url',
335 'active_checks_enabled' : {
336 'depythonize' : from_bool_to_int
,
337 'description' : 'Wether active checks are enabled for the host (0/1)',
341 'description' : 'IP address',
345 'description' : 'An alias name for the host',
349 'depythonize' : 'call',
350 'description' : 'Nagios command for active host check of this host',
353 'check_freshness' : {
354 'depythonize' : from_bool_to_int
,
355 'description' : 'Wether freshness checks are activated (0/1)',
360 'description' : 'Number of basic interval lengths between two scheduled checks of the host',
364 'description' : 'The current check option, forced, normal, freshness... (0-2)',
368 'depythonize' : 'get_name',
369 'description' : 'Time period in which this host will be checked. If empty then the host will always be checked.',
374 'description' : 'Type of check (0: active, 1: passive)',
378 'depythonize' : from_bool_to_int
,
379 'description' : 'Wether checks of the host are enabled (0/1)',
380 'prop' : 'active_checks_enabled',
384 'description' : 'A list of all direct childs of the host',
389 'depythonize' : 'id',
390 'description' : 'A list of the ids of all comments of this host',
394 'depythonize' : 'contact_name',
395 'description' : 'A list of all contacts of this host, either direct or via a contact group',
398 'current_attempt' : {
401 'description' : 'Number of the current check attempts',
405 'current_notification_number' : {
407 'description' : 'Number of the current notification',
410 'custom_variable_names' : {
412 'description' : 'A list of the names of all custom variables',
414 'depythonize' : get_customs_keys
,
416 'custom_variable_values' : {
418 'description' : 'A list of the values of the custom variables',
420 'depythonize' : get_customs_values
,
423 'description' : 'Optional display name of the host - not used by Nagios\' web interface',
427 'description' : 'A list of the ids of all scheduled downtimes of this host',
430 'event_handler_enabled' : {
431 'depythonize' : from_bool_to_int
,
432 'description' : 'Wether event handling is enabled (0/1)',
437 'description' : 'Time the host check needed for execution',
440 'first_notification_delay' : {
442 'description' : 'Delay before the first notification',
445 'flap_detection_enabled' : {
446 'depythonize' : from_bool_to_int
,
447 'description' : 'Wether flap detection is enabled (0/1)',
450 'got_business_rule' : {
451 'depythonize' : from_bool_to_int
,
452 'description' : 'Wether the host state is an business rule based host or not (0/1)',
457 'depythonize' : to_split
,
458 'description' : 'A list of all host groups this host is in',
459 'prop' : 'hostgroups',
463 'description' : 'The effective hard state of the host (eliminates a problem in hard_state)',
466 'has_been_checked' : {
467 'depythonize' : from_bool_to_int
,
468 'description' : 'Wether the host has already been checked (0/1)',
471 'high_flap_threshold' : {
473 'description' : 'High threshold of flap detection',
477 'description' : 'The name of an image file to be used in the web pages',
481 'description' : 'Alternative text for the icon_image',
484 'icon_image_expanded' : {
485 'description' : 'The same as icon_image, but with the most important macros expanded',
488 'in_check_period' : {
489 'fulldepythonize' : lambda p
, e
, r
: from_bool_to_int((p
== None and [False] or [p
.is_time_valid(r
.tic
)])[0]),
490 'description' : 'Wether this host is currently in its check period (0/1)',
491 'prop' : 'check_period',
494 'in_notification_period' : {
495 'fulldepythonize' : lambda p
, e
, r
: from_bool_to_int((p
== None and [False] or [p
.is_time_valid(r
.tic
)])[0]),
496 'description' : 'Wether this host is currently in its notification period (0/1)',
497 'prop' : 'notification_period',
501 'description' : 'Initial host state',
505 'default' : 0, # value in scheduler is not real-time
506 'description' : 'is there a host check currently running... (0/1)',
507 #'prop' : 'in_checking',
511 'depythonize' : from_bool_to_int
,
512 'description' : 'Wether the host state is flapping (0/1)',
516 'depythonize' : from_bool_to_int
,
517 'description' : 'Wether the host state is an impact or not (0/1)',
521 'depythonize' : from_bool_to_int
,
522 'description' : 'Wether the host state is a problem or not (0/1)',
527 'depythonize' : from_float_to_int
,
528 'description' : 'Time of the last check (Unix timestamp)',
532 'last_hard_state' : {
533 'description' : 'Last hard state',
536 'last_hard_state_change' : {
537 'description' : 'Time of the last hard state change (Unix timestamp)',
540 'last_notification' : {
542 'depythonize' : to_int
,
543 'description' : 'Time of the last notification (Unix timestamp)',
547 'description' : 'State before last state change',
550 'last_state_change' : {
552 'depythonize' : from_float_to_int
,
553 'description' : 'Time of the last state change - soft or hard (Unix timestamp)',
558 'description' : 'Time difference between scheduled check time and actual check time',
561 'long_plugin_output' : {
562 'description' : 'Complete output from check plugin',
563 'prop' : 'long_output',
566 'low_flap_threshold' : {
567 'description' : 'Low threshold of flap detection',
570 'max_check_attempts' : {
571 'description' : 'Max check attempts for active host checks',
575 'description' : 'Host name',
576 'prop' : 'host_name',
581 'depythonize' : from_float_to_int
,
582 'description' : 'Scheduled time for the next check (Unix timestamp)',
586 'next_notification' : {
588 'description' : 'Time of the next notification (Unix timestamp)',
592 'description' : 'Optional notes for this host',
596 'description' : 'The same as notes, but with the most important macros expanded',
600 'description' : 'An optional URL with further information about the host',
603 'notes_url_expanded' : {
604 'fulldepythonize' : lambda p
, e
, r
: MacroResolver().resolve_simple_macros_in_string(p
, e
.get_data_for_checks()),
605 'description' : 'Same es notes_url, but with the most important macros expanded',
606 'prop' : 'notes_url',
609 'notification_interval' : {
611 'description' : 'Interval of periodic notification or 0 if its off',
614 'notification_period' : {
615 'depythonize' : 'get_name',
616 'description' : 'Time period in which problems of this host will be notified. If empty then notification will be always',
619 'notifications_enabled' : {
620 'depythonize' : from_bool_to_int
,
621 'description' : 'Wether notifications of the host are enabled (0/1)',
625 'depythonize' : lambda x
: len(x
),
626 'description' : 'The total number of services of the host',
630 'num_services_crit' : {
631 'depythonize' : lambda x
: len([y
for y
in x
if y
.state_id
== 2]),
632 'description' : 'The number of the host\'s services with the soft state CRIT',
636 'num_services_hard_crit' : {
637 'depythonize' : lambda x
: len([y
for y
in x
if y
.state_id
== 2 and y
.state_type_id
== 1]),
638 'description' : 'The number of the host\'s services with the hard state CRIT',
642 'num_services_hard_ok' : {
643 'depythonize' : lambda x
: len([y
for y
in x
if y
.state_id
== 0 and y
.state_type_id
== 1]),
644 'description' : 'The number of the host\'s services with the hard state OK',
648 'num_services_hard_unknown' : {
649 'depythonize' : lambda x
: len([y
for y
in x
if y
.state_id
== 3 and y
.state_type_id
== 1]),
650 'description' : 'The number of the host\'s services with the hard state UNKNOWN',
654 'num_services_hard_warn' : {
655 'depythonize' : lambda x
: len([y
for y
in x
if y
.state_id
== 2 and y
.state_type_id
== 1]),
656 'description' : 'The number of the host\'s services with the hard state WARN',
660 'num_services_ok' : {
661 'depythonize' : lambda x
: len([y
for y
in x
if y
.state_id
== 0]),
662 'description' : 'The number of the host\'s services with the soft state OK',
666 'num_services_pending' : {
667 'depythonize' : lambda x
: len([y
for y
in x
if y
.has_been_checked
== 0]),
668 'description' : 'The number of the host\'s services which have not been checked yet (pending)',
672 'num_services_unknown' : {
673 'depythonize' : lambda x
: len([y
for y
in x
if y
.state_id
== 3]),
674 'description' : 'The number of the host\'s services with the soft state UNKNOWN',
678 'num_services_warn' : {
679 'depythonize' : lambda x
: len([y
for y
in x
if y
.state_id
== 1]),
680 'description' : 'The number of the host\'s services with the soft state WARN',
684 'obsess_over_host' : {
685 'depythonize' : from_bool_to_int
,
686 'description' : 'The current obsess_over_host setting... (0/1)',
690 'description' : 'A list of all direct parents of the host',
693 'pending_flex_downtime' : {
694 'description' : 'Wether a flex downtime is pending (0/1)',
697 'percent_state_change' : {
698 'description' : 'Percent state change',
702 'description' : 'Optional performance data of the last host check',
706 'description' : 'Output of the last host check',
710 'pnpgraph_present' : {
711 'fulldepythonize' : find_pnp_perfdata_xml
,
712 'description' : 'Whether there is a PNP4Nagios graph present for this host (0/1)',
713 'prop' : 'host_name',
716 'process_performance_data' : {
717 'depythonize' : from_bool_to_int
,
718 'description' : 'Wether processing of performance data is enabled (0/1)',
719 'prop' : 'process_perf_data',
723 'description' : 'Number of basic interval lengths between checks when retrying after a soft error',
726 'scheduled_downtime_depth' : {
728 'description' : 'The number of downtimes this host is currently in',
733 'description' : 'The current state of the host (0: up, 1: down, 2: unreachable)',
739 'description' : 'Type of the current state (0: soft, 1: hard)',
740 'prop' : 'state_type_id',
743 'statusmap_image' : {
744 'description' : 'The name of in image file for the status map',
748 'description' : 'The total number of services of the host',
751 'worst_service_hard_state' : {
752 'description' : 'The worst hard state of all of the host\'s services (OK <= WARN <= UNKNOWN <= CRIT)',
755 'worst_service_state' : {
756 'description' : 'The worst soft state of all of the host\'s services (OK <= WARN <= UNKNOWN <= CRIT)',
760 'description' : '3D-Coordinates: X',
764 'description' : '3D-Coordinates: Y',
768 'description' : '3D-Coordinates: Z',
773 'description' : 'The importance we gave to this host between hte minimum 0 and the maximum 5',
776 'source_problems' : {
777 'description' : 'The name of the source problems (host or service)',
778 'prop' : 'source_problems',
780 'depythonize' : from_svc_hst_distinct_lists
,
783 'description' : 'List of what the source impact (list of hosts and services)',
786 'depythonize' : from_svc_hst_distinct_lists
,
788 'parent_dependencies' : {
789 'description' : 'List of the dependencies (logical, network or business one) of this host.',
790 'prop' : 'parent_dependencies',
792 'depythonize' : from_svc_hst_distinct_lists
,
794 'child_dependencies' : {
795 'description' : 'List of the host/service that depend on this host (logical, network or business one).',
796 'prop' : 'child_dependencies',
798 'depythonize' : from_svc_hst_distinct_lists
,
804 'accept_passive_checks' : {
805 'depythonize' : from_bool_to_int
,
806 'description' : 'Wether the service accepts passive checks (0/1)',
807 'prop' : 'passive_checks_enabled',
811 'depythonize' : from_bool_to_int
,
812 'description' : 'Wether the current service problem has been acknowledged (0/1)',
813 'prop' : 'problem_has_been_acknowledged',
816 'acknowledgement_type' : {
817 'description' : 'The type of the acknownledgement (0: none, 1: normal, 2: sticky)',
821 'description' : 'An optional URL for actions or custom information about the service',
824 'action_url_expanded' : {
825 'fulldepythonize' : lambda p
, e
, r
: MacroResolver().resolve_simple_macros_in_string(p
, e
.get_data_for_checks()),
826 'description' : 'The action_url with (the most important) macros expanded',
827 'prop' : 'action_url',
830 'active_checks_enabled' : {
831 'depythonize' : from_bool_to_int
,
832 'description' : 'Wether active checks are enabled for the service (0/1)',
836 'depythonize' : 'call',
837 'description' : 'Nagios command used for active checks',
841 'description' : 'Number of basic interval lengths between two scheduled checks of the service',
845 'description' : 'The current check option, forced, normal, freshness... (0/1)',
849 'depythonize' : 'get_name',
850 'description' : 'The name of the check period of the service. It this is empty, the service is always checked.',
855 'depythonize' : to_int
,
856 'description' : 'The type of the last check (0: active, 1: passive)',
860 'depythonize' : from_bool_to_int
,
861 'description' : 'Wether active checks are enabled for the service (0/1)',
862 'prop' : 'active_checks_enabled',
867 'depythonize' : 'id',
868 'description' : 'A list of all comment ids of the service',
872 'depythonize' : 'contact_name',
873 'description' : 'A list of all contacts of the service, either direct or via a contact group',
876 'current_attempt' : {
878 'description' : 'The number of the current check attempt',
882 'current_notification_number' : {
883 'description' : 'The number of the current notification',
886 'custom_variable_names' : {
888 'description' : 'A list of the names of all custom variables of the service',
890 'depythonize' : get_customs_keys
,
892 'custom_variable_values' : {
894 'description' : 'A list of the values of all custom variable of the service',
896 'depythonize' : get_customs_values
,
899 'description' : 'Description of the service (also used as key)',
900 'prop' : 'service_description',
904 'description' : 'An optional display name (not used by Nagios standard web pages)',
908 'description' : 'A list of all downtime ids of the service',
912 'depythonize' : 'call',
913 'description' : 'Nagios command used as event handler',
916 'event_handler_enabled' : {
917 'depythonize' : from_bool_to_int
,
918 'description' : 'Wether and event handler is activated for the service (0/1)',
923 'description' : 'Time the host check needed for execution',
926 'first_notification_delay' : {
928 'description' : 'Delay before the first notification',
931 'flap_detection_enabled' : {
932 'depythonize' : from_bool_to_int
,
933 'description' : 'Wether flap detection is enabled for the service (0/1)',
936 'got_business_rule' : {
937 'depythonize' : from_bool_to_int
,
938 'description' : 'Wether the service state is an business rule based host or not (0/1)',
943 'depythonize' : to_split
,
944 'description' : 'A list of all service groups the service is in',
945 'prop' : 'servicegroups',
948 'has_been_checked' : {
949 'depythonize' : from_bool_to_int
,
950 'description' : 'Wether the service already has been checked (0/1)',
953 'high_flap_threshold' : {
954 'description' : 'High threshold of flap detection',
957 'host_accept_passive_checks' : {
958 'description' : 'Wether passive host checks are accepted (0/1)',
961 'host_acknowledged' : {
962 'depythonize' : lambda x
: from_bool_to_int(x
.problem_has_been_acknowledged
),
963 'description' : 'Wether the current host problem has been acknowledged (0/1)',
967 'host_acknowledgement_type' : {
968 'description' : 'Type of acknowledgement (0: none, 1: normal, 2: stick)',
971 'host_action_url' : {
972 'description' : 'An optional URL to custom actions or information about this host',
975 'host_action_url_expanded' : {
976 'description' : 'The same as action_url, but with the most important macros expanded',
979 'host_active_checks_enabled' : {
980 'description' : 'Wether active checks are enabled for the host (0/1)',
984 'depythonize' : lambda x
: x
.address
,
985 'description' : 'IP address',
990 'depythonize' : lambda x
: x
.alias
,
991 'description' : 'An alias name for the host',
995 'host_check_command' : {
996 'description' : 'Nagios command for active host check of this host',
999 'host_check_freshness' : {
1000 'description' : 'Wether freshness checks are activated (0/1)',
1003 'host_check_interval' : {
1004 'description' : 'Number of basic interval lengths between two scheduled checks of the host',
1007 'host_check_options' : {
1008 'description' : 'The current check option, forced, normal, freshness... (0-2)',
1011 'host_check_period' : {
1012 'description' : 'Time period in which this host will be checked. If empty then the host will always be checked.',
1015 'host_check_type' : {
1016 'description' : 'Type of check (0: active, 1: passive)',
1019 'host_checks_enabled' : {
1020 'depythonize' : lambda x
: from_bool_to_int(x
.active_checks_enabled
),
1021 'description' : 'Wether checks of the host are enabled (0/1)',
1026 'description' : 'A list of all direct childs of the host',
1031 'depythonize' : lambda h
: ([c
.id for c
in h
.comments
]),
1032 'description' : 'A list of the ids of all comments of this host',
1037 'description' : 'A list of all contacts of this host, either direct or via a contact group',
1040 'host_current_attempt' : {
1041 'description' : 'Number of the current check attempts',
1044 'host_current_notification_number' : {
1045 'description' : 'Number of the current notification',
1048 'host_custom_variable_names' : {
1049 'description' : 'A list of the names of all custom variables',
1050 'depythonize' : lambda h
: get_customs_keys(h
.customs
),
1054 'host_custom_variable_values' : {
1055 'description' : 'A list of the values of the custom variables',
1056 'depythonize' : lambda h
: get_customs_values(h
.customs
),
1060 'host_display_name' : {
1061 'description' : 'Optional display name of the host - not used by Nagios\' web interface',
1064 'host_downtimes' : {
1065 'description' : 'A list of the ids of all scheduled downtimes of this host',
1068 'host_event_handler_enabled' : {
1069 'description' : 'Wether event handling is enabled (0/1)',
1072 'host_execution_time' : {
1073 'description' : 'Time the host check needed for execution',
1076 'host_first_notification_delay' : {
1077 'description' : 'Delay before the first notification',
1080 'host_flap_detection_enabled' : {
1081 'description' : 'Wether flap detection is enabled (0/1)',
1086 'depythonize' : lambda x
: to_split(x
.hostgroups
),
1087 'description' : 'A list of all host groups this host is in',
1091 'host_hard_state' : {
1092 'description' : 'The effective hard state of the host (eliminates a problem in hard_state)',
1095 'host_has_been_checked' : {
1096 'depythonize' : lambda x
: from_bool_to_int(x
.has_been_checked
),
1097 'description' : 'Wether the host has already been checked (0/1)',
1101 'host_high_flap_threshold' : {
1102 'description' : 'High threshold of flap detection',
1105 'host_icon_image' : {
1106 'description' : 'The name of an image file to be used in the web pages',
1109 'host_icon_image_alt' : {
1110 'description' : 'Alternative text for the icon_image',
1113 'host_icon_image_expanded' : {
1114 'description' : 'The same as icon_image, but with the most important macros expanded',
1117 'host_in_check_period' : {
1118 'depythonize' : lambda h
: from_bool_to_int((h
.check_period
== None and [False] or [h
.check_period
.is_time_valid(time
.time())])[0]),
1119 'description' : 'Wether this host is currently in its check period (0/1)',
1123 'host_in_notification_period' : {
1124 'depythonize' : lambda h
: from_bool_to_int((h
.notification_period
== None and [False] or [h
.notification_period
.is_time_valid(time
.time())])[0]),
1125 'description' : 'Wether this host is currently in its notification period (0/1)',
1129 'host_initial_state' : {
1130 'description' : 'Initial host state',
1133 'host_is_executing' : {
1134 'default' : 0, # value in scheduler is not real-time
1135 'description' : 'is there a host check currently running... (0/1)',
1138 'host_is_flapping' : {
1140 'depythonize' : from_bool_to_int
,
1141 'description' : 'Wether the host state is flapping (0/1)',
1144 'host_last_check' : {
1145 'description' : 'Time of the last check (Unix timestamp)',
1148 'host_last_hard_state' : {
1149 'description' : 'Last hard state',
1152 'host_last_hard_state_change' : {
1153 'description' : 'Time of the last hard state change (Unix timestamp)',
1156 'host_last_notification' : {
1157 'description' : 'Time of the last notification (Unix timestamp)',
1160 'host_last_state' : {
1161 'description' : 'State before last state change',
1164 'host_last_state_change' : {
1165 'description' : 'Time of the last state change - soft or hard (Unix timestamp)',
1169 'description' : 'Time difference between scheduled check time and actual check time',
1172 'host_long_plugin_output' : {
1173 'description' : 'Complete output from check plugin',
1176 'host_low_flap_threshold' : {
1177 'description' : 'Low threshold of flap detection',
1180 'host_max_check_attempts' : {
1181 'description' : 'Max check attempts for active host checks',
1185 'description' : 'Host name',
1188 'host_next_check' : {
1189 'description' : 'Scheduled time for the next check (Unix timestamp)',
1192 'host_next_notification' : {
1193 'description' : 'Time of the next notification (Unix timestamp)',
1197 'description' : 'Optional notes for this host',
1200 'host_notes_expanded' : {
1201 'description' : 'The same as notes, but with the most important macros expanded',
1204 'host_notes_url' : {
1205 'description' : 'An optional URL with further information about the host',
1208 'host_notes_url_expanded' : {
1209 'description' : 'Same es notes_url, but with the most important macros expanded',
1212 'host_notification_interval' : {
1213 'description' : 'Interval of periodic notification or 0 if its off',
1216 'host_notification_period' : {
1217 'description' : 'Time period in which problems of this host will be notified. If empty then notification will be always',
1220 'host_notifications_enabled' : {
1221 'depythonize' : lambda x
: from_bool_to_int(x
.notifications_enabled
),
1222 'description' : 'Wether notifications of the host are enabled (0/1)',
1226 'host_num_services' : {
1227 'depythonize' : lambda x
: len(x
.services
),
1228 'description' : 'The total number of services of the host',
1232 'host_num_services_crit' : {
1233 'depythonize' : lambda x
: len([y
for y
in x
.services
if y
.state_id
== 2]),
1234 'description' : 'The number of the host\'s services with the soft state CRIT',
1238 'host_num_services_hard_crit' : {
1239 'depythonize' : lambda x
: len([y
for y
in x
.services
if y
.state_id
== 2 and y
.state_type_id
== 1]),
1240 'description' : 'The number of the host\'s services with the hard state CRIT',
1244 'host_num_services_hard_ok' : {
1245 'depythonize' : lambda x
: len([y
for y
in x
.services
if y
.state_id
== 0 and y
.state_type_id
== 1]),
1246 'description' : 'The number of the host\'s services with the hard state OK',
1250 'host_num_services_hard_unknown' : {
1251 'depythonize' : lambda x
: len([y
for y
in x
.services
if y
.state_id
== 3 and y
.state_type_id
== 1]),
1252 'description' : 'The number of the host\'s services with the hard state UNKNOWN',
1256 'host_num_services_hard_warn' : {
1257 'depythonize' : lambda x
: len([y
for y
in x
.services
if y
.state_id
== 2 and y
.state_type_id
== 1]),
1258 'description' : 'The number of the host\'s services with the hard state WARN',
1262 'host_num_services_ok' : {
1263 'depythonize' : lambda x
: len([y
for y
in x
.services
if y
.state_id
== 0]),
1264 'description' : 'The number of the host\'s services with the soft state OK',
1268 'host_num_services_pending' : {
1269 'depythonize' : lambda x
: len([y
for y
in x
.services
if y
.has_been_checked
== 0]),
1270 'description' : 'The number of the host\'s services which have not been checked yet (pending)',
1274 'host_num_services_unknown' : {
1275 'depythonize' : lambda x
: len([y
for y
in x
.services
if y
.state_id
== 3]),
1276 'description' : 'The number of the host\'s services with the soft state UNKNOWN',
1280 'host_num_services_warn' : {
1281 'depythonize' : lambda x
: len([y
for y
in x
.services
if y
.state_id
== 1]),
1282 'description' : 'The number of the host\'s services with the soft state WARN',
1286 'host_obsess_over_host' : {
1287 'description' : 'The current obsess_over_host setting... (0/1)',
1291 'description' : 'A list of all direct parents of the host',
1294 'host_pending_flex_downtime' : {
1295 'description' : 'Wether a flex downtime is pending (0/1)',
1298 'host_percent_state_change' : {
1299 'description' : 'Percent state change',
1302 'host_perf_data' : {
1303 'description' : 'Optional performance data of the last host check',
1306 'host_plugin_output' : {
1307 'description' : 'Output of the last host check',
1310 'host_process_performance_data' : {
1311 'description' : 'Wether processing of performance data is enabled (0/1)',
1314 'host_retry_interval' : {
1315 'description' : 'Number of basic interval lengths between checks when retrying after a soft error',
1318 'host_scheduled_downtime_depth' : {
1320 'depythonize' : lambda x
: x
.scheduled_downtime_depth
,
1321 'description' : 'The number of downtimes this host is currently in',
1327 'depythonize' : lambda x
: x
.state_id
,
1328 'description' : 'The current state of the host (0: up, 1: down, 2: unreachable)',
1332 'host_state_type' : {
1333 'description' : 'Type of the current state (0: soft, 1: hard)',
1336 'host_statusmap_image' : {
1337 'description' : 'The name of in image file for the status map',
1340 'host_total_services' : {
1341 'description' : 'The total number of services of the host',
1344 'host_worst_service_hard_state' : {
1345 'description' : 'The worst hard state of all of the host\'s services (OK <= WARN <= UNKNOWN <= CRIT)',
1348 'host_worst_service_state' : {
1349 'description' : 'The worst soft state of all of the host\'s services (OK <= WARN <= UNKNOWN <= CRIT)',
1353 'description' : '3D-Coordinates: X',
1357 'description' : '3D-Coordinates: Y',
1361 'description' : '3D-Coordinates: Z',
1365 'description' : 'The name of an image to be used as icon in the web interface',
1368 'icon_image_alt' : {
1369 'description' : 'An alternative text for the icon_image for browsers not displaying icons',
1372 'icon_image_expanded' : {
1373 'description' : 'The icon_image with (the most important) macros expanded',
1376 'in_check_period' : {
1377 'depythonize' : lambda tp
: from_bool_to_int((tp
== None and [False] or [tp
.is_time_valid(time
.time())])[0]),
1378 'description' : 'Wether the service is currently in its check period (0/1)',
1379 'prop' : 'check_period',
1382 'in_notification_period' : {
1383 'depythonize' : lambda tp
: from_bool_to_int((tp
== None and [False] or [tp
.is_time_valid(time
.time())])[0]),
1384 'description' : 'Wether the service is currently in its notification period (0/1)',
1385 'prop' : 'notification_period',
1389 'description' : 'The initial state of the service',
1393 'default' : 0, # value in scheduler is not real-time
1394 'description' : 'is there a service check currently running... (0/1)',
1398 'depythonize' : from_bool_to_int
,
1399 'description' : 'Wether the service is flapping (0/1)',
1403 'depythonize' : from_bool_to_int
,
1404 'description' : 'Wether the host state is an impact or not (0/1)',
1408 'depythonize' : from_bool_to_int
,
1409 'description' : 'Wether the host state is a problem or not (0/1)',
1413 'depythonize' : from_float_to_int
,
1414 'description' : 'The time of the last check (Unix timestamp)',
1415 'prop' : 'last_chk',
1418 'last_hard_state' : {
1419 'description' : 'The last hard state of the service',
1422 'last_hard_state_change' : {
1423 'description' : 'The time of the last hard state change (Unix timestamp)',
1426 'last_notification' : {
1427 'depythonize' : to_int
,
1428 'description' : 'The time of the last notification (Unix timestamp)',
1432 'description' : 'The last state of the service',
1435 'last_state_change' : {
1436 'depythonize' : from_float_to_int
,
1437 'description' : 'The time of the last state change (Unix timestamp)',
1441 'depythonize' : to_int
,
1442 'description' : 'Time difference between scheduled check time and actual check time',
1445 'long_plugin_output' : {
1446 'description' : 'Unabbreviated output of the last check plugin',
1447 'prop' : 'long_output',
1450 'low_flap_threshold' : {
1451 'description' : 'Low threshold of flap detection',
1454 'max_check_attempts' : {
1455 'description' : 'The maximum number of check attempts',
1459 'depythonize' : from_float_to_int
,
1460 'description' : 'The scheduled time of the next check (Unix timestamp)',
1461 'prop' : 'next_chk',
1464 'next_notification' : {
1465 'description' : 'The time of the next notification (Unix timestamp)',
1469 'description' : 'Optional notes about the service',
1472 'notes_expanded' : {
1473 'description' : 'The notes with (the most important) macros expanded',
1477 'description' : 'An optional URL for additional notes about the service',
1480 'notes_url_expanded' : {
1481 'fulldepythonize' : lambda p
, e
, r
: MacroResolver().resolve_simple_macros_in_string(p
, e
.get_data_for_checks()),
1482 'description' : 'The notes_url with (the most important) macros expanded',
1483 'prop' : 'notes_url',
1486 'notification_interval' : {
1487 'description' : 'Interval of periodic notification or 0 if its off',
1490 'notification_period' : {
1491 'depythonize' : 'get_name',
1492 'description' : 'The name of the notification period of the service. It this is empty, service problems are always notified.',
1495 'notifications_enabled' : {
1496 'depythonize' : from_bool_to_int
,
1497 'description' : 'Wether notifications are enabled for the service (0/1)',
1500 'obsess_over_service' : {
1501 'depythonize' : from_bool_to_int
,
1502 'description' : 'Wether \'obsess_over_service\' is enabled for the service (0/1)',
1505 'percent_state_change' : {
1506 'description' : 'Percent state change',
1510 'description' : 'Performance data of the last check plugin',
1514 'description' : 'Output of the last check plugin',
1518 'pnpgraph_present' : {
1519 'fulldepythonize' : find_pnp_perfdata_xml
,
1520 'description' : 'Whether there is a PNP4Nagios graph present for this service (0/1)',
1521 'prop' : 'get_dbg_name',
1524 'process_performance_data' : {
1525 'depythonize' : from_bool_to_int
,
1526 'description' : 'Wether processing of performance data is enabled for the service (0/1)',
1527 'prop' : 'process_perf_data',
1530 'retry_interval' : {
1531 'description' : 'Number of basic interval lengths between checks when retrying after a soft error',
1534 'scheduled_downtime_depth' : {
1536 'description' : 'The number of scheduled downtimes the service is currently in',
1541 'description' : 'The current state of the service (0: OK, 1: WARN, 2: CRITICAL, 3: UNKNOWN)',
1542 'prop' : 'state_id',
1547 'description' : 'The type of the current state (0: soft, 1: hard)',
1548 'prop' : 'state_type_id',
1553 'description' : 'The importance we gave to this service between hte minimum 0 and the maximum 5',
1556 'source_problems' : {
1557 'description' : 'The name of the source problems (host or service)',
1558 'prop' : 'source_problems',
1560 'depythonize' : from_svc_hst_distinct_lists
,
1563 'description' : 'List of what the source impact (list of hosts and services)',
1566 'depythonize' : from_svc_hst_distinct_lists
,
1568 'parent_dependencies' : {
1569 'description' : 'List of the dependencies (logical, network or business one) of this service.',
1570 'prop' : 'parent_dependencies',
1572 'depythonize' : from_svc_hst_distinct_lists
,
1574 'child_dependencies' : {
1575 'description' : 'List of the host/service that depend on this service (logical, network or business one).',
1576 'prop' : 'child_dependencies',
1578 'depythonize' : from_svc_hst_distinct_lists
,
1585 'description' : 'An optional URL to custom actions or information about the hostgroup',
1589 'description' : 'An alias of the hostgroup',
1593 'depythonize' : 'get_name',
1594 'description' : 'A list of all host names that are members of the hostgroup',
1598 'description' : 'Name of the hostgroup',
1599 'prop' : 'hostgroup_name',
1603 'description' : 'Optional notes to the hostgroup',
1607 'description' : 'An optional URL with further information about the hostgroup',
1611 'depythonize' : lambda x
: len(x
),
1612 'description' : 'The total number of hosts in the group',
1613 'prop' : 'get_hosts',
1616 'num_hosts_down' : {
1617 'depythonize' : lambda x
: len([y
for y
in x
if y
.state_id
== 1]),
1618 'description' : 'The number of hosts in the group that are down',
1619 'prop' : 'get_hosts',
1622 'num_hosts_pending' : {
1623 'depythonize' : lambda x
: len([y
for y
in x
if y
.has_been_checked
== 0]),
1624 'description' : 'The number of hosts in the group that are pending',
1625 'prop' : 'get_hosts',
1628 'num_hosts_unreach' : {
1629 'depythonize' : lambda x
: len([y
for y
in x
if y
.state_id
== 2]),
1630 'description' : 'The number of hosts in the group that are unreachable',
1631 'prop' : 'get_hosts',
1635 'depythonize' : lambda x
: len([y
for y
in x
if y
.state_id
== 0]),
1636 'description' : 'The number of hosts in the group that are up',
1637 'prop' : 'get_hosts',
1641 'depythonize' : lambda x
: sum((len(y
.service_ids
) for y
in x
)),
1642 'description' : 'The total number of services of hosts in this group',
1643 'prop' : 'get_hosts',
1646 'num_services_crit' : {
1647 'depythonize' : lambda x
: len([z
for y
in x
for z
in y
.services
if z
.state_id
== 2]),
1648 'description' : 'The total number of services with the state CRIT of hosts in this group',
1649 'prop' : 'get_hosts',
1652 'num_services_hard_crit' : {
1653 'depythonize' : lambda x
: len([z
for y
in x
for z
in y
.services
if z
.state_id
== 2 and z
.state_type_id
== 1]),
1654 'description' : 'The total number of services with the state CRIT of hosts in this group',
1655 'prop' : 'get_hosts',
1658 'num_services_hard_ok' : {
1659 'depythonize' : lambda x
: len([z
for y
in x
for z
in y
.services
if z
.state_id
== 0 and z
.state_type_id
== 1]),
1660 'description' : 'The total number of services with the state OK of hosts in this group',
1661 'prop' : 'get_hosts',
1664 'num_services_hard_unknown' : {
1665 'depythonize' : lambda x
: len([z
for y
in x
for z
in y
.services
if z
.state_id
== 3 and z
.state_type_id
== 1]),
1666 'description' : 'The total number of services with the state UNKNOWN of hosts in this group',
1667 'prop' : 'get_hosts',
1670 'num_services_hard_warn' : {
1671 'depythonize' : lambda x
: len([z
for y
in x
for z
in y
.services
if z
.state_id
== 2 and z
.state_type_id
== 1]),
1672 'description' : 'The total number of services with the state WARN of hosts in this group',
1673 'prop' : 'get_hosts',
1676 'num_services_ok' : {
1677 'depythonize' : lambda x
: len([z
for y
in x
for z
in y
.services
if z
.state_id
== 0]),
1678 'description' : 'The total number of services with the state OK of hosts in this group',
1679 'prop' : 'get_hosts',
1682 'num_services_pending' : {
1683 'depythonize' : lambda x
: len([z
for y
in x
for z
in y
.services
if z
.has_been_checked
== 0]),
1684 'description' : 'The total number of services with the state Pending of hosts in this group',
1685 'prop' : 'get_hosts',
1688 'num_services_unknown' : {
1689 'depythonize' : lambda x
: len([z
for y
in x
for z
in y
.services
if z
.state_id
== 3]),
1690 'description' : 'The total number of services with the state UNKNOWN of hosts in this group',
1691 'prop' : 'get_hosts',
1694 'num_services_warn' : {
1695 'depythonize' : lambda x
: len([z
for y
in x
for z
in y
.services
if z
.state_id
== 1]),
1696 'description' : 'The total number of services with the state WARN of hosts in this group',
1697 'prop' : 'get_hosts',
1700 'worst_host_state' : {
1701 'depythonize' : lambda x
: reduce(worst_host_state
, (y
.state_id
for y
in x
), 0),
1702 'description' : 'The worst state of all of the groups\' hosts (UP <= UNREACHABLE <= DOWN)',
1703 'prop' : 'get_hosts',
1706 'worst_service_hard_state' : {
1707 'depythonize' : lambda x
: reduce(worst_service_state
, (z
.state_id
for y
in x
for z
in y
.services
if z
.state_type_id
== 1), 0),
1708 'description' : 'The worst state of all services that belong to a host of this group (OK <= WARN <= UNKNOWN <= CRIT)',
1709 'prop' : 'get_hosts',
1712 'worst_service_state' : {
1713 'depythonize' : lambda x
: reduce(worst_service_state
, (z
.state_id
for y
in x
for z
in y
.services
), 0),
1714 'description' : 'The worst state of all services that belong to a host of this group (OK <= WARN <= UNKNOWN <= CRIT)',
1715 'prop' : 'get_hosts',
1722 'description' : 'An optional URL to custom notes or actions on the service group',
1726 'description' : 'An alias of the service group',
1730 'fulldepythonize' : get_livestatus_full_name
,
1731 'description' : 'A list of all members of the service group as host/service pairs ',
1735 'description' : 'The name of the service group',
1736 'prop' : 'servicegroup_name',
1740 'description' : 'Optional additional notes about the service group',
1744 'description' : 'An optional URL to further notes on the service group',
1749 'depythonize' : lambda x
: len(x
),
1750 'description' : 'The total number of services in the group',
1751 'prop' : 'get_services',
1754 'num_services_crit' : {
1756 'depythonize' : lambda x
: len([y
for y
in x
if y
.state_id
== 2]),
1757 'description' : 'The number of services in the group that are CRIT',
1758 'prop' : 'get_services',
1761 'num_services_hard_crit' : {
1763 'depythonize' : lambda x
: len([y
for y
in x
if y
.state_id
== 2 and y
.state_type_id
== 1]),
1764 'description' : 'The number of services in the group that are CRIT',
1765 'prop' : 'get_services',
1768 'num_services_hard_ok' : {
1770 'depythonize' : lambda x
: len([y
for y
in x
if y
.state_id
== 0 and y
.state_type_id
== 1]),
1771 'description' : 'The number of services in the group that are OK',
1772 'prop' : 'get_services',
1775 'num_services_hard_unknown' : {
1777 'depythonize' : lambda x
: len([y
for y
in x
if y
.state_id
== 3 and y
.state_type_id
== 1]),
1778 'description' : 'The number of services in the group that are UNKNOWN',
1779 'prop' : 'get_services',
1782 'num_services_hard_warn' : {
1784 'depythonize' : lambda x
: len([y
for y
in x
if y
.state_id
== 2 and y
.state_type_id
== 1]),
1785 'description' : 'The number of services in the group that are WARN',
1786 'prop' : 'get_services',
1789 'num_services_ok' : {
1791 'depythonize' : lambda x
: len([y
for y
in x
if y
.state_id
== 0]),
1792 'description' : 'The number of services in the group that are OK',
1793 'prop' : 'get_services',
1796 'num_services_pending' : {
1798 'depythonize' : lambda x
: len([y
for y
in x
if y
.has_been_checked
== 0]),
1799 'description' : 'The number of services in the group that are PENDING',
1800 'prop' : 'get_services',
1803 'num_services_unknown' : {
1805 'depythonize' : lambda x
: len([y
for y
in x
if y
.state_id
== 3]),
1806 'description' : 'The number of services in the group that are UNKNOWN',
1807 'prop' : 'get_services',
1810 'num_services_warn' : {
1812 'depythonize' : lambda x
: len([y
for y
in x
if y
.state_id
== 1]),
1813 'description' : 'The number of services in the group that are WARN',
1814 'prop' : 'get_services',
1817 'worst_service_state' : {
1818 'depythonize' : lambda x
: reduce(worst_service_state
, (y
.state_id
for y
in x
), 0),
1819 'description' : 'The worst soft state of all of the groups services (OK <= WARN <= UNKNOWN <= CRIT)',
1820 'prop' : 'get_services',
1827 'description' : 'The additional field address1',
1831 'description' : 'The additional field address2',
1835 'description' : 'The additional field address3',
1839 'description' : 'The additional field address4',
1843 'description' : 'The additional field address5',
1847 'description' : 'The additional field address6',
1851 'description' : 'The full name of the contact',
1854 'can_submit_commands' : {
1855 'depythonize' : from_bool_to_int
,
1856 'description' : 'Wether the contact is allowed to submit commands (0/1)',
1859 'custom_variable_names' : {
1860 'description' : 'A list of all custom variables of the contact',
1863 'custom_variable_values' : {
1864 'description' : 'A list of the values of all custom variables of the contact',
1868 'description' : 'The email address of the contact',
1871 'host_notification_period' : {
1872 'depythonize' : 'get_name',
1873 'description' : 'The time period in which the contact will be notified about host problems',
1876 'host_notifications_enabled' : {
1877 'depythonize' : from_bool_to_int
,
1878 'description' : 'Wether the contact will be notified about host problems in general (0/1)',
1881 'in_host_notification_period' : {
1882 'depythonize' : from_bool_to_int
,
1883 'description' : 'Wether the contact is currently in his/her host notification period (0/1)',
1886 'in_service_notification_period' : {
1887 'depythonize' : from_bool_to_int
,
1888 'description' : 'Wether the contact is currently in his/her service notification period (0/1)',
1892 'description' : 'The login name of the contact person',
1893 'prop' : 'contact_name',
1897 'description' : 'The pager address of the contact',
1900 'service_notification_period' : {
1901 'depythonize' : 'get_name',
1902 'description' : 'The time period in which the contact will be notified about service problems',
1905 'service_notifications_enabled' : {
1906 'depythonize' : from_bool_to_int
,
1907 'description' : 'Wether the contact will be notified about service problems in general (0/1)',
1916 'description' : 'The alias of the contactgroup',
1920 'depythonize' : 'get_name',
1921 'description' : 'A list of all members of this contactgroup',
1925 'description' : 'The name of the contactgroup',
1926 'prop' : 'contactgroup_name',
1935 'description' : 'The alias of the timeperiod',
1939 'description' : 'The name of the timeperiod',
1940 'prop' : 'timeperiod_name',
1945 #All commands (checks + notifications)
1948 'description' : 'The shell command line',
1949 'prop' : 'command_line',
1953 'description' : 'The name of the command',
1954 'prop' : 'command_name',
1964 'description' : 'The name of the scheduler',
1965 'prop' : 'scheduler_name',
1969 'description' : 'The ip or dns adress ofthe scheduler',
1974 'description' : 'The TCP port of the scheduler',
1979 'description' : 'If the scheduler is a spare or not',
1980 'depythonize' : from_bool_to_int
,
1985 'description' : 'Weight (in terms of hosts) of the scheduler',
1990 'description' : 'If the scheduler is alive or not',
1992 'depythonize' : from_bool_to_int
,
2002 'description' : 'The name of the poller',
2003 'prop' : 'poller_name',
2007 'description' : 'The ip or dns adress of the poller',
2012 'description' : 'The TCP port of the poller',
2017 'description' : 'If the poller is a spare or not',
2018 'depythonize' : from_bool_to_int
,
2023 'description' : 'If the poller is alive or not',
2025 'depythonize' : from_bool_to_int
,
2032 'ReactionnerLink' : {
2034 'description' : 'The name of the reactionner',
2035 'prop' : 'reactionner_name',
2039 'description' : 'The ip or dns adress of the reactionner',
2044 'description' : 'The TCP port of the reactionner',
2049 'description' : 'If the reactionner is a spare or not',
2050 'depythonize' : from_bool_to_int
,
2055 'description' : 'If the reactionner is alive or not',
2057 'depythonize' : from_bool_to_int
,
2066 'description' : 'The name of the broker',
2067 'prop' : 'broker_name',
2071 'description' : 'The ip or dns adress of the broker',
2076 'description' : 'The TCP port of the broker',
2081 'description' : 'If the broker is a spare or not',
2082 'depythonize' : from_bool_to_int
,
2087 'description' : 'If the broker is alive or not',
2089 'depythonize' : from_bool_to_int
,
2098 'description' : 'The source name of the problem (host or service)',
2101 'fulldepythonize' : get_livestatus_full_name
2104 'description' : 'List of what the source impact (list of hosts and services)',
2107 'depythonize' : from_svc_hst_distinct_lists
,
2115 'default' : 'nobody',
2116 'description' : 'The contact that scheduled the downtime',
2122 'description' : 'A comment text',
2128 'description' : 'The duration of the downtime in seconds',
2134 'description' : 'The end time of the downtime as UNIX timestamp',
2140 'description' : 'The time the entry was made as UNIX timestamp',
2146 'depythonize' : from_bool_to_int
,
2147 'description' : 'A 1 if the downtime is fixed, a 0 if it is flexible',
2151 'host_accept_passive_checks' : {
2153 'description' : 'Wether passive host checks are accepted (0/1)',
2157 'host_acknowledged' : {
2159 'description' : 'Wether the current host problem has been acknowledged (0/1)',
2163 'host_acknowledgement_type' : {
2165 'description' : 'Type of acknowledgement (0: none, 1: normal, 2: stick)',
2169 'host_action_url' : {
2171 'description' : 'An optional URL to custom actions or information about this host',
2175 'host_action_url_expanded' : {
2177 'description' : 'The same as action_url, but with the most important macros expanded',
2181 'host_active_checks_enabled' : {
2183 'description' : 'Wether active checks are enabled for the host (0/1)',
2189 'description' : 'IP address',
2195 'description' : 'An alias name for the host',
2199 'host_check_command' : {
2201 'description' : 'Nagios command for active host check of this host',
2205 'host_check_freshness' : {
2207 'description' : 'Wether freshness checks are activated (0/1)',
2211 'host_check_interval' : {
2213 'description' : 'Number of basic interval lengths between two scheduled checks of the host',
2217 'host_check_options' : {
2219 'description' : 'The current check option, forced, normal, freshness... (0-2)',
2223 'host_check_period' : {
2225 'description' : 'Time period in which this host will be checked. If empty then the host will always be checked.',
2229 'host_check_type' : {
2231 'description' : 'Type of check (0: active, 1: passive)',
2235 'host_checks_enabled' : {
2237 'description' : 'Wether checks of the host are enabled (0/1)',
2243 'description' : 'A list of all direct childs of the host',
2249 'description' : 'A list of the ids of all comments of this host',
2255 'description' : 'A list of all contacts of this host, either direct or via a contact group',
2259 'host_current_attempt' : {
2261 'description' : 'Number of the current check attempts',
2265 'host_current_notification_number' : {
2267 'description' : 'Number of the current notification',
2271 'host_custom_variable_names' : {
2273 'description' : 'A list of the names of all custom variables',
2277 'host_custom_variable_values' : {
2279 'description' : 'A list of the values of the custom variables',
2283 'host_display_name' : {
2285 'description' : 'Optional display name of the host - not used by Nagios\' web interface',
2289 'host_downtimes' : {
2291 'description' : 'A list of the ids of all scheduled downtimes of this host',
2295 'host_event_handler_enabled' : {
2297 'description' : 'Wether event handling is enabled (0/1)',
2301 'host_execution_time' : {
2303 'description' : 'Time the host check needed for execution',
2307 'host_first_notification_delay' : {
2309 'description' : 'Delay before the first notification',
2313 'host_flap_detection_enabled' : {
2315 'description' : 'Wether flap detection is enabled (0/1)',
2321 'description' : 'A list of all host groups this host is in',
2325 'host_hard_state' : {
2327 'description' : 'The effective hard state of the host (eliminates a problem in hard_state)',
2331 'host_has_been_checked' : {
2333 'description' : 'Wether the host has already been checked (0/1)',
2337 'host_high_flap_threshold' : {
2339 'description' : 'High threshold of flap detection',
2343 'host_icon_image' : {
2345 'description' : 'The name of an image file to be used in the web pages',
2349 'host_icon_image_alt' : {
2351 'description' : 'Alternative text for the icon_image',
2355 'host_icon_image_expanded' : {
2357 'description' : 'The same as icon_image, but with the most important macros expanded',
2361 'host_in_check_period' : {
2363 'description' : 'Wether this host is currently in its check period (0/1)',
2367 'host_in_notification_period' : {
2369 'description' : 'Wether this host is currently in its notification period (0/1)',
2373 'host_initial_state' : {
2375 'description' : 'Initial host state',
2379 'host_is_executing' : {
2380 'default' : 0, # value in scheduler is not real-time
2381 'description' : 'is there a host check currently running... (0/1)',
2385 'host_is_flapping' : {
2387 'description' : 'Wether the host state is flapping (0/1)',
2391 'host_last_check' : {
2393 'description' : 'Time of the last check (Unix timestamp)',
2397 'host_last_hard_state' : {
2399 'description' : 'Last hard state',
2403 'host_last_hard_state_change' : {
2405 'description' : 'Time of the last hard state change (Unix timestamp)',
2409 'host_last_notification' : {
2411 'description' : 'Time of the last notification (Unix timestamp)',
2415 'host_last_state' : {
2417 'description' : 'State before last state change',
2421 'host_last_state_change' : {
2423 'description' : 'Time of the last state change - soft or hard (Unix timestamp)',
2429 'description' : 'Time difference between scheduled check time and actual check time',
2433 'host_long_plugin_output' : {
2435 'description' : 'Complete output from check plugin',
2439 'host_low_flap_threshold' : {
2441 'description' : 'Low threshold of flap detection',
2445 'host_max_check_attempts' : {
2447 'description' : 'Max check attempts for active host checks',
2453 'depythonize' : lambda x
: x
.host_name
,
2454 'description' : 'Host name',
2458 'host_next_check' : {
2460 'description' : 'Scheduled time for the next check (Unix timestamp)',
2464 'host_next_notification' : {
2466 'description' : 'Time of the next notification (Unix timestamp)',
2472 'description' : 'Optional notes for this host',
2476 'host_notes_expanded' : {
2478 'description' : 'The same as notes, but with the most important macros expanded',
2482 'host_notes_url' : {
2484 'description' : 'An optional URL with further information about the host',
2488 'host_notes_url_expanded' : {
2490 'description' : 'Same es notes_url, but with the most important macros expanded',
2494 'host_notification_interval' : {
2496 'description' : 'Interval of periodic notification or 0 if its off',
2500 'host_notification_period' : {
2502 'description' : 'Time period in which problems of this host will be notified. If empty then notification will be always',
2506 'host_notifications_enabled' : {
2508 'description' : 'Wether notifications of the host are enabled (0/1)',
2512 'host_num_services' : {
2514 'description' : 'The total number of services of the host',
2518 'host_num_services_crit' : {
2520 'description' : 'The number of the host\'s services with the soft state CRIT',
2524 'host_num_services_hard_crit' : {
2526 'description' : 'The number of the host\'s services with the hard state CRIT',
2530 'host_num_services_hard_ok' : {
2532 'description' : 'The number of the host\'s services with the hard state OK',
2536 'host_num_services_hard_unknown' : {
2538 'description' : 'The number of the host\'s services with the hard state UNKNOWN',
2542 'host_num_services_hard_warn' : {
2544 'description' : 'The number of the host\'s services with the hard state WARN',
2548 'host_num_services_ok' : {
2550 'description' : 'The number of the host\'s services with the soft state OK',
2554 'host_num_services_pending' : {
2556 'description' : 'The number of the host\'s services which have not been checked yet (pending)',
2560 'host_num_services_unknown' : {
2562 'description' : 'The number of the host\'s services with the soft state UNKNOWN',
2566 'host_num_services_warn' : {
2568 'description' : 'The number of the host\'s services with the soft state WARN',
2572 'host_obsess_over_host' : {
2574 'description' : 'The current obsess_over_host setting... (0/1)',
2580 'description' : 'A list of all direct parents of the host',
2584 'host_pending_flex_downtime' : {
2586 'description' : 'Wether a flex downtime is pending (0/1)',
2590 'host_percent_state_change' : {
2592 'description' : 'Percent state change',
2596 'host_perf_data' : {
2598 'description' : 'Optional performance data of the last host check',
2602 'host_plugin_output' : {
2604 'description' : 'Output of the last host check',
2608 'host_process_performance_data' : {
2610 'description' : 'Wether processing of performance data is enabled (0/1)',
2614 'host_retry_interval' : {
2616 'description' : 'Number of basic interval lengths between checks when retrying after a soft error',
2620 'host_scheduled_downtime_depth' : {
2622 'description' : 'The number of downtimes this host is currently in',
2628 'description' : 'The current state of the host (0: up, 1: down, 2: unreachable)',
2632 'host_state_type' : {
2634 'description' : 'Type of the current state (0: soft, 1: hard)',
2638 'host_statusmap_image' : {
2640 'description' : 'The name of in image file for the status map',
2644 'host_total_services' : {
2646 'description' : 'The total number of services of the host',
2650 'host_worst_service_hard_state' : {
2652 'description' : 'The worst hard state of all of the host\'s services (OK <= WARN <= UNKNOWN <= CRIT)',
2656 'host_worst_service_state' : {
2658 'description' : 'The worst soft state of all of the host\'s services (OK <= WARN <= UNKNOWN <= CRIT)',
2664 'description' : '3D-Coordinates: X',
2670 'description' : '3D-Coordinates: Y',
2676 'description' : '3D-Coordinates: Z',
2682 'description' : 'The id of the downtime',
2686 'service_accept_passive_checks' : {
2688 'description' : 'Wether the service accepts passive checks (0/1)',
2692 'service_acknowledged' : {
2694 'description' : 'Wether the current service problem has been acknowledged (0/1)',
2698 'service_acknowledgement_type' : {
2700 'description' : 'The type of the acknownledgement (0: none, 1: normal, 2: sticky)',
2704 'service_action_url' : {
2706 'description' : 'An optional URL for actions or custom information about the service',
2710 'service_action_url_expanded' : {
2712 'description' : 'The action_url with (the most important) macros expanded',
2716 'service_active_checks_enabled' : {
2718 'description' : 'Wether active checks are enabled for the service (0/1)',
2722 'service_check_command' : {
2724 'description' : 'Nagios command used for active checks',
2728 'service_check_interval' : {
2730 'description' : 'Number of basic interval lengths between two scheduled checks of the service',
2734 'service_check_options' : {
2736 'description' : 'The current check option, forced, normal, freshness... (0/1)',
2740 'service_check_period' : {
2742 'description' : 'The name of the check period of the service. It this is empty, the service is always checked.',
2746 'service_check_type' : {
2748 'description' : 'The type of the last check (0: active, 1: passive)',
2752 'service_checks_enabled' : {
2754 'description' : 'Wether active checks are enabled for the service (0/1)',
2758 'service_comments' : {
2760 'description' : 'A list of all comment ids of the service',
2764 'service_contacts' : {
2766 'description' : 'A list of all contacts of the service, either direct or via a contact group',
2770 'service_current_attempt' : {
2772 'description' : 'The number of the current check attempt',
2776 'service_current_notification_number' : {
2778 'description' : 'The number of the current notification',
2782 'service_custom_variable_names' : {
2784 'description' : 'A list of the names of all custom variables of the service',
2788 'service_custom_variable_values' : {
2790 'description' : 'A list of the values of all custom variable of the service',
2794 'service_description' : {
2796 'depythonize' : lambda x
: getattr(x
, 'service_description', ''),
2797 'description' : 'Description of the service (also used as key)',
2801 'service_display_name' : {
2803 'description' : 'An optional display name (not used by Nagios standard web pages)',
2807 'service_downtimes' : {
2809 'description' : 'A list of all downtime ids of the service',
2813 'service_event_handler' : {
2815 'description' : 'Nagios command used as event handler',
2819 'service_event_handler_enabled' : {
2821 'description' : 'Wether and event handler is activated for the service (0/1)',
2825 'service_execution_time' : {
2827 'description' : 'Time the host check needed for execution',
2831 'service_first_notification_delay' : {
2833 'description' : 'Delay before the first notification',
2837 'service_flap_detection_enabled' : {
2839 'description' : 'Wether flap detection is enabled for the service (0/1)',
2843 'service_groups' : {
2845 'description' : 'A list of all service groups the service is in',
2849 'service_has_been_checked' : {
2851 'description' : 'Wether the service already has been checked (0/1)',
2855 'service_high_flap_threshold' : {
2857 'description' : 'High threshold of flap detection',
2861 'service_icon_image' : {
2863 'description' : 'The name of an image to be used as icon in the web interface',
2867 'service_icon_image_alt' : {
2869 'description' : 'An alternative text for the icon_image for browsers not displaying icons',
2873 'service_icon_image_expanded' : {
2875 'description' : 'The icon_image with (the most important) macros expanded',
2879 'service_in_check_period' : {
2881 'description' : 'Wether the service is currently in its check period (0/1)',
2885 'service_in_notification_period' : {
2887 'description' : 'Wether the service is currently in its notification period (0/1)',
2891 'service_initial_state' : {
2893 'description' : 'The initial state of the service',
2897 'service_is_executing' : {
2898 'default' : 0, # value in scheduler is not real-time
2899 'description' : 'is there a service check currently running... (0/1)',
2903 'service_is_flapping' : {
2905 'description' : 'Wether the service is flapping (0/1)',
2909 'service_last_check' : {
2911 'description' : 'The time of the last check (Unix timestamp)',
2915 'service_last_hard_state' : {
2917 'description' : 'The last hard state of the service',
2921 'service_last_hard_state_change' : {
2923 'description' : 'The time of the last hard state change (Unix timestamp)',
2927 'service_last_notification' : {
2929 'description' : 'The time of the last notification (Unix timestamp)',
2933 'service_last_state' : {
2935 'description' : 'The last state of the service',
2939 'service_last_state_change' : {
2941 'description' : 'The time of the last state change (Unix timestamp)',
2945 'service_latency' : {
2947 'description' : 'Time difference between scheduled check time and actual check time',
2951 'service_long_plugin_output' : {
2953 'description' : 'Unabbreviated output of the last check plugin',
2957 'service_low_flap_threshold' : {
2959 'description' : 'Low threshold of flap detection',
2963 'service_max_check_attempts' : {
2965 'description' : 'The maximum number of check attempts',
2969 'service_next_check' : {
2971 'description' : 'The scheduled time of the next check (Unix timestamp)',
2975 'service_next_notification' : {
2977 'description' : 'The time of the next notification (Unix timestamp)',
2983 'description' : 'Optional notes about the service',
2987 'service_notes_expanded' : {
2989 'description' : 'The notes with (the most important) macros expanded',
2993 'service_notes_url' : {
2995 'description' : 'An optional URL for additional notes about the service',
2999 'service_notes_url_expanded' : {
3001 'description' : 'The notes_url with (the most important) macros expanded',
3005 'service_notification_interval' : {
3007 'description' : 'Interval of periodic notification or 0 if its off',
3011 'service_notification_period' : {
3013 'description' : 'The name of the notification period of the service. It this is empty, service problems are always notified.',
3017 'service_notifications_enabled' : {
3019 'description' : 'Wether notifications are enabled for the service (0/1)',
3023 'service_obsess_over_service' : {
3025 'description' : 'Wether \'obsess_over_service\' is enabled for the service (0/1)',
3029 'service_percent_state_change' : {
3031 'description' : 'Percent state change',
3035 'service_perf_data' : {
3037 'description' : 'Performance data of the last check plugin',
3041 'service_plugin_output' : {
3043 'description' : 'Output of the last check plugin',
3047 'service_process_performance_data' : {
3049 'description' : 'Wether processing of performance data is enabled for the service (0/1)',
3053 'service_retry_interval' : {
3055 'description' : 'Number of basic interval lengths between checks when retrying after a soft error',
3059 'service_scheduled_downtime_depth' : {
3061 'description' : 'The number of scheduled downtimes the service is currently in',
3067 'description' : 'The current state of the service (0: OK, 1: WARN, 2: CRITICAL, 3: UNKNOWN)',
3071 'service_state_type' : {
3073 'description' : 'The type of the current state (0: soft, 1: hard)',
3079 'description' : 'The start time of the downtime as UNIX timestamp',
3085 'description' : 'The id of the downtime this downtime was triggered by or 0 if it was not triggered by another downtime',
3086 'prop' : 'trigger_id',
3091 'description' : 'The type of the downtime: 0 if it is active, 1 if it is pending',
3102 'description' : 'The contact that entered the comment',
3108 'description' : 'A comment text',
3114 'description' : 'The time the entry was made as UNIX timestamp',
3120 'description' : 'The type of the comment: 1 is user, 2 is downtime, 3 is flap and 4 is acknowledgement',
3121 'prop' : 'entry_type',
3126 'description' : 'The time of expiry of this comment as a UNIX timestamp',
3132 'depythonize' : from_bool_to_int
,
3133 'description' : 'Whether this comment expires',
3137 'host_accept_passive_checks' : {
3139 'description' : 'Wether passive host checks are accepted (0/1)',
3143 'host_acknowledged' : {
3145 'description' : 'Wether the current host problem has been acknowledged (0/1)',
3149 'host_acknowledgement_type' : {
3151 'description' : 'Type of acknowledgement (0: none, 1: normal, 2: stick)',
3155 'host_action_url' : {
3157 'description' : 'An optional URL to custom actions or information about this host',
3161 'host_action_url_expanded' : {
3163 'description' : 'The same as action_url, but with the most important macros expanded',
3167 'host_active_checks_enabled' : {
3169 'description' : 'Wether active checks are enabled for the host (0/1)',
3175 'description' : 'IP address',
3181 'description' : 'An alias name for the host',
3185 'host_check_command' : {
3187 'description' : 'Nagios command for active host check of this host',
3191 'host_check_freshness' : {
3193 'description' : 'Wether freshness checks are activated (0/1)',
3197 'host_check_interval' : {
3199 'description' : 'Number of basic interval lengths between two scheduled checks of the host',
3203 'host_check_options' : {
3205 'description' : 'The current check option, forced, normal, freshness... (0-2)',
3209 'host_check_period' : {
3211 'description' : 'Time period in which this host will be checked. If empty then the host will always be checked.',
3215 'host_check_type' : {
3217 'description' : 'Type of check (0: active, 1: passive)',
3221 'host_checks_enabled' : {
3223 'description' : 'Wether checks of the host are enabled (0/1)',
3229 'description' : 'A list of all direct childs of the host',
3235 'description' : 'A list of the ids of all comments of this host',
3241 'description' : 'A list of all contacts of this host, either direct or via a contact group',
3245 'host_current_attempt' : {
3247 'description' : 'Number of the current check attempts',
3251 'host_current_notification_number' : {
3253 'description' : 'Number of the current notification',
3257 'host_custom_variable_names' : {
3259 'description' : 'A list of the names of all custom variables',
3263 'host_custom_variable_values' : {
3265 'description' : 'A list of the values of the custom variables',
3269 'host_display_name' : {
3271 'description' : 'Optional display name of the host - not used by Nagios\' web interface',
3275 'host_downtimes' : {
3277 'description' : 'A list of the ids of all scheduled downtimes of this host',
3281 'host_event_handler_enabled' : {
3283 'description' : 'Wether event handling is enabled (0/1)',
3287 'host_execution_time' : {
3289 'description' : 'Time the host check needed for execution',
3293 'host_first_notification_delay' : {
3295 'description' : 'Delay before the first notification',
3299 'host_flap_detection_enabled' : {
3301 'description' : 'Wether flap detection is enabled (0/1)',
3307 'description' : 'A list of all host groups this host is in',
3311 'host_hard_state' : {
3313 'description' : 'The effective hard state of the host (eliminates a problem in hard_state)',
3317 'host_has_been_checked' : {
3319 'description' : 'Wether the host has already been checked (0/1)',
3323 'host_high_flap_threshold' : {
3325 'description' : 'High threshold of flap detection',
3329 'host_icon_image' : {
3331 'description' : 'The name of an image file to be used in the web pages',
3335 'host_icon_image_alt' : {
3337 'description' : 'Alternative text for the icon_image',
3341 'host_icon_image_expanded' : {
3343 'description' : 'The same as icon_image, but with the most important macros expanded',
3347 'host_in_check_period' : {
3349 'description' : 'Wether this host is currently in its check period (0/1)',
3353 'host_in_notification_period' : {
3355 'description' : 'Wether this host is currently in its notification period (0/1)',
3359 'host_initial_state' : {
3361 'description' : 'Initial host state',
3365 'host_is_executing' : {
3366 'default' : 0, # value in scheduler is not real-time
3367 'description' : 'is there a host check currently running... (0/1)',
3371 'host_is_flapping' : {
3373 'description' : 'Wether the host state is flapping (0/1)',
3377 'host_last_check' : {
3379 'description' : 'Time of the last check (Unix timestamp)',
3383 'host_last_hard_state' : {
3385 'description' : 'Last hard state',
3389 'host_last_hard_state_change' : {
3391 'description' : 'Time of the last hard state change (Unix timestamp)',
3395 'host_last_notification' : {
3397 'description' : 'Time of the last notification (Unix timestamp)',
3401 'host_last_state' : {
3403 'description' : 'State before last state change',
3407 'host_last_state_change' : {
3409 'description' : 'Time of the last state change - soft or hard (Unix timestamp)',
3415 'description' : 'Time difference between scheduled check time and actual check time',
3419 'host_long_plugin_output' : {
3421 'description' : 'Complete output from check plugin',
3425 'host_low_flap_threshold' : {
3427 'description' : 'Low threshold of flap detection',
3431 'host_max_check_attempts' : {
3433 'description' : 'Max check attempts for active host checks',
3439 'depythonize' : lambda x
: x
.host_name
,
3440 'description' : 'Host name',
3444 'host_next_check' : {
3446 'description' : 'Scheduled time for the next check (Unix timestamp)',
3450 'host_next_notification' : {
3452 'description' : 'Time of the next notification (Unix timestamp)',
3458 'description' : 'Optional notes for this host',
3462 'host_notes_expanded' : {
3464 'description' : 'The same as notes, but with the most important macros expanded',
3468 'host_notes_url' : {
3470 'description' : 'An optional URL with further information about the host',
3474 'host_notes_url_expanded' : {
3476 'description' : 'Same es notes_url, but with the most important macros expanded',
3480 'host_notification_interval' : {
3482 'description' : 'Interval of periodic notification or 0 if its off',
3486 'host_notification_period' : {
3488 'description' : 'Time period in which problems of this host will be notified. If empty then notification will be always',
3492 'host_notifications_enabled' : {
3494 'description' : 'Wether notifications of the host are enabled (0/1)',
3498 'host_num_services' : {
3500 'description' : 'The total number of services of the host',
3504 'host_num_services_crit' : {
3506 'description' : 'The number of the host\'s services with the soft state CRIT',
3510 'host_num_services_hard_crit' : {
3512 'description' : 'The number of the host\'s services with the hard state CRIT',
3516 'host_num_services_hard_ok' : {
3518 'description' : 'The number of the host\'s services with the hard state OK',
3522 'host_num_services_hard_unknown' : {
3524 'description' : 'The number of the host\'s services with the hard state UNKNOWN',
3528 'host_num_services_hard_warn' : {
3530 'description' : 'The number of the host\'s services with the hard state WARN',
3534 'host_num_services_ok' : {
3536 'description' : 'The number of the host\'s services with the soft state OK',
3540 'host_num_services_pending' : {
3542 'description' : 'The number of the host\'s services which have not been checked yet (pending)',
3546 'host_num_services_unknown' : {
3548 'description' : 'The number of the host\'s services with the soft state UNKNOWN',
3552 'host_num_services_warn' : {
3554 'description' : 'The number of the host\'s services with the soft state WARN',
3558 'host_obsess_over_host' : {
3560 'description' : 'The current obsess_over_host setting... (0/1)',
3566 'description' : 'A list of all direct parents of the host',
3570 'host_pending_flex_downtime' : {
3572 'description' : 'Wether a flex downtime is pending (0/1)',
3576 'host_percent_state_change' : {
3578 'description' : 'Percent state change',
3582 'host_perf_data' : {
3584 'description' : 'Optional performance data of the last host check',
3588 'host_plugin_output' : {
3590 'description' : 'Output of the last host check',
3594 'host_process_performance_data' : {
3596 'description' : 'Wether processing of performance data is enabled (0/1)',
3600 'host_retry_interval' : {
3602 'description' : 'Number of basic interval lengths between checks when retrying after a soft error',
3606 'host_scheduled_downtime_depth' : {
3608 'description' : 'The number of downtimes this host is currently in',
3614 'description' : 'The current state of the host (0: up, 1: down, 2: unreachable)',
3618 'host_state_type' : {
3620 'description' : 'Type of the current state (0: soft, 1: hard)',
3624 'host_statusmap_image' : {
3626 'description' : 'The name of in image file for the status map',
3630 'host_total_services' : {
3632 'description' : 'The total number of services of the host',
3636 'host_worst_service_hard_state' : {
3638 'description' : 'The worst hard state of all of the host\'s services (OK <= WARN <= UNKNOWN <= CRIT)',
3642 'host_worst_service_state' : {
3644 'description' : 'The worst soft state of all of the host\'s services (OK <= WARN <= UNKNOWN <= CRIT)',
3650 'description' : '3D-Coordinates: X',
3656 'description' : '3D-Coordinates: Y',
3662 'description' : '3D-Coordinates: Z',
3668 'description' : 'The id of the comment',
3674 'depythonize' : from_bool_to_int
,
3675 'description' : 'Whether this comment is persistent (0/1)',
3679 'service_accept_passive_checks' : {
3681 'description' : 'Wether the service accepts passive checks (0/1)',
3685 'service_acknowledged' : {
3687 'description' : 'Wether the current service problem has been acknowledged (0/1)',
3691 'service_acknowledgement_type' : {
3693 'description' : 'The type of the acknownledgement (0: none, 1: normal, 2: sticky)',
3697 'service_action_url' : {
3699 'description' : 'An optional URL for actions or custom information about the service',
3703 'service_action_url_expanded' : {
3705 'description' : 'The action_url with (the most important) macros expanded',
3709 'service_active_checks_enabled' : {
3711 'description' : 'Wether active checks are enabled for the service (0/1)',
3715 'service_check_command' : {
3717 'description' : 'Nagios command used for active checks',
3721 'service_check_interval' : {
3723 'description' : 'Number of basic interval lengths between two scheduled checks of the service',
3727 'service_check_options' : {
3729 'description' : 'The current check option, forced, normal, freshness... (0/1)',
3733 'service_check_period' : {
3735 'description' : 'The name of the check period of the service. It this is empty, the service is always checked.',
3739 'service_check_type' : {
3741 'description' : 'The type of the last check (0: active, 1: passive)',
3745 'service_checks_enabled' : {
3747 'description' : 'Wether active checks are enabled for the service (0/1)',
3751 'service_comments' : {
3753 'description' : 'A list of all comment ids of the service',
3757 'service_contacts' : {
3759 'description' : 'A list of all contacts of the service, either direct or via a contact group',
3763 'service_current_attempt' : {
3765 'description' : 'The number of the current check attempt',
3769 'service_current_notification_number' : {
3771 'description' : 'The number of the current notification',
3775 'service_custom_variable_names' : {
3777 'description' : 'A list of the names of all custom variables of the service',
3781 'service_custom_variable_values' : {
3783 'description' : 'A list of the values of all custom variable of the service',
3787 'service_description' : {
3789 'depythonize' : lambda x
: getattr(x
, 'service_description', ''),
3790 'description' : 'Description of the service (also used as key)',
3794 'service_display_name' : {
3796 'description' : 'An optional display name (not used by Nagios standard web pages)',
3800 'service_downtimes' : {
3802 'description' : 'A list of all downtime ids of the service',
3806 'service_event_handler' : {
3808 'description' : 'Nagios command used as event handler',
3812 'service_event_handler_enabled' : {
3814 'description' : 'Wether and event handler is activated for the service (0/1)',
3818 'service_execution_time' : {
3820 'description' : 'Time the host check needed for execution',
3824 'service_first_notification_delay' : {
3826 'description' : 'Delay before the first notification',
3830 'service_flap_detection_enabled' : {
3832 'description' : 'Wether flap detection is enabled for the service (0/1)',
3836 'service_groups' : {
3838 'description' : 'A list of all service groups the service is in',
3842 'service_has_been_checked' : {
3844 'description' : 'Wether the service already has been checked (0/1)',
3848 'service_high_flap_threshold' : {
3850 'description' : 'High threshold of flap detection',
3854 'service_icon_image' : {
3856 'description' : 'The name of an image to be used as icon in the web interface',
3860 'service_icon_image_alt' : {
3862 'description' : 'An alternative text for the icon_image for browsers not displaying icons',
3866 'service_icon_image_expanded' : {
3868 'description' : 'The icon_image with (the most important) macros expanded',
3872 'service_in_check_period' : {
3874 'description' : 'Wether the service is currently in its check period (0/1)',
3878 'service_in_notification_period' : {
3880 'description' : 'Wether the service is currently in its notification period (0/1)',
3884 'service_initial_state' : {
3886 'description' : 'The initial state of the service',
3890 'service_is_executing' : {
3891 'default' : 0, # value in scheduler is not real-time
3892 'description' : 'is there a service check currently running... (0/1)',
3896 'service_is_flapping' : {
3898 'description' : 'Wether the service is flapping (0/1)',
3902 'service_last_check' : {
3904 'description' : 'The time of the last check (Unix timestamp)',
3908 'service_last_hard_state' : {
3910 'description' : 'The last hard state of the service',
3914 'service_last_hard_state_change' : {
3916 'description' : 'The time of the last hard state change (Unix timestamp)',
3920 'service_last_notification' : {
3922 'description' : 'The time of the last notification (Unix timestamp)',
3926 'service_last_state' : {
3928 'description' : 'The last state of the service',
3932 'service_last_state_change' : {
3934 'description' : 'The time of the last state change (Unix timestamp)',
3938 'service_latency' : {
3940 'description' : 'Time difference between scheduled check time and actual check time',
3944 'service_long_plugin_output' : {
3946 'description' : 'Unabbreviated output of the last check plugin',
3950 'service_low_flap_threshold' : {
3952 'description' : 'Low threshold of flap detection',
3956 'service_max_check_attempts' : {
3958 'description' : 'The maximum number of check attempts',
3962 'service_next_check' : {
3964 'description' : 'The scheduled time of the next check (Unix timestamp)',
3968 'service_next_notification' : {
3970 'description' : 'The time of the next notification (Unix timestamp)',
3976 'description' : 'Optional notes about the service',
3980 'service_notes_expanded' : {
3982 'description' : 'The notes with (the most important) macros expanded',
3986 'service_notes_url' : {
3988 'description' : 'An optional URL for additional notes about the service',
3992 'service_notes_url_expanded' : {
3994 'description' : 'The notes_url with (the most important) macros expanded',
3998 'service_notification_interval' : {
4000 'description' : 'Interval of periodic notification or 0 if its off',
4004 'service_notification_period' : {
4006 'description' : 'The name of the notification period of the service. It this is empty, service problems are always notified.',
4010 'service_notifications_enabled' : {
4012 'description' : 'Wether notifications are enabled for the service (0/1)',
4016 'service_obsess_over_service' : {
4018 'description' : 'Wether \'obsess_over_service\' is enabled for the service (0/1)',
4022 'service_percent_state_change' : {
4024 'description' : 'Percent state change',
4028 'service_perf_data' : {
4030 'description' : 'Performance data of the last check plugin',
4034 'service_plugin_output' : {
4036 'description' : 'Output of the last check plugin',
4040 'service_process_performance_data' : {
4042 'description' : 'Wether processing of performance data is enabled for the service (0/1)',
4046 'service_retry_interval' : {
4048 'description' : 'Number of basic interval lengths between checks when retrying after a soft error',
4052 'service_scheduled_downtime_depth' : {
4054 'description' : 'The number of scheduled downtimes the service is currently in',
4060 'description' : 'The current state of the service (0: OK, 1: WARN, 2: CRITICAL, 3: UNKNOWN)',
4064 'service_state_type' : {
4066 'description' : 'The type of the current state (0: soft, 1: hard)',
4072 'description' : 'The source of the comment (0 is internal and 1 is external)',
4078 'description' : 'The type of the comment: 1 is service, 2 is host',
4079 'prop' : 'comment_type',
4084 # loop over hostgroups then over members
4086 'hostgroup_action_url' : {
4087 'description' : 'An optional URL to custom actions or information about the hostgroup',
4088 'prop' : 'hostgroup',
4091 'hostgroup_alias' : {
4092 'depythonize' : lambda x
: getattr(x
, 'hostgroup_alias', ''),
4093 'description' : 'An alias of the hostgroup',
4094 'prop' : 'hostgroup',
4097 'hostgroup_members' : {
4098 'description' : 'A list of all host names that are members of the hostgroup',
4099 'prop' : 'hostgroup',
4102 'hostgroup_members_with_state' : {
4103 'description' : 'A list of all host names that are members of the hostgroup together with state and has_been_checked',
4104 'prop' : 'hostgroup',
4107 'hostgroup_name' : {
4108 'depythonize' : lambda x
: getattr(x
, 'hostgroup_name', ''),
4109 'description' : 'Name of the hostgroup',
4110 'prop' : 'hostgroup',
4113 'hostgroup_notes' : {
4114 'description' : 'Optional notes to the hostgroup',
4115 'prop' : 'hostgroup',
4118 'hostgroup_notes_url' : {
4119 'description' : 'An optional URL with further information about the hostgroup',
4120 'prop' : 'hostgroup',
4123 'hostgroup_num_hosts' : {
4124 'description' : 'The total number of hosts in the group',
4125 'prop' : 'hostgroup',
4128 'hostgroup_num_hosts_down' : {
4129 'description' : 'The number of hosts in the group that are down',
4130 'prop' : 'hostgroup',
4133 'hostgroup_num_hosts_pending' : {
4134 'description' : 'The number of hosts in the group that are pending',
4135 'prop' : 'hostgroup',
4138 'hostgroup_num_hosts_unreach' : {
4139 'description' : 'The number of hosts in the group that are unreachable',
4140 'prop' : 'hostgroup',
4143 'hostgroup_num_hosts_up' : {
4144 'description' : 'The number of hosts in the group that are up',
4145 'prop' : 'hostgroup',
4148 'hostgroup_num_services' : {
4149 'description' : 'The total number of services of hosts in this group',
4150 'prop' : 'hostgroup',
4153 'hostgroup_num_services_crit' : {
4154 'description' : 'The total number of services with the state CRIT of hosts in this group',
4155 'prop' : 'hostgroup',
4158 'hostgroup_num_services_hard_crit' : {
4159 'description' : 'The total number of services with the state CRIT of hosts in this group',
4160 'prop' : 'hostgroup',
4163 'hostgroup_num_services_hard_ok' : {
4164 'description' : 'The total number of services with the state OK of hosts in this group',
4165 'prop' : 'hostgroup',
4168 'hostgroup_num_services_hard_unknown' : {
4169 'description' : 'The total number of services with the state UNKNOWN of hosts in this group',
4170 'prop' : 'hostgroup',
4173 'hostgroup_num_services_hard_warn' : {
4174 'description' : 'The total number of services with the state WARN of hosts in this group',
4175 'prop' : 'hostgroup',
4178 'hostgroup_num_services_ok' : {
4179 'description' : 'The total number of services with the state OK of hosts in this group',
4180 'prop' : 'hostgroup',
4183 'hostgroup_num_services_pending' : {
4184 'description' : 'The total number of services with the state Pending of hosts in this group',
4185 'prop' : 'hostgroup',
4188 'hostgroup_num_services_unknown' : {
4189 'description' : 'The total number of services with the state UNKNOWN of hosts in this group',
4190 'prop' : 'hostgroup',
4193 'hostgroup_num_services_warn' : {
4194 'description' : 'The total number of services with the state WARN of hosts in this group',
4195 'prop' : 'hostgroup',
4198 'hostgroup_worst_host_state' : {
4199 'description' : 'The worst state of all of the groups\' hosts (UP <= UNREACHABLE <= DOWN)',
4200 'prop' : 'hostgroup',
4203 'hostgroup_worst_service_hard_state' : {
4204 'description' : 'The worst state of all services that belong to a host of this group (OK <= WARN <= UNKNOWN <= CRIT)',
4205 'prop' : 'hostgroup',
4208 'hostgroup_worst_service_state' : {
4209 'description' : 'The worst state of all services that belong to a host of this group (OK <= WARN <= UNKNOWN <= CRIT)',
4210 'prop' : 'hostgroup',
4215 'Servicesbygroup' : {
4216 'servicegroup_action_url' : {
4217 'description' : 'An optional URL to custom notes or actions on the service group',
4220 'servicegroup_alias' : {
4221 'description' : 'An alias of the service group',
4224 'servicegroup_members' : {
4225 'description' : 'A list of all members of the service group as host/service pairs',
4228 'servicegroup_members_with_state' : {
4229 'description' : 'A list of all members of the service group with state and has_been_checked',
4232 'servicegroup_name' : {
4233 'description' : 'The name of the service group',
4236 'servicegroup_notes' : {
4237 'description' : 'Optional additional notes about the service group',
4240 'servicegroup_notes_url' : {
4241 'description' : 'An optional URL to further notes on the service group',
4244 'servicegroup_num_services' : {
4245 'description' : 'The total number of services in the group',
4248 'servicegroup_num_services_crit' : {
4249 'description' : 'The number of services in the group that are CRIT',
4252 'servicegroup_num_services_hard_crit' : {
4253 'description' : 'The number of services in the group that are CRIT',
4256 'servicegroup_num_services_hard_ok' : {
4257 'description' : 'The number of services in the group that are OK',
4260 'servicegroup_num_services_hard_unknown' : {
4261 'description' : 'The number of services in the group that are UNKNOWN',
4264 'servicegroup_num_services_hard_warn' : {
4265 'description' : 'The number of services in the group that are WARN',
4268 'servicegroup_num_services_ok' : {
4269 'description' : 'The number of services in the group that are OK',
4272 'servicegroup_num_services_pending' : {
4273 'description' : 'The number of services in the group that are PENDING',
4276 'servicegroup_num_services_unknown' : {
4277 'description' : 'The number of services in the group that are UNKNOWN',
4280 'servicegroup_num_services_warn' : {
4281 'description' : 'The number of services in the group that are WARN',
4284 'servicegroup_worst_service_state' : {
4285 'description' : 'The worst soft state of all of the groups services (OK <= WARN <= UNKNOWN <= CRIT)',
4290 'Servicesbyhostgroup' : {
4291 'hostgroup_action_url' : {
4292 'description' : 'An optional URL to custom actions or information about the hostgroup',
4295 'hostgroup_alias' : {
4296 'description' : 'An alias of the hostgroup',
4299 'hostgroup_members' : {
4300 'description' : 'A list of all host names that are members of the hostgroup',
4303 'hostgroup_members_with_state' : {
4304 'description' : 'A list of all host names that are members of the hostgroup together with state and has_been_checked',
4307 'hostgroup_name' : {
4308 'depythonize' : lambda x
: getattr(x
, 'hostgroup_name', ''),
4309 'description' : 'Name of the hostgroup',
4310 'prop' : 'hostgroup',
4313 'hostgroup_notes' : {
4314 'description' : 'Optional notes to the hostgroup',
4317 'hostgroup_notes_url' : {
4318 'description' : 'An optional URL with further information about the hostgroup',
4321 'hostgroup_num_hosts' : {
4322 'description' : 'The total number of hosts in the group',
4325 'hostgroup_num_hosts_down' : {
4326 'description' : 'The number of hosts in the group that are down',
4329 'hostgroup_num_hosts_pending' : {
4330 'description' : 'The number of hosts in the group that are pending',
4333 'hostgroup_num_hosts_unreach' : {
4334 'description' : 'The number of hosts in the group that are unreachable',
4337 'hostgroup_num_hosts_up' : {
4338 'description' : 'The number of hosts in the group that are up',
4341 'hostgroup_num_services' : {
4342 'description' : 'The total number of services of hosts in this group',
4345 'hostgroup_num_services_crit' : {
4346 'description' : 'The total number of services with the state CRIT of hosts in this group',
4349 'hostgroup_num_services_hard_crit' : {
4350 'description' : 'The total number of services with the state CRIT of hosts in this group',
4353 'hostgroup_num_services_hard_ok' : {
4354 'description' : 'The total number of services with the state OK of hosts in this group',
4357 'hostgroup_num_services_hard_unknown' : {
4358 'description' : 'The total number of services with the state UNKNOWN of hosts in this group',
4361 'hostgroup_num_services_hard_warn' : {
4362 'description' : 'The total number of services with the state WARN of hosts in this group',
4365 'hostgroup_num_services_ok' : {
4366 'description' : 'The total number of services with the state OK of hosts in this group',
4369 'hostgroup_num_services_pending' : {
4370 'description' : 'The total number of services with the state Pending of hosts in this group',
4373 'hostgroup_num_services_unknown' : {
4374 'description' : 'The total number of services with the state UNKNOWN of hosts in this group',
4377 'hostgroup_num_services_warn' : {
4378 'description' : 'The total number of services with the state WARN of hosts in this group',
4381 'hostgroup_worst_host_state' : {
4382 'description' : 'The worst state of all of the groups\' hosts (UP <= UNREACHABLE <= DOWN)',
4385 'hostgroup_worst_service_hard_state' : {
4386 'description' : 'The worst state of all services that belong to a host of this group (OK <= WARN <= UNKNOWN <= CRIT)',
4389 'hostgroup_worst_service_state' : {
4390 'description' : 'The worst state of all services that belong to a host of this group (OK <= WARN <= UNKNOWN <= CRIT)',
4395 #All the global config parameters
4398 'accept_passive_host_checks' : {
4400 'depythonize' : from_bool_to_int
,
4401 'description' : 'Whether passive host checks are accepted in general (0/1)',
4402 'prop' : 'passive_host_checks_enabled',
4405 'accept_passive_service_checks' : {
4407 'depythonize' : from_bool_to_int
,
4408 'description' : 'Whether passive service checks are activated in general (0/1)',
4409 'prop' : 'passive_service_checks_enabled',
4412 'cached_log_messages' : {
4414 'description' : 'The current number of log messages MK Livestatus keeps in memory',
4418 'check_external_commands' : {
4420 'depythonize' : from_bool_to_int
,
4421 'description' : 'Whether Nagios checks for external commands at its command pipe (0/1)',
4425 'check_host_freshness' : {
4427 'depythonize' : from_bool_to_int
,
4428 'description' : 'Whether host freshness checking is activated in general (0/1)',
4432 'check_service_freshness' : {
4434 'depythonize' : from_bool_to_int
,
4435 'description' : 'Whether service freshness checking is activated in general (0/1)',
4441 'description' : 'The number of client connections to Livestatus since program start',
4445 'connections_rate' : {
4447 'description' : 'The averaged number of new client connections to Livestatus per second',
4451 'enable_event_handlers' : {
4453 'depythonize' : from_bool_to_int
,
4454 'description' : 'Whether event handlers are activated in general (0/1)',
4455 'prop' : 'event_handlers_enabled',
4458 'enable_flap_detection' : {
4460 'depythonize' : from_bool_to_int
,
4461 'description' : 'Whether flap detection is activated in general (0/1)',
4462 'prop' : 'flap_detection_enabled',
4465 'enable_notifications' : {
4467 'depythonize' : from_bool_to_int
,
4468 'description' : 'Whether notifications are enabled in general (0/1)',
4469 'prop' : 'notifications_enabled',
4472 'execute_host_checks' : {
4474 'depythonize' : from_bool_to_int
,
4475 'description' : 'Whether host checks are executed in general (0/1)',
4476 'prop' : 'active_host_checks_enabled',
4479 'execute_service_checks' : {
4481 'depythonize' : from_bool_to_int
,
4482 'description' : 'Whether active service checks are activated in general (0/1)',
4483 'prop' : 'active_service_checks_enabled',
4488 'description' : 'The number of host checks since program start',
4492 'host_checks_rate' : {
4494 'description' : 'the averaged number of host checks per second',
4498 'interval_length' : {
4500 'description' : 'The default interval length from nagios.cfg',
4504 'last_command_check' : {
4506 'description' : 'The time of the last check for a command as UNIX timestamp',
4510 'last_log_rotation' : {
4512 'description' : 'Time time of the last log file rotation',
4516 'livestatus_version' : {
4517 'default' : '1.1.3-shinken',
4518 'description' : 'The version of the MK Livestatus module',
4524 'description' : 'The process ID of the Nagios main process',
4530 'description' : 'The number of NEB call backs since program start',
4534 'neb_callbacks_rate' : {
4536 'description' : 'The averaged number of NEB call backs per second',
4540 'obsess_over_hosts' : {
4542 'depythonize' : from_bool_to_int
,
4543 'description' : 'Whether Nagios will obsess over host checks (0/1)',
4547 'obsess_over_services' : {
4549 'depythonize' : from_bool_to_int
,
4550 'description' : 'Whether Nagios will obsess over service checks and run the ocsp_command (0/1)',
4554 'process_performance_data' : {
4556 'depythonize' : from_bool_to_int
,
4557 'description' : 'Whether processing of performance data is activated in general (0/1)',
4563 'description' : 'The time of the last program start as UNIX timestamp',
4567 'program_version' : {
4568 'default' : VERSION
,
4569 'description' : 'The version of the monitoring daemon',
4575 'description' : 'The number of requests to Livestatus since program start',
4581 'description' : 'The averaged number of request to Livestatus per second',
4585 'service_checks' : {
4587 'description' : 'The number of completed service checks since program start',
4591 'service_checks_rate' : {
4593 'description' : 'The averaged number of service checks per second',
4601 'description' : 'The number of the check attempt',
4605 'description' : 'The class of the message as integer (0:info, 1:state, 2:program, 3:notification, 4:passive, 5:command)',
4609 'description' : 'The name of the command of the log entry (e.g. for notifications)',
4613 'description' : 'A comment field used in various message types',
4617 'description' : 'The name of the contact the log entry is about (might be empty)',
4620 'current_command_line' : {
4621 'description' : 'The shell command line',
4624 'current_command_name' : {
4625 'description' : 'The name of the command',
4628 'current_contact_address1' : {
4629 'description' : 'The additional field address1',
4632 'current_contact_address2' : {
4633 'description' : 'The additional field address2',
4636 'current_contact_address3' : {
4637 'description' : 'The additional field address3',
4640 'current_contact_address4' : {
4641 'description' : 'The additional field address4',
4644 'current_contact_address5' : {
4645 'description' : 'The additional field address5',
4648 'current_contact_address6' : {
4649 'description' : 'The additional field address6',
4652 'current_contact_alias' : {
4653 'description' : 'The full name of the contact',
4656 'current_contact_can_submit_commands' : {
4657 'description' : 'Wether the contact is allowed to submit commands (0/1)',
4660 'current_contact_custom_variable_names' : {
4661 'description' : 'A list of all custom variables of the contact',
4664 'current_contact_custom_variable_values' : {
4665 'description' : 'A list of the values of all custom variables of the contact',
4668 'current_contact_email' : {
4669 'description' : 'The email address of the contact',
4672 'current_contact_host_notification_period' : {
4673 'description' : 'The time period in which the contact will be notified about host problems',
4676 'current_contact_host_notifications_enabled' : {
4677 'description' : 'Wether the contact will be notified about host problems in general (0/1)',
4680 'current_contact_in_host_notification_period' : {
4681 'description' : 'Wether the contact is currently in his/her host notification period (0/1)',
4684 'current_contact_in_service_notification_period' : {
4685 'description' : 'Wether the contact is currently in his/her service notification period (0/1)',
4688 'current_contact_name' : {
4689 'description' : 'The login name of the contact person',
4692 'current_contact_pager' : {
4693 'description' : 'The pager address of the contact',
4696 'current_contact_service_notification_period' : {
4697 'description' : 'The time period in which the contact will be notified about service problems',
4700 'current_contact_service_notifications_enabled' : {
4701 'description' : 'Wether the contact will be notified about service problems in general (0/1)',
4704 'current_host_accept_passive_checks' : {
4705 'description' : 'Wether passive host checks are accepted (0/1)',
4708 'current_host_acknowledged' : {
4709 'description' : 'Wether the current host problem has been acknowledged (0/1)',
4712 'current_host_acknowledgement_type' : {
4713 'description' : 'Type of acknowledgement (0: none, 1: normal, 2: stick)',
4716 'current_host_action_url' : {
4717 'description' : 'An optional URL to custom actions or information about this host',
4720 'current_host_action_url_expanded' : {
4721 'description' : 'The same as action_url, but with the most important macros expanded',
4724 'current_host_active_checks_enabled' : {
4725 'description' : 'Wether active checks are enabled for the host (0/1)',
4728 'current_host_address' : {
4729 'description' : 'IP address',
4732 'current_host_alias' : {
4733 'description' : 'An alias name for the host',
4736 'current_host_check_command' : {
4737 'description' : 'Nagios command for active host check of this host',
4740 'current_host_check_freshness' : {
4741 'description' : 'Wether freshness checks are activated (0/1)',
4744 'current_host_check_interval' : {
4745 'description' : 'Number of basic interval lengths between two scheduled checks of the host',
4748 'current_host_check_options' : {
4749 'description' : 'The current check option, forced, normal, freshness... (0-2)',
4752 'current_host_check_period' : {
4753 'description' : 'Time period in which this host will be checked. If empty then the host will always be checked.',
4756 'current_host_check_type' : {
4757 'description' : 'Type of check (0: active, 1: passive)',
4760 'current_host_checks_enabled' : {
4761 'description' : 'Wether checks of the host are enabled (0/1)',
4764 'current_host_childs' : {
4765 'description' : 'A list of all direct childs of the host',
4768 'current_host_comments' : {
4769 'description' : 'A list of the ids of all comments of this host',
4772 'current_host_contacts' : {
4773 'description' : 'A list of all contacts of this host, either direct or via a contact group',
4776 'current_host_current_attempt' : {
4777 'description' : 'Number of the current check attempts',
4780 'current_host_current_notification_number' : {
4781 'description' : 'Number of the current notification',
4784 'current_host_custom_variable_names' : {
4785 'description' : 'A list of the names of all custom variables',
4788 'current_host_custom_variable_values' : {
4789 'description' : 'A list of the values of the custom variables',
4792 'current_host_display_name' : {
4793 'description' : 'Optional display name of the host - not used by Nagios\' web interface',
4796 'current_host_downtimes' : {
4797 'description' : 'A list of the ids of all scheduled downtimes of this host',
4800 'current_host_event_handler_enabled' : {
4801 'description' : 'Wether event handling is enabled (0/1)',
4804 'current_host_execution_time' : {
4805 'description' : 'Time the host check needed for execution',
4808 'current_host_first_notification_delay' : {
4809 'description' : 'Delay before the first notification',
4812 'current_host_flap_detection_enabled' : {
4813 'description' : 'Wether flap detection is enabled (0/1)',
4816 'current_host_groups' : {
4817 'description' : 'A list of all host groups this host is in',
4820 'current_host_hard_state' : {
4821 'description' : 'The effective hard state of the host (eliminates a problem in hard_state)',
4824 'current_host_has_been_checked' : {
4825 'description' : 'Wether the host has already been checked (0/1)',
4828 'current_host_high_flap_threshold' : {
4829 'description' : 'High threshold of flap detection',
4832 'current_host_icon_image' : {
4833 'description' : 'The name of an image file to be used in the web pages',
4836 'current_host_icon_image_alt' : {
4837 'description' : 'Alternative text for the icon_image',
4840 'current_host_icon_image_expanded' : {
4841 'description' : 'The same as icon_image, but with the most important macros expanded',
4844 'current_host_in_check_period' : {
4845 'description' : 'Wether this host is currently in its check period (0/1)',
4848 'current_host_in_notification_period' : {
4849 'description' : 'Wether this host is currently in its notification period (0/1)',
4852 'current_host_initial_state' : {
4853 'description' : 'Initial host state',
4856 'current_host_is_executing' : {
4857 'default' : 0, # value in scheduler is not real-time
4858 'description' : 'is there a host check currently running... (0/1)',
4861 'current_host_is_flapping' : {
4862 'description' : 'Wether the host state is flapping (0/1)',
4865 'current_host_last_check' : {
4866 'description' : 'Time of the last check (Unix timestamp)',
4869 'current_host_last_hard_state' : {
4870 'description' : 'Last hard state',
4873 'current_host_last_hard_state_change' : {
4874 'description' : 'Time of the last hard state change (Unix timestamp)',
4877 'current_host_last_notification' : {
4878 'description' : 'Time of the last notification (Unix timestamp)',
4881 'current_host_last_state' : {
4882 'description' : 'State before last state change',
4885 'current_host_last_state_change' : {
4886 'description' : 'Time of the last state change - soft or hard (Unix timestamp)',
4889 'current_host_latency' : {
4890 'description' : 'Time difference between scheduled check time and actual check time',
4893 'current_host_long_plugin_output' : {
4894 'description' : 'Complete output from check plugin',
4897 'current_host_low_flap_threshold' : {
4898 'description' : 'Low threshold of flap detection',
4901 'current_host_max_check_attempts' : {
4902 'description' : 'Max check attempts for active host checks',
4905 'current_host_name' : {
4907 'depythonize' : lambda x
: x
.get_name(),
4908 'description' : 'Host name',
4909 'prop' : 'log_host',
4912 'current_host_next_check' : {
4913 'description' : 'Scheduled time for the next check (Unix timestamp)',
4916 'current_host_next_notification' : {
4917 'description' : 'Time of the next notification (Unix timestamp)',
4920 'current_host_notes' : {
4921 'description' : 'Optional notes for this host',
4924 'current_host_notes_expanded' : {
4925 'description' : 'The same as notes, but with the most important macros expanded',
4928 'current_host_notes_url' : {
4929 'description' : 'An optional URL with further information about the host',
4932 'current_host_notes_url_expanded' : {
4933 'description' : 'Same es notes_url, but with the most important macros expanded',
4936 'current_host_notification_interval' : {
4937 'description' : 'Interval of periodic notification or 0 if its off',
4940 'current_host_notification_period' : {
4941 'description' : 'Time period in which problems of this host will be notified. If empty then notification will be always',
4944 'current_host_notifications_enabled' : {
4945 'description' : 'Wether notifications of the host are enabled (0/1)',
4948 'current_host_num_services' : {
4949 'description' : 'The total number of services of the host',
4952 'current_host_num_services_crit' : {
4953 'description' : 'The number of the host\'s services with the soft state CRIT',
4956 'current_host_num_services_hard_crit' : {
4957 'description' : 'The number of the host\'s services with the hard state CRIT',
4960 'current_host_num_services_hard_ok' : {
4961 'description' : 'The number of the host\'s services with the hard state OK',
4964 'current_host_num_services_hard_unknown' : {
4965 'description' : 'The number of the host\'s services with the hard state UNKNOWN',
4968 'current_host_num_services_hard_warn' : {
4969 'description' : 'The number of the host\'s services with the hard state WARN',
4972 'current_host_num_services_ok' : {
4973 'description' : 'The number of the host\'s services with the soft state OK',
4976 'current_host_num_services_pending' : {
4977 'description' : 'The number of the host\'s services which have not been checked yet (pending)',
4980 'current_host_num_services_unknown' : {
4981 'description' : 'The number of the host\'s services with the soft state UNKNOWN',
4984 'current_host_num_services_warn' : {
4985 'description' : 'The number of the host\'s services with the soft state WARN',
4988 'current_host_obsess_over_host' : {
4989 'description' : 'The current obsess_over_host setting... (0/1)',
4992 'current_host_parents' : {
4993 'description' : 'A list of all direct parents of the host',
4996 'current_host_pending_flex_downtime' : {
4997 'description' : 'Wether a flex downtime is pending (0/1)',
5000 'current_host_percent_state_change' : {
5001 'description' : 'Percent state change',
5004 'current_host_perf_data' : {
5005 'description' : 'Optional performance data of the last host check',
5008 'current_host_plugin_output' : {
5009 'description' : 'Output of the last host check',
5012 'current_host_process_performance_data' : {
5013 'description' : 'Wether processing of performance data is enabled (0/1)',
5016 'current_host_retry_interval' : {
5017 'description' : 'Number of basic interval lengths between checks when retrying after a soft error',
5020 'current_host_scheduled_downtime_depth' : {
5021 'description' : 'The number of downtimes this host is currently in',
5024 'current_host_state' : {
5025 'description' : 'The current state of the host (0: up, 1: down, 2: unreachable)',
5028 'current_host_state_type' : {
5029 'description' : 'Type of the current state (0: soft, 1: hard)',
5032 'current_host_statusmap_image' : {
5033 'description' : 'The name of in image file for the status map',
5036 'current_host_total_services' : {
5037 'description' : 'The total number of services of the host',
5040 'current_host_worst_service_hard_state' : {
5041 'description' : 'The worst hard state of all of the host\'s services (OK <= WARN <= UNKNOWN <= CRIT)',
5044 'current_host_worst_service_state' : {
5045 'description' : 'The worst soft state of all of the host\'s services (OK <= WARN <= UNKNOWN <= CRIT)',
5048 'current_host_x_3d' : {
5049 'description' : '3D-Coordinates: X',
5052 'current_host_y_3d' : {
5053 'description' : '3D-Coordinates: Y',
5056 'current_host_z_3d' : {
5057 'description' : '3D-Coordinates: Z',
5060 'current_service_accept_passive_checks' : {
5061 'description' : 'Wether the service accepts passive checks (0/1)',
5064 'current_service_acknowledged' : {
5065 'description' : 'Wether the current service problem has been acknowledged (0/1)',
5068 'current_service_acknowledgement_type' : {
5069 'description' : 'The type of the acknownledgement (0: none, 1: normal, 2: sticky)',
5072 'current_service_action_url' : {
5073 'description' : 'An optional URL for actions or custom information about the service',
5076 'current_service_action_url_expanded' : {
5077 'description' : 'The action_url with (the most important) macros expanded',
5080 'current_service_active_checks_enabled' : {
5081 'description' : 'Wether active checks are enabled for the service (0/1)',
5084 'current_service_check_command' : {
5085 'description' : 'Nagios command used for active checks',
5088 'current_service_check_interval' : {
5089 'description' : 'Number of basic interval lengths between two scheduled checks of the service',
5092 'current_service_check_options' : {
5093 'description' : 'The current check option, forced, normal, freshness... (0/1)',
5096 'current_service_check_period' : {
5097 'description' : 'The name of the check period of the service. It this is empty, the service is always checked.',
5100 'current_service_check_type' : {
5101 'description' : 'The type of the last check (0: active, 1: passive)',
5104 'current_service_checks_enabled' : {
5105 'description' : 'Wether active checks are enabled for the service (0/1)',
5108 'current_service_comments' : {
5109 'description' : 'A list of all comment ids of the service',
5112 'current_service_contacts' : {
5113 'description' : 'A list of all contacts of the service, either direct or via a contact group',
5116 'current_service_current_attempt' : {
5117 'description' : 'The number of the current check attempt',
5120 'current_service_current_notification_number' : {
5121 'description' : 'The number of the current notification',
5124 'current_service_custom_variable_names' : {
5125 'description' : 'A list of the names of all custom variables of the service',
5128 'current_service_custom_variable_values' : {
5129 'description' : 'A list of the values of all custom variable of the service',
5132 'current_service_description' : {
5134 'depythonize' : lambda x
: x
.get_name(),
5135 'description' : 'Description of the service (also used as key)',
5136 'prop' : 'log_service',
5139 'current_service_display_name' : {
5140 'description' : 'An optional display name (not used by Nagios standard web pages)',
5143 'current_service_downtimes' : {
5144 'description' : 'A list of all downtime ids of the service',
5147 'current_service_event_handler' : {
5148 'description' : 'Nagios command used as event handler',
5151 'current_service_event_handler_enabled' : {
5152 'description' : 'Wether and event handler is activated for the service (0/1)',
5155 'current_service_execution_time' : {
5156 'description' : 'Time the host check needed for execution',
5159 'current_service_first_notification_delay' : {
5160 'description' : 'Delay before the first notification',
5163 'current_service_flap_detection_enabled' : {
5164 'description' : 'Wether flap detection is enabled for the service (0/1)',
5167 'current_service_groups' : {
5168 'description' : 'A list of all service groups the service is in',
5171 'current_service_has_been_checked' : {
5172 'description' : 'Wether the service already has been checked (0/1)',
5175 'current_service_high_flap_threshold' : {
5176 'description' : 'High threshold of flap detection',
5179 'current_service_icon_image' : {
5180 'description' : 'The name of an image to be used as icon in the web interface',
5183 'current_service_icon_image_alt' : {
5184 'description' : 'An alternative text for the icon_image for browsers not displaying icons',
5187 'current_service_icon_image_expanded' : {
5188 'description' : 'The icon_image with (the most important) macros expanded',
5191 'current_service_in_check_period' : {
5192 'description' : 'Wether the service is currently in its check period (0/1)',
5195 'current_service_in_notification_period' : {
5196 'description' : 'Wether the service is currently in its notification period (0/1)',
5199 'current_service_initial_state' : {
5200 'description' : 'The initial state of the service',
5203 'current_service_is_executing' : {
5204 'default' : 0, # value in scheduler is not real-time
5205 'description' : 'is there a service check currently running... (0/1)',
5208 'current_service_is_flapping' : {
5209 'description' : 'Wether the service is flapping (0/1)',
5212 'current_service_last_check' : {
5213 'description' : 'The time of the last check (Unix timestamp)',
5216 'current_service_last_hard_state' : {
5217 'description' : 'The last hard state of the service',
5220 'current_service_last_hard_state_change' : {
5221 'description' : 'The time of the last hard state change (Unix timestamp)',
5224 'current_service_last_notification' : {
5225 'description' : 'The time of the last notification (Unix timestamp)',
5228 'current_service_last_state' : {
5229 'description' : 'The last state of the service',
5232 'current_service_last_state_change' : {
5233 'description' : 'The time of the last state change (Unix timestamp)',
5236 'current_service_latency' : {
5237 'description' : 'Time difference between scheduled check time and actual check time',
5240 'current_service_long_plugin_output' : {
5241 'description' : 'Unabbreviated output of the last check plugin',
5244 'current_service_low_flap_threshold' : {
5245 'description' : 'Low threshold of flap detection',
5248 'current_service_max_check_attempts' : {
5249 'description' : 'The maximum number of check attempts',
5252 'current_service_next_check' : {
5253 'description' : 'The scheduled time of the next check (Unix timestamp)',
5256 'current_service_next_notification' : {
5257 'description' : 'The time of the next notification (Unix timestamp)',
5260 'current_service_notes' : {
5261 'description' : 'Optional notes about the service',
5264 'current_service_notes_expanded' : {
5265 'description' : 'The notes with (the most important) macros expanded',
5268 'current_service_notes_url' : {
5269 'description' : 'An optional URL for additional notes about the service',
5272 'current_service_notes_url_expanded' : {
5273 'description' : 'The notes_url with (the most important) macros expanded',
5276 'current_service_notification_interval' : {
5277 'description' : 'Interval of periodic notification or 0 if its off',
5280 'current_service_notification_period' : {
5281 'description' : 'The name of the notification period of the service. It this is empty, service problems are always notified.',
5284 'current_service_notifications_enabled' : {
5285 'description' : 'Wether notifications are enabled for the service (0/1)',
5288 'current_service_obsess_over_service' : {
5289 'description' : 'Wether \'obsess_over_service\' is enabled for the service (0/1)',
5292 'current_service_percent_state_change' : {
5293 'description' : 'Percent state change',
5296 'current_service_perf_data' : {
5297 'description' : 'Performance data of the last check plugin',
5300 'current_service_plugin_output' : {
5301 'description' : 'Output of the last check plugin',
5304 'current_service_process_performance_data' : {
5305 'description' : 'Wether processing of performance data is enabled for the service (0/1)',
5308 'current_service_retry_interval' : {
5309 'description' : 'Number of basic interval lengths between checks when retrying after a soft error',
5312 'current_service_scheduled_downtime_depth' : {
5313 'description' : 'The number of scheduled downtimes the service is currently in',
5316 'current_service_state' : {
5317 'description' : 'The current state of the service (0: OK, 1: WARN, 2: CRITICAL, 3: UNKNOWN)',
5320 'current_service_state_type' : {
5321 'description' : 'The type of the current state (0: soft, 1: hard)',
5325 'description' : 'The name of the host the log entry is about (might be empty)',
5329 'description' : 'The number of the line in the log file',
5333 'description' : 'The complete message line including the timestamp',
5337 'description' : 'The part of the message after the \':\'',
5341 'description' : 'The output of the check, if any is associated with the message',
5344 'service_description' : {
5345 'description' : 'The description of the service log entry is about (might be empty)',
5350 'description' : 'The state of the host or service in question',
5355 'description' : 'The type of the state (varies on different log classes)',
5360 'description' : 'Time of the log event (UNIX timestamp)',
5365 'description' : 'The type of the message (text before the colon), the message itself for info messages',
5372 separators
= map(lambda x
: chr(int(x
)), [10, 59, 44, 124])
5375 def __init__(self
, configs
, hostname_lookup_table
, servicename_lookup_table
, hosts
, services
, contacts
, hostgroups
, servicegroups
, contactgroups
, timeperiods
, commands
, schedulers
, pollers
, reactionners
, brokers
, dbconn
, pnp_path
, return_queue
):
5376 self
.configs
= configs
5377 self
.hostname_lookup_table
= hostname_lookup_table
5378 self
.servicename_lookup_table
= servicename_lookup_table
5380 self
.services
= services
5381 self
.contacts
= contacts
5382 self
.hostgroups
= hostgroups
5383 self
.servicegroups
= servicegroups
5384 self
.contactgroups
= contactgroups
5385 self
.timeperiods
= timeperiods
5386 self
.commands
= commands
5387 self
.schedulers
= schedulers
5388 self
.pollers
= pollers
5389 self
.reactionners
= reactionners
5390 self
.brokers
= brokers
5391 self
.dbconn
= dbconn
5392 LiveStatus
.pnp_path
= pnp_path
5394 self
.dbconn
.row_factory
= self
.row_factory
5395 self
.return_queue
= return_queue
5397 self
.create_out_map_delegates()
5398 self
.create_out_map_hooks()
5399 # add Host attributes to Hostsbygroup etc.
5400 for attribute
in LiveStatus
.out_map
['Host']:
5401 LiveStatus
.out_map
['Hostsbygroup'][attribute
] = LiveStatus
.out_map
['Host'][attribute
]
5402 for attribute
in self
.out_map
['Service']:
5403 LiveStatus
.out_map
['Servicesbygroup'][attribute
] = LiveStatus
.out_map
['Service'][attribute
]
5404 for attribute
in self
.out_map
['Service']:
5405 LiveStatus
.out_map
['Servicesbyhostgroup'][attribute
] = LiveStatus
.out_map
['Service'][attribute
]
5408 def row_factory(self
, cursor
, row
):
5409 """Handler for the sqlite fetch method."""
5410 return Logline(cursor
, row
)
5413 def handle_request(self
, data
):
5414 """Execute the livestatus request.
5416 This function creates a LiveStatusRequest method, calls the parser,
5417 handles the execution of the request and formatting of the result.
5420 request
= LiveStatusRequest(self
.configs
, self
.hostname_lookup_table
, self
.servicename_lookup_table
, self
.hosts
, self
.services
,
5421 self
.contacts
, self
.hostgroups
, self
.servicegroups
, self
.contactgroups
, self
.timeperiods
, self
.commands
,
5422 self
.schedulers
, self
.pollers
, self
.reactionners
, self
.brokers
, self
.dbconn
, self
.pnp_path
, self
.return_queue
)
5423 request
.parse_input(data
)
5424 print "REQUEST\n%s\n" % data
5426 result
= request
.launch_query()
5427 # Now bring the retrieved information to a form which can be sent back to the client
5428 response
= request
.response
5429 response
.format_live_data(result
, request
.columns
, request
.aliases
)
5430 output
, keepalive
= response
.respond()
5431 print "RESPONSE\n%s\n" % output
5432 print "DURATION %.4fs" % (time
.time() - request
.tic
)
5433 return output
, keepalive
5436 def make_hook(self
, hook
, prop
, default
, func
, as_prop
):
5439 def hook_get_prop(elt
):
5440 return getattr(elt
, prop
, default
)
5443 def hook_get_prop_depythonize(elt
):
5445 attr
= getattr(elt
, prop
)
5453 def hook_get_prop_depythonize_notcallable(elt
):
5454 if hasattr(elt
, prop
):
5455 value
= getattr(elt
, prop
)
5456 if value
== None or value
== 'none':
5458 elif isinstance(value
, list):
5459 # Example: Service['comments'] = { type : 'list', depythonize : 'id' }
5461 value
= [getattr(item
, func
)() for item
in value
if callable(getattr(item
, func
)) ] \
5462 + [getattr(item
, func
) for item
in value
if not callable(getattr(item
, func
)) ]
5465 f
= getattr(value
, func
)
5474 def hook_get_prop_full_depythonize(elt
):
5476 value
= getattr(elt
, prop
)
5479 if value
== None or value
== 'none':
5481 elif isinstance(value
, list):
5482 return [func(item
, elt
, self
) for item
in value
]
5484 return func(value
, elt
, self
)
5489 def hook_get_prop_delegate(elt
):
5494 if hasattr(elt
, func
):
5495 attr
= getattr(elt
, func
)
5498 new_hook
= self
.out_map
[attr
.__class
__.__name
__][new_prop
]['hook']
5499 return new_hook(attr
)
5504 if hook
== 'get_prop':
5505 return hook_get_prop
5506 elif hook
== 'get_prop_depythonize':
5507 return hook_get_prop_depythonize
5508 elif hook
== 'get_prop_depythonize_notcallable':
5509 return hook_get_prop_depythonize_notcallable
5510 elif hook
== 'get_prop_full_depythonize':
5511 return hook_get_prop_full_depythonize
5512 elif hook
== 'get_prop_delegate':
5513 return hook_get_prop_delegate
5516 def create_out_map_hooks(self
):
5517 """Add hooks to the elements of the LiveStatus.out_map.
5519 This function analyzes the elements of the out_map.
5520 Depending on the existence of several keys like
5521 default, prop, depythonize, etc. it creates a function which
5522 resolves an attribute as fast as possible and adds this function
5523 as a new key called hook.
5526 for objtype
in LiveStatus
.out_map
:
5527 for attribute
in LiveStatus
.out_map
[objtype
]:
5528 entry
= LiveStatus
.out_map
[objtype
][attribute
]
5529 if 'prop' not in entry
or entry
['prop'] == None:
5532 prop
= entry
['prop']
5533 if 'default' in entry
:
5534 default
= entry
['default']
5537 if entry
['type'] == 'int' or entry
['type'] == 'float':
5539 elif entry
['type'] == 'list':
5545 if 'delegate' in entry
:
5546 entry
['hook'] = self
.make_hook('get_prop_delegate', prop
, default
, entry
['delegate'], entry
.setdefault('as', None))
5548 if 'depythonize' in entry
:
5549 func
= entry
['depythonize']
5551 entry
['hook'] = self
.make_hook('get_prop_depythonize', prop
, default
, func
, None)
5553 entry
['hook'] = self
.make_hook('get_prop_depythonize_notcallable', prop
, default
, func
, None)
5554 elif 'fulldepythonize' in entry
:
5555 func
= entry
['fulldepythonize']
5556 entry
['hook'] = self
.make_hook('get_prop_full_depythonize', prop
, default
, func
, None)
5557 entry
['hooktype'] = 'depythonize'
5559 entry
['hook'] = self
.make_hook('get_prop', prop
, default
, None, None)
5562 def create_out_map_delegates(self
):
5563 """Add delegate keys for certain attributes.
5565 Some attributes are not directly reachable via prop or
5566 need a complicated depythonize function.
5567 Example: Logline (the objects created for a "GET log" request
5568 have the column current_host_state. The Logline object does
5569 not have an attribute of this name, but a log_host attribute.
5570 The Host object represented by log_host has an attribute state
5571 which is the desired current_host_state. Because it's the same
5572 for all columns starting with current_host, a rule can
5573 be applied that automatically redirects the resolving to the
5574 corresponding object. Instead of creating a complicated
5575 depythonize handler which gets log_host and then state, two new
5576 keys for Logline/current_host_state are added:
5579 This instructs the hook function to first get attribute state of
5580 the object represented by log_host.
5585 'current_service_' : 'log_service',
5586 'current_host_' : 'log_host',
5589 for objtype
in LiveStatus
.out_map
:
5590 for attribute
in LiveStatus
.out_map
[objtype
]:
5591 entry
= LiveStatus
.out_map
[objtype
][attribute
]
5592 if objtype
in delegate_map
:
5593 for prefix
in delegate_map
[objtype
]:
5594 if attribute
.startswith(prefix
):
5595 if 'delegate' not in entry
:
5596 entry
['delegate'] = delegate_map
[objtype
][prefix
]
5597 entry
['as'] = attribute
.replace(prefix
, '')
5601 class LiveStatusResponse
:
5603 """A class which represents the response to a livestatus request.
5606 respond -- Add a header to the response text
5607 format_live_data -- Take the raw output and format it according to
5608 the desired output format (csv or json)
5612 def __init__(self
, responseheader
= 'off', outputformat
= 'csv', keepalive
= 'off', columnheaders
= 'off', separators
= LiveStatus
.separators
):
5613 self
.responseheader
= responseheader
5614 self
.outputformat
= outputformat
5615 self
.keepalive
= keepalive
5616 self
.columnheaders
= columnheaders
5617 self
.separators
= separators
5624 if self
.responseheader
== 'fixed16':
5626 responselength
= len(self
.output
)
5627 self
.output
= '%3d %11d\n' % (statuscode
, responselength
) + self
.output
5629 return self
.output
, self
.keepalive
5632 def format_live_data(self
, result
, columns
, aliases
):
5637 if self
.columnheaders
!= 'off' or len(columns
) == 0:
5638 if len(aliases
) > 0:
5642 if len(columns
) == 0:
5643 # Show all available columns
5644 columns
= sorted(result
[0].keys())
5645 elif self
.columnheaders
== 'on':
5647 if self
.outputformat
== 'csv':
5648 for object in result
:
5649 # Construct one line of output for each object found
5651 for x
in [object[c
] for c
in columns
]:
5652 if isinstance(x
, list):
5653 l
.append(self
.separators
[2].join(str(y
) for y
in x
))
5656 lines
.append(self
.separators
[1].join(l
))
5658 if len(aliases
) > 0:
5659 # This is for statements like "Stats: .... as alias_column
5660 lines
.insert(0, self
.separators
[1].join([aliases
[col
] for col
in columns
]))
5662 lines
.insert(0, self
.separators
[1].join(columns
))
5663 self
.output
= self
.separators
[0].join(lines
)
5664 elif self
.outputformat
== 'json' or self
.outputformat
== 'python':
5665 for object in result
:
5666 lines
.append([object[c
] for c
in columns
])
5667 if self
.columnheaders
== 'on':
5668 if len(aliases
) > 0:
5669 lines
.insert(0, [str(aliases
[col
]) for col
in columns
])
5671 lines
.insert(0, columns
)
5672 if self
.outputformat
== 'json':
5673 self
.output
= json
.dumps(lines
, separators
=(',', ':'))
5675 self
.output
= str(json
.loads(json
.dumps(lines
, separators
=(',', ':'))))
5678 class LiveStatusConstraints
:
5679 """ Represent the constraints applied on a livestatus request """
5680 def __init__(self
, filter_func
, out_map
, filter_map
, output_map
, without_filter
):
5681 self
.filter_func
= filter_func
5682 self
.out_map
= out_map
5683 self
.filter_map
= filter_map
5684 self
.output_map
= output_map
5685 self
.without_filter
= without_filter
5688 class LiveStatusRequest(LiveStatus
):
5690 """A class describing a livestatus request."""
5692 def __init__(self
, configs
, hostname_lookup_table
, servicename_lookup_table
, hosts
, services
, contacts
, hostgroups
, servicegroups
, contactgroups
, timeperiods
, commands
, schedulers
, pollers
, reactionners
, brokers
, dbconn
, pnp_path
, return_queue
):
5693 # Runtime data form the global LiveStatus object
5694 self
.configs
= configs
5695 self
.hostname_lookup_table
= hostname_lookup_table
5696 self
.servicename_lookup_table
= servicename_lookup_table
5698 self
.services
= services
5699 self
.contacts
= contacts
5700 self
.hostgroups
= hostgroups
5701 self
.servicegroups
= servicegroups
5702 self
.contactgroups
= contactgroups
5703 self
.timeperiods
= timeperiods
5704 self
.commands
= commands
5705 self
.schedulers
= schedulers
5706 self
.pollers
= pollers
5707 self
.reactionners
= reactionners
5708 self
.brokers
= brokers
5709 self
.dbconn
= dbconn
5710 self
.pnp_path
= pnp_path
5711 self
.return_queue
= return_queue
5713 # Private attributes for this specific request
5714 self
.response
= LiveStatusResponse(responseheader
= 'off', outputformat
= 'csv', keepalive
= 'off', columnheaders
= 'undef', separators
= LiveStatus
.separators
)
5717 self
.filtercolumns
= []
5718 self
.prefiltercolumns
= []
5719 self
.stats_group_by
= []
5720 self
.stats_columns
= []
5724 self
.out_map
= self
.copy_out_map_hooks()
5726 # Initialize the stacks which are needed for the Filter: and Stats:
5727 # filter- and count-operations
5728 self
.filter_stack
= LiveStatusStack()
5729 self
.sql_filter_stack
= LiveStatusStack()
5730 self
.sql_filter_stack
.type = 'sql'
5731 self
.stats_filter_stack
= LiveStatusStack()
5732 self
.stats_postprocess_stack
= LiveStatusStack()
5733 self
.stats_request
= False
5735 # Set a timestamp for this specific request
5736 self
.tic
= time
.time()
5737 # Clients can also send their local time with the request
5738 self
.client_localtime
= time
.time()
5741 def find_converter(self
, attribute
):
5742 """Return a function that converts textual numbers
5743 in the request to the correct data type"""
5744 out_map
= LiveStatus
.out_map
[self
.out_map_name
]
5745 if attribute
in out_map
and 'type' in out_map
[attribute
]:
5746 if out_map
[attribute
]['type'] == 'int':
5748 elif out_map
[attribute
]['type'] == 'float':
5753 def set_default_out_map_name(self
):
5754 """Translate the table name to the corresponding out_map key."""
5755 self
.out_map_name
= {
5757 'services' : 'Service',
5758 'hostgroups' : 'Hostgroup',
5759 'servicegroups' : 'Servicegroup',
5760 'contacts' : 'Contact',
5761 'contactgroups' : 'Contactgroup',
5762 'comments' : 'Comment',
5763 'downtimes' : 'Downtime',
5764 'commands' : 'Command',
5765 'timeperiods' : 'Timeperiod',
5766 'hostsbygroup' : 'Hostsbygroup',
5767 'servicesbygroup' : 'Servicesbygroup',
5768 'servicesbyhostgroup' : 'Servicesbyhostgroup',
5769 'status' : 'Config',
5771 'schedulers' : 'SchedulerLink',
5772 'pollers' : 'PollerLink',
5773 'reactionners' : 'ReactionnerLink',
5774 'brokers' : 'BrokerLink',
5775 'problems' : 'Problem',
5776 'columns' : 'Config', # just a dummy
5780 def copy_out_map_hooks(self
):
5781 """Update the hooks for some out_map entries.
5783 Livestatus columns which have a fulldepythonize postprocessor
5784 need an updated argument list. The third argument needs to
5785 be the request object. (When the out_map is first supplied
5786 with hooks, the third argument is the Livestatus object.)
5790 for objtype
in LiveStatus
.out_map
:
5791 new_map
[objtype
] = {}
5792 for attribute
in LiveStatus
.out_map
[objtype
]:
5793 new_map
[objtype
][attribute
] = {}
5794 entry
= LiveStatus
.out_map
[objtype
][attribute
]
5795 if 'hooktype' in entry
:
5796 if 'prop' not in entry
or entry
['prop'] == None:
5799 prop
= entry
['prop']
5800 if 'default' in entry
:
5801 default
= entry
['default']
5803 if entry
['type'] == 'int' or entry
['type'] == 'float':
5807 func
= entry
['fulldepythonize']
5808 new_map
[objtype
][attribute
]['hook'] = self
.make_hook('get_prop_full_depythonize', prop
, default
, func
, None)
5810 new_map
[objtype
][attribute
]['hook'] = entry
['hook']
5815 output
= "LiveStatusRequest:\n"
5816 for attr
in ["table", "columns", "filtercolumns", "prefiltercolumns", "aliases", "stats_group_by", "stats_request"]:
5817 output
+= "request %s: %s\n" % (attr
, getattr(self
, attr
))
5821 def split_command(self
, line
, splits
=1):
5822 """Create a list from the words of a line"""
5823 return line
.split(' ', splits
)
5826 def split_option(self
, line
, splits
=1):
5827 """Like split_commands, but converts numbers to int data type"""
5828 #x = [int(i) if i.isdigit() else i for i in [token.strip() for token in re.split(r"[\s]+", line, splits)]]
5829 x
= map (lambda i
: (i
.isdigit() and int(i
)) or i
, [token
.strip() for token
in re
.split(r
"[\s]+", line
, splits
)])
5833 def split_option_with_columns(self
, line
):
5834 """Split a line in a command and a list of words"""
5835 cmd
, columns
= self
.split_option(line
)
5836 return cmd
, [self
.strip_table_from_column(c
) for c
in re
.compile(r
'\s+').split(columns
)]
5839 def strip_table_from_column(self
, column
):
5840 """Cut off the table name, because it is possible
5841 to say service_state instead of state"""
5842 bygroupmatch
= re
.compile('(\w+)by.*group').search(self
.table
)
5844 return re
.sub(re
.sub('s$', '', bygroupmatch
.group(1)) + '_', '', column
, 1)
5846 return re
.sub(re
.sub('s$', '', self
.table
) + '_', '', column
, 1)
5849 def parse_input(self
, data
):
5850 """Parse the lines of a livestatus request.
5852 This function looks for keywords in input lines and
5853 sets the attributes of the request object
5856 for line
in [line
.strip() for line
in data
.splitlines()]:
5857 # Tools like NagVis send KEYWORK:option, and we prefer to have
5858 # a space folowing the :
5859 if ':' in line
and not ' ' in line
:
5860 line
= line
.replace(':', ': ')
5861 keyword
= line
.split(' ')[0].rstrip(':')
5862 if keyword
== 'GET': # Get the name of the base table
5863 cmd
, self
.table
= self
.split_command(line
)
5864 self
.set_default_out_map_name()
5865 elif keyword
== 'Columns': # Get the names of the desired columns
5866 cmd
, self
.columns
= self
.split_option_with_columns(line
)
5867 self
.response
.columnheaders
= 'off'
5868 elif keyword
== 'ResponseHeader':
5869 cmd
, responseheader
= self
.split_option(line
)
5870 self
.response
.responseheader
= responseheader
5871 elif keyword
== 'OutputFormat':
5872 cmd
, outputformat
= self
.split_option(line
)
5873 self
.response
.outputformat
= outputformat
5874 elif keyword
== 'KeepAlive':
5875 cmd
, keepalive
= self
.split_option(line
)
5876 self
.response
.keepalive
= keepalive
5877 elif keyword
== 'ColumnHeaders':
5878 cmd
, columnheaders
= self
.split_option(line
)
5879 self
.response
.columnheaders
= columnheaders
5880 elif keyword
== 'Limit':
5881 cmd
, self
.limit
= self
.split_option(line
)
5882 elif keyword
== 'Filter':
5884 cmd
, attribute
, operator
, reference
= self
.split_option(line
, 3)
5886 cmd
, attribute
, operator
, reference
= self
.split_option(line
, 2) + ['']
5887 if operator
in ['=', '>', '>=', '<', '<=', '=~', '~', '~~', '!=', '!>', '!>=', '!<', '!<=']:
5888 # Cut off the table name
5889 attribute
= self
.strip_table_from_column(attribute
)
5890 # Some operators can simply be negated
5891 if operator
in ['!>', '!>=', '!<', '!<=']:
5892 operator
= { '!>' : '<=', '!>=' : '<', '!<' : '>=', '!<=' : '>' }[operator
]
5893 # Put a function on top of the filter_stack which implements
5894 # the desired operation
5895 self
.filtercolumns
.append(attribute
)
5896 self
.prefiltercolumns
.append(attribute
)
5897 self
.filter_stack
.put(self
.make_filter(operator
, attribute
, reference
))
5898 if self
.table
== 'log':
5899 if attribute
== 'time':
5900 self
.sql_filter_stack
.put(self
.make_sql_filter(operator
, attribute
, reference
))
5902 print "illegal operation", operator
5903 pass # illegal operation
5904 elif keyword
== 'And':
5905 cmd
, andnum
= self
.split_option(line
)
5906 # Take the last andnum functions from the stack
5907 # Construct a new function which makes a logical and
5908 # Put the function back onto the stack
5909 self
.filter_stack
.and_elements(andnum
)
5910 elif keyword
== 'Or':
5911 cmd
, ornum
= self
.split_option(line
)
5912 # Take the last ornum functions from the stack
5913 # Construct a new function which makes a logical or
5914 # Put the function back onto the stack
5915 self
.filter_stack
.or_elements(ornum
)
5916 elif keyword
== 'StatsGroupBy':
5917 cmd
, stats_group_by
= self
.split_option_with_columns(line
)
5918 self
.filtercolumns
.extend(stats_group_by
)
5919 self
.stats_group_by
.extend(stats_group_by
)
5920 # Deprecated. If your query contains at least one Stats:-header
5921 # then Columns: has the meaning of the old StatsGroupBy: header
5922 elif keyword
== 'Stats':
5923 self
.stats_request
= True
5925 cmd
, attribute
, operator
, reference
= self
.split_option(line
, 3)
5926 if attribute
in ['sum', 'min', 'max', 'avg', 'std'] and reference
.find('as ', 3) != -1:
5927 attribute
, operator
= operator
, attribute
5928 asas
, alias
= reference
.split(' ')
5929 self
.aliases
.append(alias
)
5930 elif attribute
in ['sum', 'min', 'max', 'avg', 'std'] and reference
== '=':
5931 # Workaround for thruk-cmds like: Stats: sum latency =
5932 attribute
, operator
= operator
, attribute
5935 cmd
, attribute
, operator
= self
.split_option(line
, 3)
5936 if attribute
in ['sum', 'min', 'max', 'avg', 'std']:
5937 attribute
, operator
= operator
, attribute
5939 attribute
= self
.strip_table_from_column(attribute
)
5940 if operator
in ['=', '>', '>=', '<', '<=', '=~', '~', '~~', '!=', '!>', '!>=', '!<', '!<=']:
5941 if operator
in ['!>', '!>=', '!<', '!<=']:
5942 operator
= { '!>' : '<=', '!>=' : '<', '!<' : '>=', '!<=' : '>' }[operator
]
5943 self
.filtercolumns
.append(attribute
)
5944 self
.stats_columns
.append(attribute
)
5945 self
.stats_filter_stack
.put(self
.make_filter(operator
, attribute
, reference
))
5946 self
.stats_postprocess_stack
.put(self
.make_filter('count', attribute
, None))
5947 elif operator
in ['sum', 'min', 'max', 'avg', 'std']:
5948 self
.stats_columns
.append(attribute
)
5949 self
.stats_filter_stack
.put(self
.make_filter('dummy', attribute
, None))
5950 self
.stats_postprocess_stack
.put(self
.make_filter(operator
, attribute
, None))
5952 print "illegal operation", operator
5953 pass # illegal operation
5954 elif keyword
== 'StatsAnd':
5955 cmd
, andnum
= self
.split_option(line
)
5956 self
.stats_filter_stack
.and_elements(andnum
)
5957 elif keyword
== 'StatsOr':
5958 cmd
, ornum
= self
.split_option(line
)
5959 self
.stats_filter_stack
.or_elements(ornum
)
5960 elif keyword
== 'Separators':
5961 cmd
, sep1
, sep2
, sep3
, sep4
= line
.split(' ', 5)
5962 self
.response
.separators
= map(lambda x
: chr(int(x
)), [sep1
, sep2
, sep3
, sep4
])
5963 elif keyword
== 'Localtime':
5964 cmd
, self
.client_localtime
= self
.split_option(line
)
5965 elif keyword
== 'COMMAND':
5966 cmd
, self
.extcmd
= line
.split(' ', 1)
5968 # This line is not valid or not implemented
5969 print "Received a line of input which i can't handle : '%s'" % line
5973 def launch_query(self
):
5974 """Prepare the request object's filter stacks"""
5976 # External command are send back to broker
5977 e
= ExternalCommand(self
.extcmd
)
5978 self
.return_queue
.put(e
)
5981 # A minimal integrity check
5985 # Make columns unique
5986 self
.filtercolumns
= list(set(self
.filtercolumns
))
5987 self
.prefiltercolumns
= list(set(self
.prefiltercolumns
))
5988 self
.stats_columns
= list(set(self
.stats_columns
))
5990 if self
.stats_request
:
5991 if len(self
.columns
) > 0:
5992 # StatsGroupBy is deprecated. Columns: can be used instead
5993 self
.stats_group_by
= self
.columns
5994 elif len(self
.stats_group_by
) > 0:
5995 self
.columns
= self
.stats_group_by
+ self
.stats_columns
5996 #if len(self.stats_columns) > 0 and len(self.columns) == 0:
5997 if len(self
.stats_columns
) > 0:
5998 self
.columns
= self
.stats_columns
+ self
.columns
6000 # Make one big filter where the single filters are anded
6001 self
.filter_stack
.and_elements(self
.filter_stack
.qsize())
6003 # Remember the number of stats filters. We need these numbers as columns later.
6004 # But we need to ask now, because get_live_data() will empty the stack
6005 num_stats_filters
= self
.stats_filter_stack
.qsize()
6006 if self
.table
== 'log':
6007 self
.sql_filter_stack
.and_elements(self
.sql_filter_stack
.qsize())
6008 result
= self
.get_live_data_log()
6010 # If the pnpgraph_present column is involved, then check
6011 # with each request if the pnp perfdata path exists
6012 if 'pnpgraph_present' in self
.columns
+ self
.filtercolumns
+ self
.prefiltercolumns
and self
.pnp_path
and os
.access(self
.pnp_path
, os
.R_OK
):
6013 self
.pnp_path_readable
= True
6015 self
.pnp_path_readable
= False
6016 # Apply the filters on the broker's host/service/etc elements
6018 result
= self
.get_live_data()
6020 if self
.stats_request
:
6021 self
.columns
= range(num_stats_filters
)
6022 if self
.stats_group_by
:
6023 self
.columns
= tuple(list(self
.stats_group_by
) + list(self
.columns
))
6024 if len(self
.aliases
) == 0:
6025 #If there were Stats: staments without "as", show no column headers at all
6026 self
.response
.columnheaders
= 'off'
6028 self
.response
.columnheaders
= 'on'
6031 except Exception, e
:
6033 print "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
6035 traceback
.print_exc(32)
6036 print "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
6039 def get_hosts_or_services_livedata(self
, cs
, key
):
6040 objects
= getattr(self
, self
.table
)
6042 objects
= objects
.values()
6044 objects
= sorted(objects
.values(), key
=key
)
6046 self
.create_output(cs
.output_map
, y
) for y
in (
6048 if cs
.without_filter
or cs
.filter_func(self
.create_output(cs
.filter_map
, x
)))
6051 def get_hosts_livedata(self
, cs
):
6052 return self
.get_hosts_or_services_livedata(cs
, lambda k
: (k
.host_name
))
6054 def get_services_livedata(self
, cs
):
6055 return self
.get_hosts_or_services_livedata(cs
, lambda k
: (k
.host_name
, k
.service_description
))
6057 def get_simple_livedata(self
, cs
):
6058 objects
= getattr(self
, self
.table
)
6059 return [ self
.create_output(cs
.output_map
, obj
) for obj
in objects
.values() ]
6061 def get_filtered_livedata(self
, cs
):
6062 objects
= getattr(self
, self
.table
).values()
6063 if cs
.without_filter
:
6064 return [ y
for y
in [ self
.create_output(cs
.output_map
, x
) for x
in objects
] if cs
.filter_func(y
) ]
6065 res
= [ x
for x
in objects
if cs
.filter_func(self
.create_output(cs
.filter_map
, x
)) ]
6066 return [ self
.create_output(cs
.output_map
, x
) for x
in res
]
6068 def get_list_livedata(self
, cs
):
6070 if cs
.without_filter
:
6071 res
= [ self
.create_output(cs
.output_map
, y
) for y
in
6073 , [ getattr(x
, t
) for x
in self
.services
.values() + self
.hosts
.values()
6074 if len(getattr(x
, t
)) > 0 ]
6078 res
= [ c
for c
in reduce(list.__add
__
6079 , [ getattr(x
, t
) for x
in self
.services
.values() + self
.hosts
.values()
6080 if len(getattr(x
, t
)) > 0]
6083 if cs
.filter_func(self
.create_output(cs
.filter_map
, c
)) ]
6084 res
= [ self
.create_output(cs
.output_map
, x
) for x
in res
]
6088 def get_group_livedata(self
, cs
, objs
, an
, group_key
, member_key
):
6089 """ return a list of elements from a "group" of 'objs'. group can be a hostgroup or a servicegroup.
6090 objs: the objects to get elements from.
6091 an: the attribute name to set on result.
6092 group_key: the key to be used to sort the group members.
6093 member_key: the key to be used to sort each resulting element of a group member. """
6094 return [ self
.create_output(cs
.output_map
, x
) for x
in (
6096 setattr(og
[0], an
, og
[1]) or og
[0] for og
in (
6097 ( copy
.copy(item0
), inner_list0
[1]) for inner_list0
in (
6098 (sorted(sg1
.members
, key
= member_key
), sg1
) for sg1
in
6099 sorted([sg0
for sg0
in objs
if sg0
.members
], key
= group_key
)
6100 ) for item0
in inner_list0
[0]
6102 ) if (cs
.without_filter
or cs
.filter_func(self
.create_output(cs
.filter_map
, svc
))))
6105 def get_hostbygroups_livedata(self
, cs
):
6106 member_key
= lambda k
: k
.host_name
6107 group_key
= lambda k
: k
.hostgroup_name
6108 return self
.get_group_livedata(cs
, self
.hostgroups
.values(), 'hostgroup', group_key
, member_key
)
6110 def get_servicebygroups_livedata(self
, cs
):
6111 member_key
= lambda k
: k
.get_name()
6112 group_key
= lambda k
: k
.servicegroup_name
6113 return self
.get_group_livedata(cs
, self
.servicegroups
.values(), 'servicegroup', group_key
, member_key
)
6115 def get_problem_livedata(self
, cs
):
6116 # We will crate a problems list first with all problems and source in it
6117 # TODO : create with filter
6119 for h
in self
.hosts
.values():
6121 pb
= Problem(h
, h
.impacts
)
6123 for s
in self
.services
.values():
6125 pb
= Problem(s
, s
.impacts
)
6128 return [ self
.create_output(cs
.output_map
, pb
) for pb
in problems
]
6130 def get_status_livedata(self
, cs
):
6131 cs
.out_map
= self
.out_map
['Config']
6132 return [ self
.create_output(cs
.output_map
, c
) for c
in self
.configs
.values() ]
6134 def get_columns_livedata(self
, cs
):
6137 'description' : 'A description of the column' , 'name' : 'description' , 'table' : 'columns' , 'type' : 'string' })
6139 'description' : 'The name of the column within the table' , 'name' : 'name' , 'table' : 'columns' , 'type' : 'string' })
6141 'description' : 'The name of the table' , 'name' : 'table' , 'table' : 'columns' , 'type' : 'string' })
6143 'description' : 'The data type of the column (int, float, string, list)' , 'name' : 'type' , 'table' : 'columns' , 'type' : 'string' })
6144 tablenames
= { 'Host' : 'hosts', 'Service' : 'services', 'Hostgroup' : 'hostgroups', 'Servicegroup' : 'servicegroups', 'Contact' : 'contacts', 'Contactgroup' : 'contactgroups', 'Command' : 'commands', 'Downtime' : 'downtimes', 'Comment' : 'comments', 'Timeperiod' : 'timeperiods', 'Config' : 'status', 'Logline' : 'log', 'Statsbygroup' : 'statsgroupby', 'Hostsbygroup' : 'hostsbygroup', 'Servicesbygroup' : 'servicesbygroup', 'Servicesbyhostgroup' : 'servicesbyhostgroup' }
6145 for obj
in sorted(LiveStatus
.out_map
, key
=lambda x
: x
):
6146 if obj
in tablenames
:
6147 for attr
in LiveStatus
.out_map
[obj
]:
6148 if 'description' in LiveStatus
.out_map
[obj
][attr
] and LiveStatus
.out_map
[obj
][attr
]['description']:
6149 result
.append({ 'description' : LiveStatus
.out_map
[obj
][attr
]['description'], 'name' : attr
, 'table' : tablenames
[obj
], 'type' : LiveStatus
.out_map
[obj
][attr
]['type'] })
6151 result
.append({'description' : 'to_do_desc', 'name' : attr
, 'table' : tablenames
[obj
], 'type' : LiveStatus
.out_map
[obj
][attr
]['type'] })
6154 def get_servicebyhostgroups_livedata(self
, cs
):
6156 res
= [ self
.create_output(cs
.output_map
, x
) for x
in (
6158 setattr(svchgrp
[0], 'hostgroup', svchgrp
[1]) or svchgrp
[0] for svchgrp
in (
6159 # (service, hostgroup), (service, hostgroup), (service, hostgroup), ... service objects are individuals
6160 (copy
.copy(item1
), inner_list1
[1]) for inner_list1
in (
6161 # ([service, service, ...], hostgroup), ([service, ...], hostgroup), ... flattened by host. only if a host has services. sorted by service_description
6162 (sorted(item0
.services
, key
= lambda k
: k
.service_description
), inner_list0
[1]) for inner_list0
in (
6163 # ([host, host, ...], hostgroup), ([host, host, host, ...], hostgroup), ... sorted by host_name
6164 (sorted(hg1
.members
, key
= lambda k
: k
.host_name
), hg1
) for hg1
in # ([host, host], hg), ([host], hg),... hostgroup.members->explode->sort
6165 # hostgroups, sorted by hostgroup_name
6166 sorted([hg0
for hg0
in self
.hostgroups
.values() if hg0
.members
], key
= lambda k
: k
.hostgroup_name
)
6167 ) for item0
in inner_list0
[0] if item0
.services
6168 ) for item1
in inner_list1
[0]
6170 ) if (cs
.without_filter
or cs
.filter_func(self
.create_output(cs
.filter_map
, svc
)))
6175 objects_get_handlers
= {
6176 'hosts': get_hosts_livedata
,
6177 'services': get_services_livedata
,
6178 'commands': get_simple_livedata
,
6179 'schedulers': get_simple_livedata
,
6180 'brokers': get_simple_livedata
,
6181 'pollers': get_simple_livedata
,
6182 'reactionners': get_simple_livedata
,
6183 'contacts': get_filtered_livedata
,
6184 'hostgroups': get_filtered_livedata
,
6185 'servicegroups': get_filtered_livedata
,
6186 'downtimes': get_list_livedata
,
6187 'comments': get_list_livedata
,
6188 'hostsbygroup': get_hostbygroups_livedata
,
6189 'servicesbygroup': get_servicebygroups_livedata
,
6190 'problems': get_problem_livedata
,
6191 'status': get_status_livedata
,
6192 'columns': get_columns_livedata
,
6193 'servicesbyhostgroup': get_servicebyhostgroups_livedata
6196 def get_live_data(self
):
6197 """Find the objects which match the request.
6199 This function scans a list of objects (hosts, services, etc.) and
6200 applies the filter functions first. The remaining objects are
6201 converted to simple dicts which have only the keys that were
6202 requested through Column: attributes. """
6203 # We will use prefiltercolumns here for some serious speedup.
6204 # For example, if nagvis wants Filter: host_groups >= hgxy
6205 # we don't have to use the while list of hostgroups in
6206 # the innermost loop
6207 # Filter: host_groups >= linux-servers
6208 # host_groups is a service attribute
6209 # We can get all services of all hosts of all hostgroups and filter at the end
6210 # But it would save a lot of time to already filter the hostgroups. This means host_groups must be hard-coded
6211 # Also host_name, but then we must filter the second step.
6212 # And a mixture host_groups/host_name with FilterAnd/Or? Must have several filter functions
6214 handler
= self
.objects_get_handlers
.get(self
.table
, None)
6216 print("Got unhandled table: %s" % (self
.table
))
6219 # Get the function which implements the Filter: statements
6220 filter_func
= self
.filter_stack
.get_stack()
6221 out_map
= self
.out_map
[self
.out_map_name
]
6222 filter_map
= dict([(k
, out_map
.get(k
)) for k
in self
.filtercolumns
])
6223 output_map
= dict([(k
, out_map
.get(k
)) for k
in self
.columns
]) or out_map
6224 without_filter
= len(self
.filtercolumns
) == 0
6226 cs
= LiveStatusConstraints(filter_func
, out_map
, filter_map
, output_map
, without_filter
)
6227 res
= handler(self
, cs
)
6230 res
= res
[:self
.limit
]
6232 if self
.stats_request
:
6233 res
= self
.statsify_result(res
)
6238 def get_live_data_log(self
):
6239 """Like get_live_data, but for log objects"""
6240 filter_func
= self
.filter_stack
.get_stack()
6241 sql_filter_func
= self
.sql_filter_stack
.get_stack()
6242 out_map
= self
.out_map
[self
.out_map_name
]
6243 filter_map
= dict([(k
, out_map
.get(k
)) for k
in self
.filtercolumns
])
6244 output_map
= dict([(k
, out_map
.get(k
)) for k
in self
.columns
]) or out_map
6245 without_filter
= len(self
.filtercolumns
) == 0
6247 if self
.table
== 'log':
6248 out_map
= self
.out_map
['Logline']
6249 # We can apply the filterstack here as well. we have columns and filtercolumns.
6250 # the only additional step is to enrich log lines with host/service-attributes
6251 # A timerange can be useful for a faster preselection of lines
6252 filter_clause
, filter_values
= sql_filter_func()
6253 c
= self
.dbconn
.cursor()
6255 if sqlite3
.paramstyle
== 'pyformat':
6257 for m
in re
.finditer(r
"\?", filter_clause
):
6258 filter_clause
= re
.sub('\\?', '%(' + str(matchcount
) + ')s', filter_clause
, 1)
6260 filter_values
= dict(zip([str(x
) for x
in xrange(len(filter_values
))], filter_values
))
6261 c
.execute('SELECT * FROM logs WHERE %s' % filter_clause
, filter_values
)
6262 except sqlite3
.Error
, e
:
6263 print "An error occurred:", e
.args
[0]
6264 dbresult
= c
.fetchall()
6265 if sqlite3
.paramstyle
== 'pyformat':
6266 dbresult
= [self
.row_factory(c
, d
) for d
in dbresult
]
6268 prefiltresult
= [y
for y
in (x
.fill(self
.hosts
, self
.services
, self
.hostname_lookup_table
, self
.servicename_lookup_table
, set(self
.columns
+ self
.filtercolumns
)) for x
in dbresult
) if (without_filter
or filter_func(self
.create_output(filter_map
, y
)))]
6269 filtresult
= [self
.create_output(output_map
, x
) for x
in prefiltresult
]
6270 if self
.stats_request
:
6271 result
= self
.statsify_result(filtresult
)
6273 # Results are host/service/etc dicts with the requested attributes
6274 # Columns: = keys of the dicts
6277 #print "result is", result
6281 def create_output(self
, out_map
, elt
):
6282 """Convert an object to a dict with selected keys."""
6284 display_attributes
= out_map
.keys()
6285 for display
in display_attributes
:
6287 hook
= out_map
[display
]['hook']
6291 output
[display
] = value
6295 def statsify_result(self
, filtresult
):
6296 """Applies the stats filter functions to the result.
6299 stats_group_by is ["service_description", "host_name"]
6300 filtresult is a list of elements which have, among others, service_description and host_name attributes
6303 groupedresult is a dict where the keys are unique combinations of the stats_group_by attributes
6304 where the values are arrays of elements which have those attributes in common
6306 groupedresult[("host1","svc1")] = { host_name : "host1", service_description : "svc1", state : 2, in_downtime : 0 }
6307 groupedresult[("host1","svc2")] = { host_name : "host1", service_description : "svc2", state : 0, in_downtime : 0 }
6308 groupedresult[("host1","svc2")] = { host_name : "host1", service_description : "svc2", state : 1, in_downtime : 1 }
6310 resultdict is a dict where the keys are unique combinations of the stats_group_by attributes
6311 where the values are dicts
6312 resultdict values are dicts where the keys are attribute names from stats_group_by
6313 where the values are attribute values
6315 resultdict[("host1","svc1")] = { host_name : "host1", service_description : "svc1" }
6316 resultdict[("host1","svc2")] = { host_name : "host1", service_description : "svc2" }
6317 These attributes are later used as output columns
6320 Run the filters (1 filter for each Stats: statement) and the postprocessors (default: len)
6321 The filters are numbered. After each run, add the result to resultdictay as <filterno> : <result>
6322 Example for Stats: state = 0\nStats: state = 1\nStats: state = 2\nStats: state = 3\n
6323 resultdict[("host1","svc1")] = { host_name : "host1", service_description : "svc1", 0 : 0, 1 : 0, 2 : 1, 3 : 0 }
6324 resultdict[("host1","svc2")] = { host_name : "host1", service_description : "svc2", 0 : 1, 1 : 1, 2 : 0, 3 : 0 }
6327 Create the final result array from resultdict
6332 if self
.stats_group_by
:
6333 # stats_group_by is a list in newer implementations
6334 if isinstance(self
.stats_group_by
, list):
6335 self
.stats_group_by
= tuple(self
.stats_group_by
)
6337 self
.stats_group_by
= tuple([self
.stats_group_by
])
6338 # Break up filtresult and prepare resultdict
6339 # rseultarr is not a simple array (for a single result line)
6340 # It is a dict with the statsgroupyby: as key
6342 for elem
in filtresult
:
6343 # Make a tuple consisting of the stats_group_by values
6344 stats_group_by_values
= tuple([elem
[c
] for c
in self
.stats_group_by
])
6345 if not stats_group_by_values
in groupedresult
:
6346 groupedresult
[stats_group_by_values
] = []
6347 groupedresult
[stats_group_by_values
].append(elem
)
6348 for group
in groupedresult
:
6349 # All possible combinations of stats_group_by values. group is a tuple
6350 resultdict
[group
] = dict(zip(self
.stats_group_by
, group
))
6352 #The number of Stats: statements
6353 #For each statement there is one function on the stack
6354 maxidx
= self
.stats_filter_stack
.qsize()
6355 for i
in range(maxidx
):
6356 # Stats:-statements were put on a Lifo, so we need to reverse the number
6357 #stats_number = str(maxidx - i - 1)
6358 stats_number
= maxidx
- i
- 1
6359 # First, get a filter for the attributes mentioned in Stats: statements
6360 filtfunc
= self
.stats_filter_stack
.get()
6361 # Then, postprocess (sum, max, min,...) the results
6362 postprocess
= self
.stats_postprocess_stack
.get()
6363 if self
.stats_group_by
:
6364 # Calc statistics over _all_ elements of groups
6365 # which share the same stats_filter_by
6366 for group
in groupedresult
:
6367 resultdict
[group
][stats_number
] = postprocess(filter(filtfunc
, groupedresult
[group
]))
6369 # Calc statistics over _all_ elements of filtresult
6370 resultdict
[stats_number
] = postprocess(filter(filtfunc
, filtresult
))
6371 if self
.stats_group_by
:
6372 for group
in resultdict
:
6373 result
.append(resultdict
[group
])
6375 # Without StatsGroupBy: we have only one line
6376 result
= [resultdict
]
6380 def make_filter(self
, operator
, attribute
, reference
):
6381 if reference
!= None:
6382 # Reference is now datatype string. The referring object attribute on the other hand
6383 # may be an integer. (current_attempt for example)
6384 # So for the filter to work correctly (the two values compared must be
6385 # of the same type), we need to convert the reference to the desired type
6386 converter
= self
.find_converter(attribute
)
6388 reference
= converter(reference
)
6390 # The filters are closures.
6391 # Add parameter Class (Host, Service), lookup datatype (default string), convert reference
6393 return ref
[attribute
] == reference
6395 def eq_nocase_filter(ref
):
6396 return ref
[attribute
].lower() == reference
.lower()
6399 return ref
[attribute
] != reference
6402 return ref
[attribute
] > reference
6405 return ref
[attribute
] >= reference
6408 return ref
[attribute
] < reference
6411 return ref
[attribute
] <= reference
6413 def contains_filter(ref
):
6414 return reference
in ref
[attribute
].split(',')
6416 def match_filter(ref
):
6417 p
= re
.compile(reference
)
6418 return p
.search(ref
[attribute
])
6420 def match_nocase_filter(ref
):
6421 p
= re
.compile(reference
, re
.I
)
6422 return p
.search(ref
[attribute
])
6424 def ge_contains_filter(ref
):
6425 if isinstance(ref
[attribute
], list):
6426 return reference
in ref
[attribute
]
6428 return ref
[attribute
] >= reference
6430 def dummy_filter(ref
):
6433 def count_postproc(ref
):
6436 def extract_postproc(ref
):
6437 return [float(obj
[attribute
]) for obj
in ref
]
6439 def sum_postproc(ref
):
6440 return sum(float(obj
[attribute
]) for obj
in ref
)
6442 def max_postproc(ref
):
6444 return max(float(obj
[attribute
]) for obj
in ref
)
6447 def min_postproc(ref
):
6449 return min(float(obj
[attribute
]) for obj
in ref
)
6452 def avg_postproc(ref
):
6454 return sum(float(obj
[attribute
]) for obj
in ref
) / len(ref
)
6457 def std_postproc(ref
):
6462 elif operator
== '!=':
6464 elif operator
== '>':
6466 elif operator
== '>=':
6467 return ge_contains_filter
6468 elif operator
== '<':
6470 elif operator
== '<=':
6472 elif operator
== '=~':
6473 return eq_nocase_filter
6474 elif operator
== '~':
6476 elif operator
== '~~':
6477 return match_nocase_filter
6478 elif operator
== 'dummy':
6480 elif operator
== 'sum':
6482 elif operator
== 'max':
6484 elif operator
== 'min':
6486 elif operator
== 'avg':
6488 elif operator
== 'std':
6490 elif operator
== 'count':
6491 # postprocess for stats
6492 return count_postproc
6493 elif operator
== 'extract':
6494 # postprocess for max,min,...
6495 return extract_postproc
6497 raise "wrong operation", operator
6500 def make_sql_filter(self
, operator
, attribute
, reference
):
6501 # The filters are text fragments which are put together to form a sql where-condition finally.
6502 # Add parameter Class (Host, Service), lookup datatype (default string), convert reference
6505 return ['%s IS NULL' % attribute
, ()]
6507 return ['%s = ?' % attribute
, (reference
, )]
6510 return ['%s IS NOT NULL' % attribute
, ()]
6512 return ['%s != ?' % attribute
, (reference
, )]
6514 return ['%s > ?' % attribute
, (reference
, )]
6516 return ['%s >= ?' % attribute
, (reference
, )]
6518 return ['%s < ?' % attribute
, (reference
, )]
6520 return ['%s <= ?' % attribute
, (reference
, )]
6522 return ['%s LIKE ?' % attribute
, ('%'+reference
+'%', )]
6527 if operator
== '>=':
6531 if operator
== '<=':
6533 if operator
== '!=':