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
39 from shinken
.objects
.service
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
290 LiveStatusStack
.__bases
__ = (Queue
.LifoQueue
,)
291 except AttributeError:
292 # Ptyhon 2.4 and 2.5 do not have it.
293 # Use our own implementation.
294 LiveStatusStack
.__bases
__ = (MyLifoQueue
,)
299 """A class that represents the status of all objects in the broker
302 # description (optional): no need to explain this
303 # prop (optional): the property of the object. If this is missing, the key is the property
304 # type (mandatory): int, float, string, list
305 # depythonize : use it if the property needs to be post-processed.
306 # fulldepythonize : the same, but the postprocessor takes three arguments. property, object, request
307 # delegate : get the property of a different object
308 # as : use it together with delegate, if the property of the other object has another name
311 'accept_passive_checks' : {
312 'depythonize' : from_bool_to_int
,
313 'description' : 'Wether passive host checks are accepted (0/1)',
314 'prop' : 'passive_checks_enabled',
318 'depythonize' : from_bool_to_int
,
319 'description' : 'Wether the current host problem has been acknowledged (0/1)',
320 'prop' : 'problem_has_been_acknowledged',
323 'acknowledgement_type' : {
324 'description' : 'Type of acknowledgement (0: none, 1: normal, 2: stick)',
328 'description' : 'An optional URL to custom actions or information about this host',
331 'action_url_expanded' : {
332 'fulldepythonize' : lambda p
, e
, r
: MacroResolver().resolve_simple_macros_in_string(p
, e
.get_data_for_checks()),
333 'description' : 'The same as action_url, but with the most important macros expanded',
334 'prop' : 'action_url',
337 'active_checks_enabled' : {
338 'depythonize' : from_bool_to_int
,
339 'description' : 'Wether active checks are enabled for the host (0/1)',
343 'description' : 'IP address',
347 'description' : 'An alias name for the host',
351 'depythonize' : 'call',
352 'description' : 'Nagios command for active host check of this host',
355 'check_freshness' : {
356 'depythonize' : from_bool_to_int
,
357 'description' : 'Wether freshness checks are activated (0/1)',
362 'description' : 'Number of basic interval lengths between two scheduled checks of the host',
366 'description' : 'The current check option, forced, normal, freshness... (0-2)',
370 'depythonize' : 'get_name',
371 'description' : 'Time period in which this host will be checked. If empty then the host will always be checked.',
376 'description' : 'Type of check (0: active, 1: passive)',
380 'depythonize' : from_bool_to_int
,
381 'description' : 'Wether checks of the host are enabled (0/1)',
382 'prop' : 'active_checks_enabled',
386 'description' : 'A list of all direct childs of the host',
391 'depythonize' : 'id',
392 'description' : 'A list of the ids of all comments of this host',
396 'depythonize' : 'contact_name',
397 'description' : 'A list of all contacts of this host, either direct or via a contact group',
400 'current_attempt' : {
403 'description' : 'Number of the current check attempts',
407 'current_notification_number' : {
409 'description' : 'Number of the current notification',
412 'custom_variable_names' : {
414 'description' : 'A list of the names of all custom variables',
416 'depythonize' : get_customs_keys
,
418 'custom_variable_values' : {
420 'description' : 'A list of the values of the custom variables',
422 'depythonize' : get_customs_values
,
425 'description' : 'Optional display name of the host - not used by Nagios\' web interface',
429 'description' : 'A list of the ids of all scheduled downtimes of this host',
432 'event_handler_enabled' : {
433 'depythonize' : from_bool_to_int
,
434 'description' : 'Wether event handling is enabled (0/1)',
439 'description' : 'Time the host check needed for execution',
442 'first_notification_delay' : {
444 'description' : 'Delay before the first notification',
447 'flap_detection_enabled' : {
448 'depythonize' : from_bool_to_int
,
449 'description' : 'Wether flap detection is enabled (0/1)',
452 'got_business_rule' : {
453 'depythonize' : from_bool_to_int
,
454 'description' : 'Wether the host state is an business rule based host or not (0/1)',
459 'depythonize' : to_split
,
460 'description' : 'A list of all host groups this host is in',
461 'prop' : 'hostgroups',
465 'description' : 'The effective hard state of the host (eliminates a problem in hard_state)',
468 'has_been_checked' : {
469 'depythonize' : from_bool_to_int
,
470 'description' : 'Wether the host has already been checked (0/1)',
473 'high_flap_threshold' : {
475 'description' : 'High threshold of flap detection',
479 'description' : 'The name of an image file to be used in the web pages',
483 'description' : 'Alternative text for the icon_image',
486 'icon_image_expanded' : {
487 'description' : 'The same as icon_image, but with the most important macros expanded',
490 'in_check_period' : {
491 'fulldepythonize' : lambda p
, e
, r
: from_bool_to_int((p
== None and [False] or [p
.is_time_valid(r
.tic
)])[0]),
492 'description' : 'Wether this host is currently in its check period (0/1)',
493 'prop' : 'check_period',
496 'in_notification_period' : {
497 'fulldepythonize' : lambda p
, e
, r
: from_bool_to_int((p
== None and [False] or [p
.is_time_valid(r
.tic
)])[0]),
498 'description' : 'Wether this host is currently in its notification period (0/1)',
499 'prop' : 'notification_period',
503 'description' : 'Initial host state',
507 'default' : 0, # value in scheduler is not real-time
508 'description' : 'is there a host check currently running... (0/1)',
509 #'prop' : 'in_checking',
513 'depythonize' : from_bool_to_int
,
514 'description' : 'Wether the host state is flapping (0/1)',
518 'depythonize' : from_bool_to_int
,
519 'description' : 'Wether the host state is an impact or not (0/1)',
523 'depythonize' : from_bool_to_int
,
524 'description' : 'Wether the host state is a problem or not (0/1)',
529 'depythonize' : from_float_to_int
,
530 'description' : 'Time of the last check (Unix timestamp)',
534 'last_hard_state' : {
535 'description' : 'Last hard state',
538 'last_hard_state_change' : {
539 'description' : 'Time of the last hard state change (Unix timestamp)',
542 'last_notification' : {
544 'depythonize' : to_int
,
545 'description' : 'Time of the last notification (Unix timestamp)',
549 'description' : 'State before last state change',
552 'last_state_change' : {
554 'depythonize' : from_float_to_int
,
555 'description' : 'Time of the last state change - soft or hard (Unix timestamp)',
560 'description' : 'Time difference between scheduled check time and actual check time',
563 'long_plugin_output' : {
564 'description' : 'Complete output from check plugin',
565 'prop' : 'long_output',
568 'low_flap_threshold' : {
569 'description' : 'Low threshold of flap detection',
572 'max_check_attempts' : {
573 'description' : 'Max check attempts for active host checks',
577 'description' : 'Host name',
578 'prop' : 'host_name',
583 'depythonize' : from_float_to_int
,
584 'description' : 'Scheduled time for the next check (Unix timestamp)',
588 'next_notification' : {
590 'description' : 'Time of the next notification (Unix timestamp)',
594 'description' : 'Optional notes for this host',
598 'description' : 'The same as notes, but with the most important macros expanded',
602 'description' : 'An optional URL with further information about the host',
605 'notes_url_expanded' : {
606 'fulldepythonize' : lambda p
, e
, r
: MacroResolver().resolve_simple_macros_in_string(p
, e
.get_data_for_checks()),
607 'description' : 'Same es notes_url, but with the most important macros expanded',
608 'prop' : 'notes_url',
611 'notification_interval' : {
613 'description' : 'Interval of periodic notification or 0 if its off',
616 'notification_period' : {
617 'depythonize' : 'get_name',
618 'description' : 'Time period in which problems of this host will be notified. If empty then notification will be always',
621 'notifications_enabled' : {
622 'depythonize' : from_bool_to_int
,
623 'description' : 'Wether notifications of the host are enabled (0/1)',
627 'depythonize' : lambda x
: len(x
),
628 'description' : 'The total number of services of the host',
632 'num_services_crit' : {
633 'depythonize' : lambda x
: len([y
for y
in x
if y
.state_id
== 2]),
634 'description' : 'The number of the host\'s services with the soft state CRIT',
638 'num_services_hard_crit' : {
639 'depythonize' : lambda x
: len([y
for y
in x
if y
.state_id
== 2 and y
.state_type_id
== 1]),
640 'description' : 'The number of the host\'s services with the hard state CRIT',
644 'num_services_hard_ok' : {
645 'depythonize' : lambda x
: len([y
for y
in x
if y
.state_id
== 0 and y
.state_type_id
== 1]),
646 'description' : 'The number of the host\'s services with the hard state OK',
650 'num_services_hard_unknown' : {
651 'depythonize' : lambda x
: len([y
for y
in x
if y
.state_id
== 3 and y
.state_type_id
== 1]),
652 'description' : 'The number of the host\'s services with the hard state UNKNOWN',
656 'num_services_hard_warn' : {
657 'depythonize' : lambda x
: len([y
for y
in x
if y
.state_id
== 2 and y
.state_type_id
== 1]),
658 'description' : 'The number of the host\'s services with the hard state WARN',
662 'num_services_ok' : {
663 'depythonize' : lambda x
: len([y
for y
in x
if y
.state_id
== 0]),
664 'description' : 'The number of the host\'s services with the soft state OK',
668 'num_services_pending' : {
669 'depythonize' : lambda x
: len([y
for y
in x
if y
.has_been_checked
== 0]),
670 'description' : 'The number of the host\'s services which have not been checked yet (pending)',
674 'num_services_unknown' : {
675 'depythonize' : lambda x
: len([y
for y
in x
if y
.state_id
== 3]),
676 'description' : 'The number of the host\'s services with the soft state UNKNOWN',
680 'num_services_warn' : {
681 'depythonize' : lambda x
: len([y
for y
in x
if y
.state_id
== 1]),
682 'description' : 'The number of the host\'s services with the soft state WARN',
686 'obsess_over_host' : {
687 'depythonize' : from_bool_to_int
,
688 'description' : 'The current obsess_over_host setting... (0/1)',
692 'description' : 'A list of all direct parents of the host',
695 'pending_flex_downtime' : {
696 'description' : 'Wether a flex downtime is pending (0/1)',
699 'percent_state_change' : {
700 'description' : 'Percent state change',
704 'description' : 'Optional performance data of the last host check',
708 'description' : 'Output of the last host check',
712 'pnpgraph_present' : {
713 'fulldepythonize' : find_pnp_perfdata_xml
,
714 'description' : 'Whether there is a PNP4Nagios graph present for this host (0/1)',
715 'prop' : 'host_name',
718 'process_performance_data' : {
719 'depythonize' : from_bool_to_int
,
720 'description' : 'Wether processing of performance data is enabled (0/1)',
721 'prop' : 'process_perf_data',
725 'description' : 'Number of basic interval lengths between checks when retrying after a soft error',
728 'scheduled_downtime_depth' : {
730 'description' : 'The number of downtimes this host is currently in',
735 'description' : 'The current state of the host (0: up, 1: down, 2: unreachable)',
741 'description' : 'Type of the current state (0: soft, 1: hard)',
742 'prop' : 'state_type_id',
745 'statusmap_image' : {
746 'description' : 'The name of in image file for the status map',
750 'description' : 'The total number of services of the host',
753 'worst_service_hard_state' : {
754 'description' : 'The worst hard state of all of the host\'s services (OK <= WARN <= UNKNOWN <= CRIT)',
757 'worst_service_state' : {
758 'description' : 'The worst soft state of all of the host\'s services (OK <= WARN <= UNKNOWN <= CRIT)',
762 'description' : '3D-Coordinates: X',
766 'description' : '3D-Coordinates: Y',
770 'description' : '3D-Coordinates: Z',
775 'description' : 'The importance we gave to this host between hte minimum 0 and the maximum 5',
778 'source_problems' : {
779 'description' : 'The name of the source problems (host or service)',
780 'prop' : 'source_problems',
782 'depythonize' : from_svc_hst_distinct_lists
,
785 'description' : 'List of what the source impact (list of hosts and services)',
788 'depythonize' : from_svc_hst_distinct_lists
,
790 'parent_dependencies' : {
791 'description' : 'List of the dependencies (logical, network or business one) of this host.',
792 'prop' : 'parent_dependencies',
794 'depythonize' : from_svc_hst_distinct_lists
,
796 'child_dependencies' : {
797 'description' : 'List of the host/service that depend on this host (logical, network or business one).',
798 'prop' : 'child_dependencies',
800 'depythonize' : from_svc_hst_distinct_lists
,
806 'accept_passive_checks' : {
807 'depythonize' : from_bool_to_int
,
808 'description' : 'Wether the service accepts passive checks (0/1)',
809 'prop' : 'passive_checks_enabled',
813 'depythonize' : from_bool_to_int
,
814 'description' : 'Wether the current service problem has been acknowledged (0/1)',
815 'prop' : 'problem_has_been_acknowledged',
818 'acknowledgement_type' : {
819 'description' : 'The type of the acknownledgement (0: none, 1: normal, 2: sticky)',
823 'description' : 'An optional URL for actions or custom information about the service',
826 'action_url_expanded' : {
827 'fulldepythonize' : lambda p
, e
, r
: MacroResolver().resolve_simple_macros_in_string(p
, e
.get_data_for_checks()),
828 'description' : 'The action_url with (the most important) macros expanded',
829 'prop' : 'action_url',
832 'active_checks_enabled' : {
833 'depythonize' : from_bool_to_int
,
834 'description' : 'Wether active checks are enabled for the service (0/1)',
838 'depythonize' : 'call',
839 'description' : 'Nagios command used for active checks',
843 'description' : 'Number of basic interval lengths between two scheduled checks of the service',
847 'description' : 'The current check option, forced, normal, freshness... (0/1)',
851 'depythonize' : 'get_name',
852 'description' : 'The name of the check period of the service. It this is empty, the service is always checked.',
857 'depythonize' : to_int
,
858 'description' : 'The type of the last check (0: active, 1: passive)',
862 'depythonize' : from_bool_to_int
,
863 'description' : 'Wether active checks are enabled for the service (0/1)',
864 'prop' : 'active_checks_enabled',
869 'depythonize' : 'id',
870 'description' : 'A list of all comment ids of the service',
874 'depythonize' : 'contact_name',
875 'description' : 'A list of all contacts of the service, either direct or via a contact group',
878 'current_attempt' : {
880 'description' : 'The number of the current check attempt',
884 'current_notification_number' : {
885 'description' : 'The number of the current notification',
888 'custom_variable_names' : {
890 'description' : 'A list of the names of all custom variables of the service',
892 'depythonize' : get_customs_keys
,
894 'custom_variable_values' : {
896 'description' : 'A list of the values of all custom variable of the service',
898 'depythonize' : get_customs_values
,
901 'description' : 'Description of the service (also used as key)',
902 'prop' : 'service_description',
906 'description' : 'An optional display name (not used by Nagios standard web pages)',
910 'description' : 'A list of all downtime ids of the service',
914 'depythonize' : 'call',
915 'description' : 'Nagios command used as event handler',
918 'event_handler_enabled' : {
919 'depythonize' : from_bool_to_int
,
920 'description' : 'Wether and event handler is activated for the service (0/1)',
925 'description' : 'Time the host check needed for execution',
928 'first_notification_delay' : {
930 'description' : 'Delay before the first notification',
933 'flap_detection_enabled' : {
934 'depythonize' : from_bool_to_int
,
935 'description' : 'Wether flap detection is enabled for the service (0/1)',
938 'got_business_rule' : {
939 'depythonize' : from_bool_to_int
,
940 'description' : 'Wether the service state is an business rule based host or not (0/1)',
945 'depythonize' : to_split
,
946 'description' : 'A list of all service groups the service is in',
947 'prop' : 'servicegroups',
950 'has_been_checked' : {
951 'depythonize' : from_bool_to_int
,
952 'description' : 'Wether the service already has been checked (0/1)',
955 'high_flap_threshold' : {
956 'description' : 'High threshold of flap detection',
959 'host_accept_passive_checks' : {
960 'description' : 'Wether passive host checks are accepted (0/1)',
963 'host_acknowledged' : {
964 'depythonize' : lambda x
: from_bool_to_int(x
.problem_has_been_acknowledged
),
965 'description' : 'Wether the current host problem has been acknowledged (0/1)',
969 'host_acknowledgement_type' : {
970 'description' : 'Type of acknowledgement (0: none, 1: normal, 2: stick)',
973 'host_action_url' : {
974 'description' : 'An optional URL to custom actions or information about this host',
977 'host_action_url_expanded' : {
978 'description' : 'The same as action_url, but with the most important macros expanded',
981 'host_active_checks_enabled' : {
982 'description' : 'Wether active checks are enabled for the host (0/1)',
986 'depythonize' : lambda x
: x
.address
,
987 'description' : 'IP address',
992 'depythonize' : lambda x
: x
.alias
,
993 'description' : 'An alias name for the host',
997 'host_check_command' : {
998 'description' : 'Nagios command for active host check of this host',
1001 'host_check_freshness' : {
1002 'description' : 'Wether freshness checks are activated (0/1)',
1005 'host_check_interval' : {
1006 'description' : 'Number of basic interval lengths between two scheduled checks of the host',
1009 'host_check_options' : {
1010 'description' : 'The current check option, forced, normal, freshness... (0-2)',
1013 'host_check_period' : {
1014 'description' : 'Time period in which this host will be checked. If empty then the host will always be checked.',
1017 'host_check_type' : {
1018 'description' : 'Type of check (0: active, 1: passive)',
1021 'host_checks_enabled' : {
1022 'depythonize' : lambda x
: from_bool_to_int(x
.active_checks_enabled
),
1023 'description' : 'Wether checks of the host are enabled (0/1)',
1028 'description' : 'A list of all direct childs of the host',
1033 'depythonize' : lambda h
: ([c
.id for c
in h
.comments
]),
1034 'description' : 'A list of the ids of all comments of this host',
1039 'description' : 'A list of all contacts of this host, either direct or via a contact group',
1042 'host_current_attempt' : {
1043 'description' : 'Number of the current check attempts',
1046 'host_current_notification_number' : {
1047 'description' : 'Number of the current notification',
1050 'host_custom_variable_names' : {
1051 'description' : 'A list of the names of all custom variables',
1052 'depythonize' : lambda h
: get_customs_keys(h
.customs
),
1056 'host_custom_variable_values' : {
1057 'description' : 'A list of the values of the custom variables',
1058 'depythonize' : lambda h
: get_customs_values(h
.customs
),
1062 'host_display_name' : {
1063 'description' : 'Optional display name of the host - not used by Nagios\' web interface',
1066 'host_downtimes' : {
1067 'description' : 'A list of the ids of all scheduled downtimes of this host',
1070 'host_event_handler_enabled' : {
1071 'description' : 'Wether event handling is enabled (0/1)',
1074 'host_execution_time' : {
1075 'description' : 'Time the host check needed for execution',
1078 'host_first_notification_delay' : {
1079 'description' : 'Delay before the first notification',
1082 'host_flap_detection_enabled' : {
1083 'description' : 'Wether flap detection is enabled (0/1)',
1088 'depythonize' : lambda x
: to_split(x
.hostgroups
),
1089 'description' : 'A list of all host groups this host is in',
1093 'host_hard_state' : {
1094 'description' : 'The effective hard state of the host (eliminates a problem in hard_state)',
1097 'host_has_been_checked' : {
1098 'depythonize' : lambda x
: from_bool_to_int(x
.has_been_checked
),
1099 'description' : 'Wether the host has already been checked (0/1)',
1103 'host_high_flap_threshold' : {
1104 'description' : 'High threshold of flap detection',
1107 'host_icon_image' : {
1108 'description' : 'The name of an image file to be used in the web pages',
1111 'host_icon_image_alt' : {
1112 'description' : 'Alternative text for the icon_image',
1115 'host_icon_image_expanded' : {
1116 'description' : 'The same as icon_image, but with the most important macros expanded',
1119 'host_in_check_period' : {
1120 'depythonize' : lambda h
: from_bool_to_int((h
.check_period
== None and [False] or [h
.check_period
.is_time_valid(time
.time())])[0]),
1121 'description' : 'Wether this host is currently in its check period (0/1)',
1125 'host_in_notification_period' : {
1126 'depythonize' : lambda h
: from_bool_to_int((h
.notification_period
== None and [False] or [h
.notification_period
.is_time_valid(time
.time())])[0]),
1127 'description' : 'Wether this host is currently in its notification period (0/1)',
1131 'host_initial_state' : {
1132 'description' : 'Initial host state',
1135 'host_is_executing' : {
1136 'default' : 0, # value in scheduler is not real-time
1137 'description' : 'is there a host check currently running... (0/1)',
1140 'host_is_flapping' : {
1142 'depythonize' : from_bool_to_int
,
1143 'description' : 'Wether the host state is flapping (0/1)',
1146 'host_last_check' : {
1147 'description' : 'Time of the last check (Unix timestamp)',
1150 'host_last_hard_state' : {
1151 'description' : 'Last hard state',
1154 'host_last_hard_state_change' : {
1155 'description' : 'Time of the last hard state change (Unix timestamp)',
1158 'host_last_notification' : {
1159 'description' : 'Time of the last notification (Unix timestamp)',
1162 'host_last_state' : {
1163 'description' : 'State before last state change',
1166 'host_last_state_change' : {
1167 'description' : 'Time of the last state change - soft or hard (Unix timestamp)',
1171 'description' : 'Time difference between scheduled check time and actual check time',
1174 'host_long_plugin_output' : {
1175 'description' : 'Complete output from check plugin',
1178 'host_low_flap_threshold' : {
1179 'description' : 'Low threshold of flap detection',
1182 'host_max_check_attempts' : {
1183 'description' : 'Max check attempts for active host checks',
1187 'description' : 'Host name',
1190 'host_next_check' : {
1191 'description' : 'Scheduled time for the next check (Unix timestamp)',
1194 'host_next_notification' : {
1195 'description' : 'Time of the next notification (Unix timestamp)',
1199 'description' : 'Optional notes for this host',
1202 'host_notes_expanded' : {
1203 'description' : 'The same as notes, but with the most important macros expanded',
1206 'host_notes_url' : {
1207 'description' : 'An optional URL with further information about the host',
1210 'host_notes_url_expanded' : {
1211 'description' : 'Same es notes_url, but with the most important macros expanded',
1214 'host_notification_interval' : {
1215 'description' : 'Interval of periodic notification or 0 if its off',
1218 'host_notification_period' : {
1219 'description' : 'Time period in which problems of this host will be notified. If empty then notification will be always',
1222 'host_notifications_enabled' : {
1223 'depythonize' : lambda x
: from_bool_to_int(x
.notifications_enabled
),
1224 'description' : 'Wether notifications of the host are enabled (0/1)',
1228 'host_num_services' : {
1229 'depythonize' : lambda x
: len(x
.services
),
1230 'description' : 'The total number of services of the host',
1234 'host_num_services_crit' : {
1235 'depythonize' : lambda x
: len([y
for y
in x
.services
if y
.state_id
== 2]),
1236 'description' : 'The number of the host\'s services with the soft state CRIT',
1240 'host_num_services_hard_crit' : {
1241 'depythonize' : lambda x
: len([y
for y
in x
.services
if y
.state_id
== 2 and y
.state_type_id
== 1]),
1242 'description' : 'The number of the host\'s services with the hard state CRIT',
1246 'host_num_services_hard_ok' : {
1247 'depythonize' : lambda x
: len([y
for y
in x
.services
if y
.state_id
== 0 and y
.state_type_id
== 1]),
1248 'description' : 'The number of the host\'s services with the hard state OK',
1252 'host_num_services_hard_unknown' : {
1253 'depythonize' : lambda x
: len([y
for y
in x
.services
if y
.state_id
== 3 and y
.state_type_id
== 1]),
1254 'description' : 'The number of the host\'s services with the hard state UNKNOWN',
1258 'host_num_services_hard_warn' : {
1259 'depythonize' : lambda x
: len([y
for y
in x
.services
if y
.state_id
== 2 and y
.state_type_id
== 1]),
1260 'description' : 'The number of the host\'s services with the hard state WARN',
1264 'host_num_services_ok' : {
1265 'depythonize' : lambda x
: len([y
for y
in x
.services
if y
.state_id
== 0]),
1266 'description' : 'The number of the host\'s services with the soft state OK',
1270 'host_num_services_pending' : {
1271 'depythonize' : lambda x
: len([y
for y
in x
.services
if y
.has_been_checked
== 0]),
1272 'description' : 'The number of the host\'s services which have not been checked yet (pending)',
1276 'host_num_services_unknown' : {
1277 'depythonize' : lambda x
: len([y
for y
in x
.services
if y
.state_id
== 3]),
1278 'description' : 'The number of the host\'s services with the soft state UNKNOWN',
1282 'host_num_services_warn' : {
1283 'depythonize' : lambda x
: len([y
for y
in x
.services
if y
.state_id
== 1]),
1284 'description' : 'The number of the host\'s services with the soft state WARN',
1288 'host_obsess_over_host' : {
1289 'description' : 'The current obsess_over_host setting... (0/1)',
1293 'description' : 'A list of all direct parents of the host',
1296 'host_pending_flex_downtime' : {
1297 'description' : 'Wether a flex downtime is pending (0/1)',
1300 'host_percent_state_change' : {
1301 'description' : 'Percent state change',
1304 'host_perf_data' : {
1305 'description' : 'Optional performance data of the last host check',
1308 'host_plugin_output' : {
1309 'description' : 'Output of the last host check',
1312 'host_process_performance_data' : {
1313 'description' : 'Wether processing of performance data is enabled (0/1)',
1316 'host_retry_interval' : {
1317 'description' : 'Number of basic interval lengths between checks when retrying after a soft error',
1320 'host_scheduled_downtime_depth' : {
1322 'depythonize' : lambda x
: x
.scheduled_downtime_depth
,
1323 'description' : 'The number of downtimes this host is currently in',
1329 'depythonize' : lambda x
: x
.state_id
,
1330 'description' : 'The current state of the host (0: up, 1: down, 2: unreachable)',
1334 'host_state_type' : {
1335 'description' : 'Type of the current state (0: soft, 1: hard)',
1338 'host_statusmap_image' : {
1339 'description' : 'The name of in image file for the status map',
1342 'host_total_services' : {
1343 'description' : 'The total number of services of the host',
1346 'host_worst_service_hard_state' : {
1347 'description' : 'The worst hard state of all of the host\'s services (OK <= WARN <= UNKNOWN <= CRIT)',
1350 'host_worst_service_state' : {
1351 'description' : 'The worst soft state of all of the host\'s services (OK <= WARN <= UNKNOWN <= CRIT)',
1355 'description' : '3D-Coordinates: X',
1359 'description' : '3D-Coordinates: Y',
1363 'description' : '3D-Coordinates: Z',
1367 'description' : 'The name of an image to be used as icon in the web interface',
1370 'icon_image_alt' : {
1371 'description' : 'An alternative text for the icon_image for browsers not displaying icons',
1374 'icon_image_expanded' : {
1375 'description' : 'The icon_image with (the most important) macros expanded',
1378 'in_check_period' : {
1379 'depythonize' : lambda tp
: from_bool_to_int((tp
== None and [False] or [tp
.is_time_valid(time
.time())])[0]),
1380 'description' : 'Wether the service is currently in its check period (0/1)',
1381 'prop' : 'check_period',
1384 'in_notification_period' : {
1385 'depythonize' : lambda tp
: from_bool_to_int((tp
== None and [False] or [tp
.is_time_valid(time
.time())])[0]),
1386 'description' : 'Wether the service is currently in its notification period (0/1)',
1387 'prop' : 'notification_period',
1391 'description' : 'The initial state of the service',
1395 'default' : 0, # value in scheduler is not real-time
1396 'description' : 'is there a service check currently running... (0/1)',
1400 'depythonize' : from_bool_to_int
,
1401 'description' : 'Wether the service is flapping (0/1)',
1405 'depythonize' : from_bool_to_int
,
1406 'description' : 'Wether the host state is an impact or not (0/1)',
1410 'depythonize' : from_bool_to_int
,
1411 'description' : 'Wether the host state is a problem or not (0/1)',
1415 'depythonize' : from_float_to_int
,
1416 'description' : 'The time of the last check (Unix timestamp)',
1417 'prop' : 'last_chk',
1420 'last_hard_state' : {
1421 'description' : 'The last hard state of the service',
1424 'last_hard_state_change' : {
1425 'description' : 'The time of the last hard state change (Unix timestamp)',
1428 'last_notification' : {
1429 'depythonize' : to_int
,
1430 'description' : 'The time of the last notification (Unix timestamp)',
1434 'description' : 'The last state of the service',
1437 'last_state_change' : {
1438 'depythonize' : from_float_to_int
,
1439 'description' : 'The time of the last state change (Unix timestamp)',
1443 'depythonize' : to_int
,
1444 'description' : 'Time difference between scheduled check time and actual check time',
1447 'long_plugin_output' : {
1448 'description' : 'Unabbreviated output of the last check plugin',
1449 'prop' : 'long_output',
1452 'low_flap_threshold' : {
1453 'description' : 'Low threshold of flap detection',
1456 'max_check_attempts' : {
1457 'description' : 'The maximum number of check attempts',
1461 'depythonize' : from_float_to_int
,
1462 'description' : 'The scheduled time of the next check (Unix timestamp)',
1463 'prop' : 'next_chk',
1466 'next_notification' : {
1467 'description' : 'The time of the next notification (Unix timestamp)',
1471 'description' : 'Optional notes about the service',
1474 'notes_expanded' : {
1475 'description' : 'The notes with (the most important) macros expanded',
1479 'description' : 'An optional URL for additional notes about the service',
1482 'notes_url_expanded' : {
1483 'fulldepythonize' : lambda p
, e
, r
: MacroResolver().resolve_simple_macros_in_string(p
, e
.get_data_for_checks()),
1484 'description' : 'The notes_url with (the most important) macros expanded',
1485 'prop' : 'notes_url',
1488 'notification_interval' : {
1489 'description' : 'Interval of periodic notification or 0 if its off',
1492 'notification_period' : {
1493 'depythonize' : 'get_name',
1494 'description' : 'The name of the notification period of the service. It this is empty, service problems are always notified.',
1497 'notifications_enabled' : {
1498 'depythonize' : from_bool_to_int
,
1499 'description' : 'Wether notifications are enabled for the service (0/1)',
1502 'obsess_over_service' : {
1503 'depythonize' : from_bool_to_int
,
1504 'description' : 'Wether \'obsess_over_service\' is enabled for the service (0/1)',
1507 'percent_state_change' : {
1508 'description' : 'Percent state change',
1512 'description' : 'Performance data of the last check plugin',
1516 'description' : 'Output of the last check plugin',
1520 'pnpgraph_present' : {
1521 'fulldepythonize' : find_pnp_perfdata_xml
,
1522 'description' : 'Whether there is a PNP4Nagios graph present for this service (0/1)',
1523 'prop' : 'get_dbg_name',
1526 'process_performance_data' : {
1527 'depythonize' : from_bool_to_int
,
1528 'description' : 'Wether processing of performance data is enabled for the service (0/1)',
1529 'prop' : 'process_perf_data',
1532 'retry_interval' : {
1533 'description' : 'Number of basic interval lengths between checks when retrying after a soft error',
1536 'scheduled_downtime_depth' : {
1538 'description' : 'The number of scheduled downtimes the service is currently in',
1543 'description' : 'The current state of the service (0: OK, 1: WARN, 2: CRITICAL, 3: UNKNOWN)',
1544 'prop' : 'state_id',
1549 'description' : 'The type of the current state (0: soft, 1: hard)',
1550 'prop' : 'state_type_id',
1555 'description' : 'The importance we gave to this service between hte minimum 0 and the maximum 5',
1558 'source_problems' : {
1559 'description' : 'The name of the source problems (host or service)',
1560 'prop' : 'source_problems',
1562 'depythonize' : from_svc_hst_distinct_lists
,
1565 'description' : 'List of what the source impact (list of hosts and services)',
1568 'depythonize' : from_svc_hst_distinct_lists
,
1570 'parent_dependencies' : {
1571 'description' : 'List of the dependencies (logical, network or business one) of this service.',
1572 'prop' : 'parent_dependencies',
1574 'depythonize' : from_svc_hst_distinct_lists
,
1576 'child_dependencies' : {
1577 'description' : 'List of the host/service that depend on this service (logical, network or business one).',
1578 'prop' : 'child_dependencies',
1580 'depythonize' : from_svc_hst_distinct_lists
,
1587 'description' : 'An optional URL to custom actions or information about the hostgroup',
1591 'description' : 'An alias of the hostgroup',
1595 'depythonize' : 'get_name',
1596 'description' : 'A list of all host names that are members of the hostgroup',
1600 'description' : 'Name of the hostgroup',
1601 'prop' : 'hostgroup_name',
1605 'description' : 'Optional notes to the hostgroup',
1609 'description' : 'An optional URL with further information about the hostgroup',
1613 'depythonize' : lambda x
: len(x
),
1614 'description' : 'The total number of hosts in the group',
1615 'prop' : 'get_hosts',
1618 'num_hosts_down' : {
1619 'depythonize' : lambda x
: len([y
for y
in x
if y
.state_id
== 1]),
1620 'description' : 'The number of hosts in the group that are down',
1621 'prop' : 'get_hosts',
1624 'num_hosts_pending' : {
1625 'depythonize' : lambda x
: len([y
for y
in x
if y
.has_been_checked
== 0]),
1626 'description' : 'The number of hosts in the group that are pending',
1627 'prop' : 'get_hosts',
1630 'num_hosts_unreach' : {
1631 'depythonize' : lambda x
: len([y
for y
in x
if y
.state_id
== 2]),
1632 'description' : 'The number of hosts in the group that are unreachable',
1633 'prop' : 'get_hosts',
1637 'depythonize' : lambda x
: len([y
for y
in x
if y
.state_id
== 0]),
1638 'description' : 'The number of hosts in the group that are up',
1639 'prop' : 'get_hosts',
1643 'depythonize' : lambda x
: sum((len(y
.service_ids
) for y
in x
)),
1644 'description' : 'The total number of services of hosts in this group',
1645 'prop' : 'get_hosts',
1648 'num_services_crit' : {
1649 'depythonize' : lambda x
: len([z
for y
in x
for z
in y
.services
if z
.state_id
== 2]),
1650 'description' : 'The total number of services with the state CRIT of hosts in this group',
1651 'prop' : 'get_hosts',
1654 'num_services_hard_crit' : {
1655 '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]),
1656 'description' : 'The total number of services with the state CRIT of hosts in this group',
1657 'prop' : 'get_hosts',
1660 'num_services_hard_ok' : {
1661 '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]),
1662 'description' : 'The total number of services with the state OK of hosts in this group',
1663 'prop' : 'get_hosts',
1666 'num_services_hard_unknown' : {
1667 '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]),
1668 'description' : 'The total number of services with the state UNKNOWN of hosts in this group',
1669 'prop' : 'get_hosts',
1672 'num_services_hard_warn' : {
1673 '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]),
1674 'description' : 'The total number of services with the state WARN of hosts in this group',
1675 'prop' : 'get_hosts',
1678 'num_services_ok' : {
1679 'depythonize' : lambda x
: len([z
for y
in x
for z
in y
.services
if z
.state_id
== 0]),
1680 'description' : 'The total number of services with the state OK of hosts in this group',
1681 'prop' : 'get_hosts',
1684 'num_services_pending' : {
1685 'depythonize' : lambda x
: len([z
for y
in x
for z
in y
.services
if z
.has_been_checked
== 0]),
1686 'description' : 'The total number of services with the state Pending of hosts in this group',
1687 'prop' : 'get_hosts',
1690 'num_services_unknown' : {
1691 'depythonize' : lambda x
: len([z
for y
in x
for z
in y
.services
if z
.state_id
== 3]),
1692 'description' : 'The total number of services with the state UNKNOWN of hosts in this group',
1693 'prop' : 'get_hosts',
1696 'num_services_warn' : {
1697 'depythonize' : lambda x
: len([z
for y
in x
for z
in y
.services
if z
.state_id
== 1]),
1698 'description' : 'The total number of services with the state WARN of hosts in this group',
1699 'prop' : 'get_hosts',
1702 'worst_host_state' : {
1703 'depythonize' : lambda x
: reduce(worst_host_state
, (y
.state_id
for y
in x
), 0),
1704 'description' : 'The worst state of all of the groups\' hosts (UP <= UNREACHABLE <= DOWN)',
1705 'prop' : 'get_hosts',
1708 'worst_service_hard_state' : {
1709 '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),
1710 'description' : 'The worst state of all services that belong to a host of this group (OK <= WARN <= UNKNOWN <= CRIT)',
1711 'prop' : 'get_hosts',
1714 'worst_service_state' : {
1715 'depythonize' : lambda x
: reduce(worst_service_state
, (z
.state_id
for y
in x
for z
in y
.services
), 0),
1716 'description' : 'The worst state of all services that belong to a host of this group (OK <= WARN <= UNKNOWN <= CRIT)',
1717 'prop' : 'get_hosts',
1724 'description' : 'An optional URL to custom notes or actions on the service group',
1728 'description' : 'An alias of the service group',
1732 'fulldepythonize' : get_livestatus_full_name
,
1733 'description' : 'A list of all members of the service group as host/service pairs ',
1737 'description' : 'The name of the service group',
1738 'prop' : 'servicegroup_name',
1742 'description' : 'Optional additional notes about the service group',
1746 'description' : 'An optional URL to further notes on the service group',
1751 'depythonize' : lambda x
: len(x
),
1752 'description' : 'The total number of services in the group',
1753 'prop' : 'get_services',
1756 'num_services_crit' : {
1758 'depythonize' : lambda x
: len([y
for y
in x
if y
.state_id
== 2]),
1759 'description' : 'The number of services in the group that are CRIT',
1760 'prop' : 'get_services',
1763 'num_services_hard_crit' : {
1765 'depythonize' : lambda x
: len([y
for y
in x
if y
.state_id
== 2 and y
.state_type_id
== 1]),
1766 'description' : 'The number of services in the group that are CRIT',
1767 'prop' : 'get_services',
1770 'num_services_hard_ok' : {
1772 'depythonize' : lambda x
: len([y
for y
in x
if y
.state_id
== 0 and y
.state_type_id
== 1]),
1773 'description' : 'The number of services in the group that are OK',
1774 'prop' : 'get_services',
1777 'num_services_hard_unknown' : {
1779 'depythonize' : lambda x
: len([y
for y
in x
if y
.state_id
== 3 and y
.state_type_id
== 1]),
1780 'description' : 'The number of services in the group that are UNKNOWN',
1781 'prop' : 'get_services',
1784 'num_services_hard_warn' : {
1786 'depythonize' : lambda x
: len([y
for y
in x
if y
.state_id
== 2 and y
.state_type_id
== 1]),
1787 'description' : 'The number of services in the group that are WARN',
1788 'prop' : 'get_services',
1791 'num_services_ok' : {
1793 'depythonize' : lambda x
: len([y
for y
in x
if y
.state_id
== 0]),
1794 'description' : 'The number of services in the group that are OK',
1795 'prop' : 'get_services',
1798 'num_services_pending' : {
1800 'depythonize' : lambda x
: len([y
for y
in x
if y
.has_been_checked
== 0]),
1801 'description' : 'The number of services in the group that are PENDING',
1802 'prop' : 'get_services',
1805 'num_services_unknown' : {
1807 'depythonize' : lambda x
: len([y
for y
in x
if y
.state_id
== 3]),
1808 'description' : 'The number of services in the group that are UNKNOWN',
1809 'prop' : 'get_services',
1812 'num_services_warn' : {
1814 'depythonize' : lambda x
: len([y
for y
in x
if y
.state_id
== 1]),
1815 'description' : 'The number of services in the group that are WARN',
1816 'prop' : 'get_services',
1819 'worst_service_state' : {
1820 'depythonize' : lambda x
: reduce(worst_service_state
, (y
.state_id
for y
in x
), 0),
1821 'description' : 'The worst soft state of all of the groups services (OK <= WARN <= UNKNOWN <= CRIT)',
1822 'prop' : 'get_services',
1829 'description' : 'The additional field address1',
1833 'description' : 'The additional field address2',
1837 'description' : 'The additional field address3',
1841 'description' : 'The additional field address4',
1845 'description' : 'The additional field address5',
1849 'description' : 'The additional field address6',
1853 'description' : 'The full name of the contact',
1856 'can_submit_commands' : {
1857 'depythonize' : from_bool_to_int
,
1858 'description' : 'Wether the contact is allowed to submit commands (0/1)',
1861 'custom_variable_names' : {
1862 'description' : 'A list of all custom variables of the contact',
1865 'custom_variable_values' : {
1866 'description' : 'A list of the values of all custom variables of the contact',
1870 'description' : 'The email address of the contact',
1873 'host_notification_period' : {
1874 'depythonize' : 'get_name',
1875 'description' : 'The time period in which the contact will be notified about host problems',
1878 'host_notifications_enabled' : {
1879 'depythonize' : from_bool_to_int
,
1880 'description' : 'Wether the contact will be notified about host problems in general (0/1)',
1883 'in_host_notification_period' : {
1884 'depythonize' : from_bool_to_int
,
1885 'description' : 'Wether the contact is currently in his/her host notification period (0/1)',
1888 'in_service_notification_period' : {
1889 'depythonize' : from_bool_to_int
,
1890 'description' : 'Wether the contact is currently in his/her service notification period (0/1)',
1894 'description' : 'The login name of the contact person',
1895 'prop' : 'contact_name',
1899 'description' : 'The pager address of the contact',
1902 'service_notification_period' : {
1903 'depythonize' : 'get_name',
1904 'description' : 'The time period in which the contact will be notified about service problems',
1907 'service_notifications_enabled' : {
1908 'depythonize' : from_bool_to_int
,
1909 'description' : 'Wether the contact will be notified about service problems in general (0/1)',
1918 'description' : 'The alias of the contactgroup',
1922 'depythonize' : 'get_name',
1923 'description' : 'A list of all members of this contactgroup',
1927 'description' : 'The name of the contactgroup',
1928 'prop' : 'contactgroup_name',
1937 'description' : 'The alias of the timeperiod',
1941 'description' : 'The name of the timeperiod',
1942 'prop' : 'timeperiod_name',
1947 #All commands (checks + notifications)
1950 'description' : 'The shell command line',
1951 'prop' : 'command_line',
1955 'description' : 'The name of the command',
1956 'prop' : 'command_name',
1966 'description' : 'The name of the scheduler',
1967 'prop' : 'scheduler_name',
1971 'description' : 'The ip or dns adress ofthe scheduler',
1976 'description' : 'The TCP port of the scheduler',
1981 'description' : 'If the scheduler is a spare or not',
1982 'depythonize' : from_bool_to_int
,
1987 'description' : 'Weight (in terms of hosts) of the scheduler',
1992 'description' : 'If the scheduler is alive or not',
1994 'depythonize' : from_bool_to_int
,
2004 'description' : 'The name of the poller',
2005 'prop' : 'poller_name',
2009 'description' : 'The ip or dns adress of the poller',
2014 'description' : 'The TCP port of the poller',
2019 'description' : 'If the poller is a spare or not',
2020 'depythonize' : from_bool_to_int
,
2025 'description' : 'If the poller is alive or not',
2027 'depythonize' : from_bool_to_int
,
2034 'ReactionnerLink' : {
2036 'description' : 'The name of the reactionner',
2037 'prop' : 'reactionner_name',
2041 'description' : 'The ip or dns adress of the reactionner',
2046 'description' : 'The TCP port of the reactionner',
2051 'description' : 'If the reactionner is a spare or not',
2052 'depythonize' : from_bool_to_int
,
2057 'description' : 'If the reactionner is alive or not',
2059 'depythonize' : from_bool_to_int
,
2068 'description' : 'The name of the broker',
2069 'prop' : 'broker_name',
2073 'description' : 'The ip or dns adress of the broker',
2078 'description' : 'The TCP port of the broker',
2083 'description' : 'If the broker is a spare or not',
2084 'depythonize' : from_bool_to_int
,
2089 'description' : 'If the broker is alive or not',
2091 'depythonize' : from_bool_to_int
,
2100 'description' : 'The source name of the problem (host or service)',
2103 'fulldepythonize' : get_livestatus_full_name
2106 'description' : 'List of what the source impact (list of hosts and services)',
2109 'depythonize' : from_svc_hst_distinct_lists
,
2117 'default' : 'nobody',
2118 'description' : 'The contact that scheduled the downtime',
2124 'description' : 'A comment text',
2130 'description' : 'The duration of the downtime in seconds',
2136 'description' : 'The end time of the downtime as UNIX timestamp',
2142 'description' : 'The time the entry was made as UNIX timestamp',
2148 'depythonize' : from_bool_to_int
,
2149 'description' : 'A 1 if the downtime is fixed, a 0 if it is flexible',
2153 'host_accept_passive_checks' : {
2155 'description' : 'Wether passive host checks are accepted (0/1)',
2159 'host_acknowledged' : {
2161 'description' : 'Wether the current host problem has been acknowledged (0/1)',
2165 'host_acknowledgement_type' : {
2167 'description' : 'Type of acknowledgement (0: none, 1: normal, 2: stick)',
2171 'host_action_url' : {
2173 'description' : 'An optional URL to custom actions or information about this host',
2177 'host_action_url_expanded' : {
2179 'description' : 'The same as action_url, but with the most important macros expanded',
2183 'host_active_checks_enabled' : {
2185 'description' : 'Wether active checks are enabled for the host (0/1)',
2191 'description' : 'IP address',
2197 'description' : 'An alias name for the host',
2201 'host_check_command' : {
2203 'description' : 'Nagios command for active host check of this host',
2207 'host_check_freshness' : {
2209 'description' : 'Wether freshness checks are activated (0/1)',
2213 'host_check_interval' : {
2215 'description' : 'Number of basic interval lengths between two scheduled checks of the host',
2219 'host_check_options' : {
2221 'description' : 'The current check option, forced, normal, freshness... (0-2)',
2225 'host_check_period' : {
2227 'description' : 'Time period in which this host will be checked. If empty then the host will always be checked.',
2231 'host_check_type' : {
2233 'description' : 'Type of check (0: active, 1: passive)',
2237 'host_checks_enabled' : {
2239 'description' : 'Wether checks of the host are enabled (0/1)',
2245 'description' : 'A list of all direct childs of the host',
2251 'description' : 'A list of the ids of all comments of this host',
2257 'description' : 'A list of all contacts of this host, either direct or via a contact group',
2261 'host_current_attempt' : {
2263 'description' : 'Number of the current check attempts',
2267 'host_current_notification_number' : {
2269 'description' : 'Number of the current notification',
2273 'host_custom_variable_names' : {
2275 'description' : 'A list of the names of all custom variables',
2279 'host_custom_variable_values' : {
2281 'description' : 'A list of the values of the custom variables',
2285 'host_display_name' : {
2287 'description' : 'Optional display name of the host - not used by Nagios\' web interface',
2291 'host_downtimes' : {
2293 'description' : 'A list of the ids of all scheduled downtimes of this host',
2297 'host_event_handler_enabled' : {
2299 'description' : 'Wether event handling is enabled (0/1)',
2303 'host_execution_time' : {
2305 'description' : 'Time the host check needed for execution',
2309 'host_first_notification_delay' : {
2311 'description' : 'Delay before the first notification',
2315 'host_flap_detection_enabled' : {
2317 'description' : 'Wether flap detection is enabled (0/1)',
2323 'description' : 'A list of all host groups this host is in',
2327 'host_hard_state' : {
2329 'description' : 'The effective hard state of the host (eliminates a problem in hard_state)',
2333 'host_has_been_checked' : {
2335 'description' : 'Wether the host has already been checked (0/1)',
2339 'host_high_flap_threshold' : {
2341 'description' : 'High threshold of flap detection',
2345 'host_icon_image' : {
2347 'description' : 'The name of an image file to be used in the web pages',
2351 'host_icon_image_alt' : {
2353 'description' : 'Alternative text for the icon_image',
2357 'host_icon_image_expanded' : {
2359 'description' : 'The same as icon_image, but with the most important macros expanded',
2363 'host_in_check_period' : {
2365 'description' : 'Wether this host is currently in its check period (0/1)',
2369 'host_in_notification_period' : {
2371 'description' : 'Wether this host is currently in its notification period (0/1)',
2375 'host_initial_state' : {
2377 'description' : 'Initial host state',
2381 'host_is_executing' : {
2382 'default' : 0, # value in scheduler is not real-time
2383 'description' : 'is there a host check currently running... (0/1)',
2387 'host_is_flapping' : {
2389 'description' : 'Wether the host state is flapping (0/1)',
2393 'host_last_check' : {
2395 'description' : 'Time of the last check (Unix timestamp)',
2399 'host_last_hard_state' : {
2401 'description' : 'Last hard state',
2405 'host_last_hard_state_change' : {
2407 'description' : 'Time of the last hard state change (Unix timestamp)',
2411 'host_last_notification' : {
2413 'description' : 'Time of the last notification (Unix timestamp)',
2417 'host_last_state' : {
2419 'description' : 'State before last state change',
2423 'host_last_state_change' : {
2425 'description' : 'Time of the last state change - soft or hard (Unix timestamp)',
2431 'description' : 'Time difference between scheduled check time and actual check time',
2435 'host_long_plugin_output' : {
2437 'description' : 'Complete output from check plugin',
2441 'host_low_flap_threshold' : {
2443 'description' : 'Low threshold of flap detection',
2447 'host_max_check_attempts' : {
2449 'description' : 'Max check attempts for active host checks',
2455 'depythonize' : lambda x
: x
.host_name
,
2456 'description' : 'Host name',
2460 'host_next_check' : {
2462 'description' : 'Scheduled time for the next check (Unix timestamp)',
2466 'host_next_notification' : {
2468 'description' : 'Time of the next notification (Unix timestamp)',
2474 'description' : 'Optional notes for this host',
2478 'host_notes_expanded' : {
2480 'description' : 'The same as notes, but with the most important macros expanded',
2484 'host_notes_url' : {
2486 'description' : 'An optional URL with further information about the host',
2490 'host_notes_url_expanded' : {
2492 'description' : 'Same es notes_url, but with the most important macros expanded',
2496 'host_notification_interval' : {
2498 'description' : 'Interval of periodic notification or 0 if its off',
2502 'host_notification_period' : {
2504 'description' : 'Time period in which problems of this host will be notified. If empty then notification will be always',
2508 'host_notifications_enabled' : {
2510 'description' : 'Wether notifications of the host are enabled (0/1)',
2514 'host_num_services' : {
2516 'description' : 'The total number of services of the host',
2520 'host_num_services_crit' : {
2522 'description' : 'The number of the host\'s services with the soft state CRIT',
2526 'host_num_services_hard_crit' : {
2528 'description' : 'The number of the host\'s services with the hard state CRIT',
2532 'host_num_services_hard_ok' : {
2534 'description' : 'The number of the host\'s services with the hard state OK',
2538 'host_num_services_hard_unknown' : {
2540 'description' : 'The number of the host\'s services with the hard state UNKNOWN',
2544 'host_num_services_hard_warn' : {
2546 'description' : 'The number of the host\'s services with the hard state WARN',
2550 'host_num_services_ok' : {
2552 'description' : 'The number of the host\'s services with the soft state OK',
2556 'host_num_services_pending' : {
2558 'description' : 'The number of the host\'s services which have not been checked yet (pending)',
2562 'host_num_services_unknown' : {
2564 'description' : 'The number of the host\'s services with the soft state UNKNOWN',
2568 'host_num_services_warn' : {
2570 'description' : 'The number of the host\'s services with the soft state WARN',
2574 'host_obsess_over_host' : {
2576 'description' : 'The current obsess_over_host setting... (0/1)',
2582 'description' : 'A list of all direct parents of the host',
2586 'host_pending_flex_downtime' : {
2588 'description' : 'Wether a flex downtime is pending (0/1)',
2592 'host_percent_state_change' : {
2594 'description' : 'Percent state change',
2598 'host_perf_data' : {
2600 'description' : 'Optional performance data of the last host check',
2604 'host_plugin_output' : {
2606 'description' : 'Output of the last host check',
2610 'host_process_performance_data' : {
2612 'description' : 'Wether processing of performance data is enabled (0/1)',
2616 'host_retry_interval' : {
2618 'description' : 'Number of basic interval lengths between checks when retrying after a soft error',
2622 'host_scheduled_downtime_depth' : {
2624 'description' : 'The number of downtimes this host is currently in',
2630 'description' : 'The current state of the host (0: up, 1: down, 2: unreachable)',
2634 'host_state_type' : {
2636 'description' : 'Type of the current state (0: soft, 1: hard)',
2640 'host_statusmap_image' : {
2642 'description' : 'The name of in image file for the status map',
2646 'host_total_services' : {
2648 'description' : 'The total number of services of the host',
2652 'host_worst_service_hard_state' : {
2654 'description' : 'The worst hard state of all of the host\'s services (OK <= WARN <= UNKNOWN <= CRIT)',
2658 'host_worst_service_state' : {
2660 'description' : 'The worst soft state of all of the host\'s services (OK <= WARN <= UNKNOWN <= CRIT)',
2666 'description' : '3D-Coordinates: X',
2672 'description' : '3D-Coordinates: Y',
2678 'description' : '3D-Coordinates: Z',
2684 'description' : 'The id of the downtime',
2688 'service_accept_passive_checks' : {
2690 'description' : 'Wether the service accepts passive checks (0/1)',
2694 'service_acknowledged' : {
2696 'description' : 'Wether the current service problem has been acknowledged (0/1)',
2700 'service_acknowledgement_type' : {
2702 'description' : 'The type of the acknownledgement (0: none, 1: normal, 2: sticky)',
2706 'service_action_url' : {
2708 'description' : 'An optional URL for actions or custom information about the service',
2712 'service_action_url_expanded' : {
2714 'description' : 'The action_url with (the most important) macros expanded',
2718 'service_active_checks_enabled' : {
2720 'description' : 'Wether active checks are enabled for the service (0/1)',
2724 'service_check_command' : {
2726 'description' : 'Nagios command used for active checks',
2730 'service_check_interval' : {
2732 'description' : 'Number of basic interval lengths between two scheduled checks of the service',
2736 'service_check_options' : {
2738 'description' : 'The current check option, forced, normal, freshness... (0/1)',
2742 'service_check_period' : {
2744 'description' : 'The name of the check period of the service. It this is empty, the service is always checked.',
2748 'service_check_type' : {
2750 'description' : 'The type of the last check (0: active, 1: passive)',
2754 'service_checks_enabled' : {
2756 'description' : 'Wether active checks are enabled for the service (0/1)',
2760 'service_comments' : {
2762 'description' : 'A list of all comment ids of the service',
2766 'service_contacts' : {
2768 'description' : 'A list of all contacts of the service, either direct or via a contact group',
2772 'service_current_attempt' : {
2774 'description' : 'The number of the current check attempt',
2778 'service_current_notification_number' : {
2780 'description' : 'The number of the current notification',
2784 'service_custom_variable_names' : {
2786 'description' : 'A list of the names of all custom variables of the service',
2790 'service_custom_variable_values' : {
2792 'description' : 'A list of the values of all custom variable of the service',
2796 'service_description' : {
2798 'depythonize' : lambda x
: getattr(x
, 'service_description', ''),
2799 'description' : 'Description of the service (also used as key)',
2803 'service_display_name' : {
2805 'description' : 'An optional display name (not used by Nagios standard web pages)',
2809 'service_downtimes' : {
2811 'description' : 'A list of all downtime ids of the service',
2815 'service_event_handler' : {
2817 'description' : 'Nagios command used as event handler',
2821 'service_event_handler_enabled' : {
2823 'description' : 'Wether and event handler is activated for the service (0/1)',
2827 'service_execution_time' : {
2829 'description' : 'Time the host check needed for execution',
2833 'service_first_notification_delay' : {
2835 'description' : 'Delay before the first notification',
2839 'service_flap_detection_enabled' : {
2841 'description' : 'Wether flap detection is enabled for the service (0/1)',
2845 'service_groups' : {
2847 'description' : 'A list of all service groups the service is in',
2851 'service_has_been_checked' : {
2853 'description' : 'Wether the service already has been checked (0/1)',
2857 'service_high_flap_threshold' : {
2859 'description' : 'High threshold of flap detection',
2863 'service_icon_image' : {
2865 'description' : 'The name of an image to be used as icon in the web interface',
2869 'service_icon_image_alt' : {
2871 'description' : 'An alternative text for the icon_image for browsers not displaying icons',
2875 'service_icon_image_expanded' : {
2877 'description' : 'The icon_image with (the most important) macros expanded',
2881 'service_in_check_period' : {
2883 'description' : 'Wether the service is currently in its check period (0/1)',
2887 'service_in_notification_period' : {
2889 'description' : 'Wether the service is currently in its notification period (0/1)',
2893 'service_initial_state' : {
2895 'description' : 'The initial state of the service',
2899 'service_is_executing' : {
2900 'default' : 0, # value in scheduler is not real-time
2901 'description' : 'is there a service check currently running... (0/1)',
2905 'service_is_flapping' : {
2907 'description' : 'Wether the service is flapping (0/1)',
2911 'service_last_check' : {
2913 'description' : 'The time of the last check (Unix timestamp)',
2917 'service_last_hard_state' : {
2919 'description' : 'The last hard state of the service',
2923 'service_last_hard_state_change' : {
2925 'description' : 'The time of the last hard state change (Unix timestamp)',
2929 'service_last_notification' : {
2931 'description' : 'The time of the last notification (Unix timestamp)',
2935 'service_last_state' : {
2937 'description' : 'The last state of the service',
2941 'service_last_state_change' : {
2943 'description' : 'The time of the last state change (Unix timestamp)',
2947 'service_latency' : {
2949 'description' : 'Time difference between scheduled check time and actual check time',
2953 'service_long_plugin_output' : {
2955 'description' : 'Unabbreviated output of the last check plugin',
2959 'service_low_flap_threshold' : {
2961 'description' : 'Low threshold of flap detection',
2965 'service_max_check_attempts' : {
2967 'description' : 'The maximum number of check attempts',
2971 'service_next_check' : {
2973 'description' : 'The scheduled time of the next check (Unix timestamp)',
2977 'service_next_notification' : {
2979 'description' : 'The time of the next notification (Unix timestamp)',
2985 'description' : 'Optional notes about the service',
2989 'service_notes_expanded' : {
2991 'description' : 'The notes with (the most important) macros expanded',
2995 'service_notes_url' : {
2997 'description' : 'An optional URL for additional notes about the service',
3001 'service_notes_url_expanded' : {
3003 'description' : 'The notes_url with (the most important) macros expanded',
3007 'service_notification_interval' : {
3009 'description' : 'Interval of periodic notification or 0 if its off',
3013 'service_notification_period' : {
3015 'description' : 'The name of the notification period of the service. It this is empty, service problems are always notified.',
3019 'service_notifications_enabled' : {
3021 'description' : 'Wether notifications are enabled for the service (0/1)',
3025 'service_obsess_over_service' : {
3027 'description' : 'Wether \'obsess_over_service\' is enabled for the service (0/1)',
3031 'service_percent_state_change' : {
3033 'description' : 'Percent state change',
3037 'service_perf_data' : {
3039 'description' : 'Performance data of the last check plugin',
3043 'service_plugin_output' : {
3045 'description' : 'Output of the last check plugin',
3049 'service_process_performance_data' : {
3051 'description' : 'Wether processing of performance data is enabled for the service (0/1)',
3055 'service_retry_interval' : {
3057 'description' : 'Number of basic interval lengths between checks when retrying after a soft error',
3061 'service_scheduled_downtime_depth' : {
3063 'description' : 'The number of scheduled downtimes the service is currently in',
3069 'description' : 'The current state of the service (0: OK, 1: WARN, 2: CRITICAL, 3: UNKNOWN)',
3073 'service_state_type' : {
3075 'description' : 'The type of the current state (0: soft, 1: hard)',
3081 'description' : 'The start time of the downtime as UNIX timestamp',
3087 'description' : 'The id of the downtime this downtime was triggered by or 0 if it was not triggered by another downtime',
3088 'prop' : 'trigger_id',
3093 'description' : 'The type of the downtime: 0 if it is active, 1 if it is pending',
3104 'description' : 'The contact that entered the comment',
3110 'description' : 'A comment text',
3116 'description' : 'The time the entry was made as UNIX timestamp',
3122 'description' : 'The type of the comment: 1 is user, 2 is downtime, 3 is flap and 4 is acknowledgement',
3123 'prop' : 'entry_type',
3128 'description' : 'The time of expiry of this comment as a UNIX timestamp',
3134 'depythonize' : from_bool_to_int
,
3135 'description' : 'Whether this comment expires',
3139 'host_accept_passive_checks' : {
3141 'description' : 'Wether passive host checks are accepted (0/1)',
3145 'host_acknowledged' : {
3147 'description' : 'Wether the current host problem has been acknowledged (0/1)',
3151 'host_acknowledgement_type' : {
3153 'description' : 'Type of acknowledgement (0: none, 1: normal, 2: stick)',
3157 'host_action_url' : {
3159 'description' : 'An optional URL to custom actions or information about this host',
3163 'host_action_url_expanded' : {
3165 'description' : 'The same as action_url, but with the most important macros expanded',
3169 'host_active_checks_enabled' : {
3171 'description' : 'Wether active checks are enabled for the host (0/1)',
3177 'description' : 'IP address',
3183 'description' : 'An alias name for the host',
3187 'host_check_command' : {
3189 'description' : 'Nagios command for active host check of this host',
3193 'host_check_freshness' : {
3195 'description' : 'Wether freshness checks are activated (0/1)',
3199 'host_check_interval' : {
3201 'description' : 'Number of basic interval lengths between two scheduled checks of the host',
3205 'host_check_options' : {
3207 'description' : 'The current check option, forced, normal, freshness... (0-2)',
3211 'host_check_period' : {
3213 'description' : 'Time period in which this host will be checked. If empty then the host will always be checked.',
3217 'host_check_type' : {
3219 'description' : 'Type of check (0: active, 1: passive)',
3223 'host_checks_enabled' : {
3225 'description' : 'Wether checks of the host are enabled (0/1)',
3231 'description' : 'A list of all direct childs of the host',
3237 'description' : 'A list of the ids of all comments of this host',
3243 'description' : 'A list of all contacts of this host, either direct or via a contact group',
3247 'host_current_attempt' : {
3249 'description' : 'Number of the current check attempts',
3253 'host_current_notification_number' : {
3255 'description' : 'Number of the current notification',
3259 'host_custom_variable_names' : {
3261 'description' : 'A list of the names of all custom variables',
3265 'host_custom_variable_values' : {
3267 'description' : 'A list of the values of the custom variables',
3271 'host_display_name' : {
3273 'description' : 'Optional display name of the host - not used by Nagios\' web interface',
3277 'host_downtimes' : {
3279 'description' : 'A list of the ids of all scheduled downtimes of this host',
3283 'host_event_handler_enabled' : {
3285 'description' : 'Wether event handling is enabled (0/1)',
3289 'host_execution_time' : {
3291 'description' : 'Time the host check needed for execution',
3295 'host_first_notification_delay' : {
3297 'description' : 'Delay before the first notification',
3301 'host_flap_detection_enabled' : {
3303 'description' : 'Wether flap detection is enabled (0/1)',
3309 'description' : 'A list of all host groups this host is in',
3313 'host_hard_state' : {
3315 'description' : 'The effective hard state of the host (eliminates a problem in hard_state)',
3319 'host_has_been_checked' : {
3321 'description' : 'Wether the host has already been checked (0/1)',
3325 'host_high_flap_threshold' : {
3327 'description' : 'High threshold of flap detection',
3331 'host_icon_image' : {
3333 'description' : 'The name of an image file to be used in the web pages',
3337 'host_icon_image_alt' : {
3339 'description' : 'Alternative text for the icon_image',
3343 'host_icon_image_expanded' : {
3345 'description' : 'The same as icon_image, but with the most important macros expanded',
3349 'host_in_check_period' : {
3351 'description' : 'Wether this host is currently in its check period (0/1)',
3355 'host_in_notification_period' : {
3357 'description' : 'Wether this host is currently in its notification period (0/1)',
3361 'host_initial_state' : {
3363 'description' : 'Initial host state',
3367 'host_is_executing' : {
3368 'default' : 0, # value in scheduler is not real-time
3369 'description' : 'is there a host check currently running... (0/1)',
3373 'host_is_flapping' : {
3375 'description' : 'Wether the host state is flapping (0/1)',
3379 'host_last_check' : {
3381 'description' : 'Time of the last check (Unix timestamp)',
3385 'host_last_hard_state' : {
3387 'description' : 'Last hard state',
3391 'host_last_hard_state_change' : {
3393 'description' : 'Time of the last hard state change (Unix timestamp)',
3397 'host_last_notification' : {
3399 'description' : 'Time of the last notification (Unix timestamp)',
3403 'host_last_state' : {
3405 'description' : 'State before last state change',
3409 'host_last_state_change' : {
3411 'description' : 'Time of the last state change - soft or hard (Unix timestamp)',
3417 'description' : 'Time difference between scheduled check time and actual check time',
3421 'host_long_plugin_output' : {
3423 'description' : 'Complete output from check plugin',
3427 'host_low_flap_threshold' : {
3429 'description' : 'Low threshold of flap detection',
3433 'host_max_check_attempts' : {
3435 'description' : 'Max check attempts for active host checks',
3441 'depythonize' : lambda x
: x
.host_name
,
3442 'description' : 'Host name',
3446 'host_next_check' : {
3448 'description' : 'Scheduled time for the next check (Unix timestamp)',
3452 'host_next_notification' : {
3454 'description' : 'Time of the next notification (Unix timestamp)',
3460 'description' : 'Optional notes for this host',
3464 'host_notes_expanded' : {
3466 'description' : 'The same as notes, but with the most important macros expanded',
3470 'host_notes_url' : {
3472 'description' : 'An optional URL with further information about the host',
3476 'host_notes_url_expanded' : {
3478 'description' : 'Same es notes_url, but with the most important macros expanded',
3482 'host_notification_interval' : {
3484 'description' : 'Interval of periodic notification or 0 if its off',
3488 'host_notification_period' : {
3490 'description' : 'Time period in which problems of this host will be notified. If empty then notification will be always',
3494 'host_notifications_enabled' : {
3496 'description' : 'Wether notifications of the host are enabled (0/1)',
3500 'host_num_services' : {
3502 'description' : 'The total number of services of the host',
3506 'host_num_services_crit' : {
3508 'description' : 'The number of the host\'s services with the soft state CRIT',
3512 'host_num_services_hard_crit' : {
3514 'description' : 'The number of the host\'s services with the hard state CRIT',
3518 'host_num_services_hard_ok' : {
3520 'description' : 'The number of the host\'s services with the hard state OK',
3524 'host_num_services_hard_unknown' : {
3526 'description' : 'The number of the host\'s services with the hard state UNKNOWN',
3530 'host_num_services_hard_warn' : {
3532 'description' : 'The number of the host\'s services with the hard state WARN',
3536 'host_num_services_ok' : {
3538 'description' : 'The number of the host\'s services with the soft state OK',
3542 'host_num_services_pending' : {
3544 'description' : 'The number of the host\'s services which have not been checked yet (pending)',
3548 'host_num_services_unknown' : {
3550 'description' : 'The number of the host\'s services with the soft state UNKNOWN',
3554 'host_num_services_warn' : {
3556 'description' : 'The number of the host\'s services with the soft state WARN',
3560 'host_obsess_over_host' : {
3562 'description' : 'The current obsess_over_host setting... (0/1)',
3568 'description' : 'A list of all direct parents of the host',
3572 'host_pending_flex_downtime' : {
3574 'description' : 'Wether a flex downtime is pending (0/1)',
3578 'host_percent_state_change' : {
3580 'description' : 'Percent state change',
3584 'host_perf_data' : {
3586 'description' : 'Optional performance data of the last host check',
3590 'host_plugin_output' : {
3592 'description' : 'Output of the last host check',
3596 'host_process_performance_data' : {
3598 'description' : 'Wether processing of performance data is enabled (0/1)',
3602 'host_retry_interval' : {
3604 'description' : 'Number of basic interval lengths between checks when retrying after a soft error',
3608 'host_scheduled_downtime_depth' : {
3610 'description' : 'The number of downtimes this host is currently in',
3616 'description' : 'The current state of the host (0: up, 1: down, 2: unreachable)',
3620 'host_state_type' : {
3622 'description' : 'Type of the current state (0: soft, 1: hard)',
3626 'host_statusmap_image' : {
3628 'description' : 'The name of in image file for the status map',
3632 'host_total_services' : {
3634 'description' : 'The total number of services of the host',
3638 'host_worst_service_hard_state' : {
3640 'description' : 'The worst hard state of all of the host\'s services (OK <= WARN <= UNKNOWN <= CRIT)',
3644 'host_worst_service_state' : {
3646 'description' : 'The worst soft state of all of the host\'s services (OK <= WARN <= UNKNOWN <= CRIT)',
3652 'description' : '3D-Coordinates: X',
3658 'description' : '3D-Coordinates: Y',
3664 'description' : '3D-Coordinates: Z',
3670 'description' : 'The id of the comment',
3676 'depythonize' : from_bool_to_int
,
3677 'description' : 'Whether this comment is persistent (0/1)',
3681 'service_accept_passive_checks' : {
3683 'description' : 'Wether the service accepts passive checks (0/1)',
3687 'service_acknowledged' : {
3689 'description' : 'Wether the current service problem has been acknowledged (0/1)',
3693 'service_acknowledgement_type' : {
3695 'description' : 'The type of the acknownledgement (0: none, 1: normal, 2: sticky)',
3699 'service_action_url' : {
3701 'description' : 'An optional URL for actions or custom information about the service',
3705 'service_action_url_expanded' : {
3707 'description' : 'The action_url with (the most important) macros expanded',
3711 'service_active_checks_enabled' : {
3713 'description' : 'Wether active checks are enabled for the service (0/1)',
3717 'service_check_command' : {
3719 'description' : 'Nagios command used for active checks',
3723 'service_check_interval' : {
3725 'description' : 'Number of basic interval lengths between two scheduled checks of the service',
3729 'service_check_options' : {
3731 'description' : 'The current check option, forced, normal, freshness... (0/1)',
3735 'service_check_period' : {
3737 'description' : 'The name of the check period of the service. It this is empty, the service is always checked.',
3741 'service_check_type' : {
3743 'description' : 'The type of the last check (0: active, 1: passive)',
3747 'service_checks_enabled' : {
3749 'description' : 'Wether active checks are enabled for the service (0/1)',
3753 'service_comments' : {
3755 'description' : 'A list of all comment ids of the service',
3759 'service_contacts' : {
3761 'description' : 'A list of all contacts of the service, either direct or via a contact group',
3765 'service_current_attempt' : {
3767 'description' : 'The number of the current check attempt',
3771 'service_current_notification_number' : {
3773 'description' : 'The number of the current notification',
3777 'service_custom_variable_names' : {
3779 'description' : 'A list of the names of all custom variables of the service',
3783 'service_custom_variable_values' : {
3785 'description' : 'A list of the values of all custom variable of the service',
3789 'service_description' : {
3791 'depythonize' : lambda x
: getattr(x
, 'service_description', ''),
3792 'description' : 'Description of the service (also used as key)',
3796 'service_display_name' : {
3798 'description' : 'An optional display name (not used by Nagios standard web pages)',
3802 'service_downtimes' : {
3804 'description' : 'A list of all downtime ids of the service',
3808 'service_event_handler' : {
3810 'description' : 'Nagios command used as event handler',
3814 'service_event_handler_enabled' : {
3816 'description' : 'Wether and event handler is activated for the service (0/1)',
3820 'service_execution_time' : {
3822 'description' : 'Time the host check needed for execution',
3826 'service_first_notification_delay' : {
3828 'description' : 'Delay before the first notification',
3832 'service_flap_detection_enabled' : {
3834 'description' : 'Wether flap detection is enabled for the service (0/1)',
3838 'service_groups' : {
3840 'description' : 'A list of all service groups the service is in',
3844 'service_has_been_checked' : {
3846 'description' : 'Wether the service already has been checked (0/1)',
3850 'service_high_flap_threshold' : {
3852 'description' : 'High threshold of flap detection',
3856 'service_icon_image' : {
3858 'description' : 'The name of an image to be used as icon in the web interface',
3862 'service_icon_image_alt' : {
3864 'description' : 'An alternative text for the icon_image for browsers not displaying icons',
3868 'service_icon_image_expanded' : {
3870 'description' : 'The icon_image with (the most important) macros expanded',
3874 'service_in_check_period' : {
3876 'description' : 'Wether the service is currently in its check period (0/1)',
3880 'service_in_notification_period' : {
3882 'description' : 'Wether the service is currently in its notification period (0/1)',
3886 'service_initial_state' : {
3888 'description' : 'The initial state of the service',
3892 'service_is_executing' : {
3893 'default' : 0, # value in scheduler is not real-time
3894 'description' : 'is there a service check currently running... (0/1)',
3898 'service_is_flapping' : {
3900 'description' : 'Wether the service is flapping (0/1)',
3904 'service_last_check' : {
3906 'description' : 'The time of the last check (Unix timestamp)',
3910 'service_last_hard_state' : {
3912 'description' : 'The last hard state of the service',
3916 'service_last_hard_state_change' : {
3918 'description' : 'The time of the last hard state change (Unix timestamp)',
3922 'service_last_notification' : {
3924 'description' : 'The time of the last notification (Unix timestamp)',
3928 'service_last_state' : {
3930 'description' : 'The last state of the service',
3934 'service_last_state_change' : {
3936 'description' : 'The time of the last state change (Unix timestamp)',
3940 'service_latency' : {
3942 'description' : 'Time difference between scheduled check time and actual check time',
3946 'service_long_plugin_output' : {
3948 'description' : 'Unabbreviated output of the last check plugin',
3952 'service_low_flap_threshold' : {
3954 'description' : 'Low threshold of flap detection',
3958 'service_max_check_attempts' : {
3960 'description' : 'The maximum number of check attempts',
3964 'service_next_check' : {
3966 'description' : 'The scheduled time of the next check (Unix timestamp)',
3970 'service_next_notification' : {
3972 'description' : 'The time of the next notification (Unix timestamp)',
3978 'description' : 'Optional notes about the service',
3982 'service_notes_expanded' : {
3984 'description' : 'The notes with (the most important) macros expanded',
3988 'service_notes_url' : {
3990 'description' : 'An optional URL for additional notes about the service',
3994 'service_notes_url_expanded' : {
3996 'description' : 'The notes_url with (the most important) macros expanded',
4000 'service_notification_interval' : {
4002 'description' : 'Interval of periodic notification or 0 if its off',
4006 'service_notification_period' : {
4008 'description' : 'The name of the notification period of the service. It this is empty, service problems are always notified.',
4012 'service_notifications_enabled' : {
4014 'description' : 'Wether notifications are enabled for the service (0/1)',
4018 'service_obsess_over_service' : {
4020 'description' : 'Wether \'obsess_over_service\' is enabled for the service (0/1)',
4024 'service_percent_state_change' : {
4026 'description' : 'Percent state change',
4030 'service_perf_data' : {
4032 'description' : 'Performance data of the last check plugin',
4036 'service_plugin_output' : {
4038 'description' : 'Output of the last check plugin',
4042 'service_process_performance_data' : {
4044 'description' : 'Wether processing of performance data is enabled for the service (0/1)',
4048 'service_retry_interval' : {
4050 'description' : 'Number of basic interval lengths between checks when retrying after a soft error',
4054 'service_scheduled_downtime_depth' : {
4056 'description' : 'The number of scheduled downtimes the service is currently in',
4062 'description' : 'The current state of the service (0: OK, 1: WARN, 2: CRITICAL, 3: UNKNOWN)',
4066 'service_state_type' : {
4068 'description' : 'The type of the current state (0: soft, 1: hard)',
4074 'description' : 'The source of the comment (0 is internal and 1 is external)',
4080 'description' : 'The type of the comment: 1 is service, 2 is host',
4081 'prop' : 'comment_type',
4086 # loop over hostgroups then over members
4088 'hostgroup_action_url' : {
4089 'description' : 'An optional URL to custom actions or information about the hostgroup',
4090 'prop' : 'hostgroup',
4093 'hostgroup_alias' : {
4094 'depythonize' : lambda x
: getattr(x
, 'hostgroup_alias', ''),
4095 'description' : 'An alias of the hostgroup',
4096 'prop' : 'hostgroup',
4099 'hostgroup_members' : {
4100 'description' : 'A list of all host names that are members of the hostgroup',
4101 'prop' : 'hostgroup',
4104 'hostgroup_members_with_state' : {
4105 'description' : 'A list of all host names that are members of the hostgroup together with state and has_been_checked',
4106 'prop' : 'hostgroup',
4109 'hostgroup_name' : {
4110 'depythonize' : lambda x
: getattr(x
, 'hostgroup_name', ''),
4111 'description' : 'Name of the hostgroup',
4112 'prop' : 'hostgroup',
4115 'hostgroup_notes' : {
4116 'description' : 'Optional notes to the hostgroup',
4117 'prop' : 'hostgroup',
4120 'hostgroup_notes_url' : {
4121 'description' : 'An optional URL with further information about the hostgroup',
4122 'prop' : 'hostgroup',
4125 'hostgroup_num_hosts' : {
4126 'description' : 'The total number of hosts in the group',
4127 'prop' : 'hostgroup',
4130 'hostgroup_num_hosts_down' : {
4131 'description' : 'The number of hosts in the group that are down',
4132 'prop' : 'hostgroup',
4135 'hostgroup_num_hosts_pending' : {
4136 'description' : 'The number of hosts in the group that are pending',
4137 'prop' : 'hostgroup',
4140 'hostgroup_num_hosts_unreach' : {
4141 'description' : 'The number of hosts in the group that are unreachable',
4142 'prop' : 'hostgroup',
4145 'hostgroup_num_hosts_up' : {
4146 'description' : 'The number of hosts in the group that are up',
4147 'prop' : 'hostgroup',
4150 'hostgroup_num_services' : {
4151 'description' : 'The total number of services of hosts in this group',
4152 'prop' : 'hostgroup',
4155 'hostgroup_num_services_crit' : {
4156 'description' : 'The total number of services with the state CRIT of hosts in this group',
4157 'prop' : 'hostgroup',
4160 'hostgroup_num_services_hard_crit' : {
4161 'description' : 'The total number of services with the state CRIT of hosts in this group',
4162 'prop' : 'hostgroup',
4165 'hostgroup_num_services_hard_ok' : {
4166 'description' : 'The total number of services with the state OK of hosts in this group',
4167 'prop' : 'hostgroup',
4170 'hostgroup_num_services_hard_unknown' : {
4171 'description' : 'The total number of services with the state UNKNOWN of hosts in this group',
4172 'prop' : 'hostgroup',
4175 'hostgroup_num_services_hard_warn' : {
4176 'description' : 'The total number of services with the state WARN of hosts in this group',
4177 'prop' : 'hostgroup',
4180 'hostgroup_num_services_ok' : {
4181 'description' : 'The total number of services with the state OK of hosts in this group',
4182 'prop' : 'hostgroup',
4185 'hostgroup_num_services_pending' : {
4186 'description' : 'The total number of services with the state Pending of hosts in this group',
4187 'prop' : 'hostgroup',
4190 'hostgroup_num_services_unknown' : {
4191 'description' : 'The total number of services with the state UNKNOWN of hosts in this group',
4192 'prop' : 'hostgroup',
4195 'hostgroup_num_services_warn' : {
4196 'description' : 'The total number of services with the state WARN of hosts in this group',
4197 'prop' : 'hostgroup',
4200 'hostgroup_worst_host_state' : {
4201 'description' : 'The worst state of all of the groups\' hosts (UP <= UNREACHABLE <= DOWN)',
4202 'prop' : 'hostgroup',
4205 'hostgroup_worst_service_hard_state' : {
4206 'description' : 'The worst state of all services that belong to a host of this group (OK <= WARN <= UNKNOWN <= CRIT)',
4207 'prop' : 'hostgroup',
4210 'hostgroup_worst_service_state' : {
4211 'description' : 'The worst state of all services that belong to a host of this group (OK <= WARN <= UNKNOWN <= CRIT)',
4212 'prop' : 'hostgroup',
4217 'Servicesbygroup' : {
4218 'servicegroup_action_url' : {
4219 'description' : 'An optional URL to custom notes or actions on the service group',
4222 'servicegroup_alias' : {
4223 'description' : 'An alias of the service group',
4226 'servicegroup_members' : {
4227 'description' : 'A list of all members of the service group as host/service pairs',
4230 'servicegroup_members_with_state' : {
4231 'description' : 'A list of all members of the service group with state and has_been_checked',
4234 'servicegroup_name' : {
4235 'description' : 'The name of the service group',
4238 'servicegroup_notes' : {
4239 'description' : 'Optional additional notes about the service group',
4242 'servicegroup_notes_url' : {
4243 'description' : 'An optional URL to further notes on the service group',
4246 'servicegroup_num_services' : {
4247 'description' : 'The total number of services in the group',
4250 'servicegroup_num_services_crit' : {
4251 'description' : 'The number of services in the group that are CRIT',
4254 'servicegroup_num_services_hard_crit' : {
4255 'description' : 'The number of services in the group that are CRIT',
4258 'servicegroup_num_services_hard_ok' : {
4259 'description' : 'The number of services in the group that are OK',
4262 'servicegroup_num_services_hard_unknown' : {
4263 'description' : 'The number of services in the group that are UNKNOWN',
4266 'servicegroup_num_services_hard_warn' : {
4267 'description' : 'The number of services in the group that are WARN',
4270 'servicegroup_num_services_ok' : {
4271 'description' : 'The number of services in the group that are OK',
4274 'servicegroup_num_services_pending' : {
4275 'description' : 'The number of services in the group that are PENDING',
4278 'servicegroup_num_services_unknown' : {
4279 'description' : 'The number of services in the group that are UNKNOWN',
4282 'servicegroup_num_services_warn' : {
4283 'description' : 'The number of services in the group that are WARN',
4286 'servicegroup_worst_service_state' : {
4287 'description' : 'The worst soft state of all of the groups services (OK <= WARN <= UNKNOWN <= CRIT)',
4292 'Servicesbyhostgroup' : {
4293 'hostgroup_action_url' : {
4294 'description' : 'An optional URL to custom actions or information about the hostgroup',
4297 'hostgroup_alias' : {
4298 'description' : 'An alias of the hostgroup',
4301 'hostgroup_members' : {
4302 'description' : 'A list of all host names that are members of the hostgroup',
4305 'hostgroup_members_with_state' : {
4306 'description' : 'A list of all host names that are members of the hostgroup together with state and has_been_checked',
4309 'hostgroup_name' : {
4310 'depythonize' : lambda x
: getattr(x
, 'hostgroup_name', ''),
4311 'description' : 'Name of the hostgroup',
4312 'prop' : 'hostgroup',
4315 'hostgroup_notes' : {
4316 'description' : 'Optional notes to the hostgroup',
4319 'hostgroup_notes_url' : {
4320 'description' : 'An optional URL with further information about the hostgroup',
4323 'hostgroup_num_hosts' : {
4324 'description' : 'The total number of hosts in the group',
4327 'hostgroup_num_hosts_down' : {
4328 'description' : 'The number of hosts in the group that are down',
4331 'hostgroup_num_hosts_pending' : {
4332 'description' : 'The number of hosts in the group that are pending',
4335 'hostgroup_num_hosts_unreach' : {
4336 'description' : 'The number of hosts in the group that are unreachable',
4339 'hostgroup_num_hosts_up' : {
4340 'description' : 'The number of hosts in the group that are up',
4343 'hostgroup_num_services' : {
4344 'description' : 'The total number of services of hosts in this group',
4347 'hostgroup_num_services_crit' : {
4348 'description' : 'The total number of services with the state CRIT of hosts in this group',
4351 'hostgroup_num_services_hard_crit' : {
4352 'description' : 'The total number of services with the state CRIT of hosts in this group',
4355 'hostgroup_num_services_hard_ok' : {
4356 'description' : 'The total number of services with the state OK of hosts in this group',
4359 'hostgroup_num_services_hard_unknown' : {
4360 'description' : 'The total number of services with the state UNKNOWN of hosts in this group',
4363 'hostgroup_num_services_hard_warn' : {
4364 'description' : 'The total number of services with the state WARN of hosts in this group',
4367 'hostgroup_num_services_ok' : {
4368 'description' : 'The total number of services with the state OK of hosts in this group',
4371 'hostgroup_num_services_pending' : {
4372 'description' : 'The total number of services with the state Pending of hosts in this group',
4375 'hostgroup_num_services_unknown' : {
4376 'description' : 'The total number of services with the state UNKNOWN of hosts in this group',
4379 'hostgroup_num_services_warn' : {
4380 'description' : 'The total number of services with the state WARN of hosts in this group',
4383 'hostgroup_worst_host_state' : {
4384 'description' : 'The worst state of all of the groups\' hosts (UP <= UNREACHABLE <= DOWN)',
4387 'hostgroup_worst_service_hard_state' : {
4388 'description' : 'The worst state of all services that belong to a host of this group (OK <= WARN <= UNKNOWN <= CRIT)',
4391 'hostgroup_worst_service_state' : {
4392 'description' : 'The worst state of all services that belong to a host of this group (OK <= WARN <= UNKNOWN <= CRIT)',
4397 #All the global config parameters
4400 'accept_passive_host_checks' : {
4402 'depythonize' : from_bool_to_int
,
4403 'description' : 'Whether passive host checks are accepted in general (0/1)',
4404 'prop' : 'passive_host_checks_enabled',
4407 'accept_passive_service_checks' : {
4409 'depythonize' : from_bool_to_int
,
4410 'description' : 'Whether passive service checks are activated in general (0/1)',
4411 'prop' : 'passive_service_checks_enabled',
4414 'cached_log_messages' : {
4416 'description' : 'The current number of log messages MK Livestatus keeps in memory',
4420 'check_external_commands' : {
4422 'depythonize' : from_bool_to_int
,
4423 'description' : 'Whether Nagios checks for external commands at its command pipe (0/1)',
4427 'check_host_freshness' : {
4429 'depythonize' : from_bool_to_int
,
4430 'description' : 'Whether host freshness checking is activated in general (0/1)',
4434 'check_service_freshness' : {
4436 'depythonize' : from_bool_to_int
,
4437 'description' : 'Whether service freshness checking is activated in general (0/1)',
4443 'description' : 'The number of client connections to Livestatus since program start',
4447 'connections_rate' : {
4449 'description' : 'The averaged number of new client connections to Livestatus per second',
4453 'enable_event_handlers' : {
4455 'depythonize' : from_bool_to_int
,
4456 'description' : 'Whether event handlers are activated in general (0/1)',
4457 'prop' : 'event_handlers_enabled',
4460 'enable_flap_detection' : {
4462 'depythonize' : from_bool_to_int
,
4463 'description' : 'Whether flap detection is activated in general (0/1)',
4464 'prop' : 'flap_detection_enabled',
4467 'enable_notifications' : {
4469 'depythonize' : from_bool_to_int
,
4470 'description' : 'Whether notifications are enabled in general (0/1)',
4471 'prop' : 'notifications_enabled',
4474 'execute_host_checks' : {
4476 'depythonize' : from_bool_to_int
,
4477 'description' : 'Whether host checks are executed in general (0/1)',
4478 'prop' : 'active_host_checks_enabled',
4481 'execute_service_checks' : {
4483 'depythonize' : from_bool_to_int
,
4484 'description' : 'Whether active service checks are activated in general (0/1)',
4485 'prop' : 'active_service_checks_enabled',
4490 'description' : 'The number of host checks since program start',
4494 'host_checks_rate' : {
4496 'description' : 'the averaged number of host checks per second',
4500 'interval_length' : {
4502 'description' : 'The default interval length from nagios.cfg',
4506 'last_command_check' : {
4508 'description' : 'The time of the last check for a command as UNIX timestamp',
4512 'last_log_rotation' : {
4514 'description' : 'Time time of the last log file rotation',
4518 'livestatus_version' : {
4519 'default' : '1.1.3-shinken',
4520 'description' : 'The version of the MK Livestatus module',
4526 'description' : 'The process ID of the Nagios main process',
4532 'description' : 'The number of NEB call backs since program start',
4536 'neb_callbacks_rate' : {
4538 'description' : 'The averaged number of NEB call backs per second',
4542 'obsess_over_hosts' : {
4544 'depythonize' : from_bool_to_int
,
4545 'description' : 'Whether Nagios will obsess over host checks (0/1)',
4549 'obsess_over_services' : {
4551 'depythonize' : from_bool_to_int
,
4552 'description' : 'Whether Nagios will obsess over service checks and run the ocsp_command (0/1)',
4556 'process_performance_data' : {
4558 'depythonize' : from_bool_to_int
,
4559 'description' : 'Whether processing of performance data is activated in general (0/1)',
4565 'description' : 'The time of the last program start as UNIX timestamp',
4569 'program_version' : {
4571 'description' : 'The version of the monitoring daemon',
4577 'description' : 'The number of requests to Livestatus since program start',
4583 'description' : 'The averaged number of request to Livestatus per second',
4587 'service_checks' : {
4589 'description' : 'The number of completed service checks since program start',
4593 'service_checks_rate' : {
4595 'description' : 'The averaged number of service checks per second',
4603 'description' : 'The number of the check attempt',
4607 'description' : 'The class of the message as integer (0:info, 1:state, 2:program, 3:notification, 4:passive, 5:command)',
4611 'description' : 'The name of the command of the log entry (e.g. for notifications)',
4615 'description' : 'A comment field used in various message types',
4619 'description' : 'The name of the contact the log entry is about (might be empty)',
4622 'current_command_line' : {
4623 'description' : 'The shell command line',
4626 'current_command_name' : {
4627 'description' : 'The name of the command',
4630 'current_contact_address1' : {
4631 'description' : 'The additional field address1',
4634 'current_contact_address2' : {
4635 'description' : 'The additional field address2',
4638 'current_contact_address3' : {
4639 'description' : 'The additional field address3',
4642 'current_contact_address4' : {
4643 'description' : 'The additional field address4',
4646 'current_contact_address5' : {
4647 'description' : 'The additional field address5',
4650 'current_contact_address6' : {
4651 'description' : 'The additional field address6',
4654 'current_contact_alias' : {
4655 'description' : 'The full name of the contact',
4658 'current_contact_can_submit_commands' : {
4659 'description' : 'Wether the contact is allowed to submit commands (0/1)',
4662 'current_contact_custom_variable_names' : {
4663 'description' : 'A list of all custom variables of the contact',
4666 'current_contact_custom_variable_values' : {
4667 'description' : 'A list of the values of all custom variables of the contact',
4670 'current_contact_email' : {
4671 'description' : 'The email address of the contact',
4674 'current_contact_host_notification_period' : {
4675 'description' : 'The time period in which the contact will be notified about host problems',
4678 'current_contact_host_notifications_enabled' : {
4679 'description' : 'Wether the contact will be notified about host problems in general (0/1)',
4682 'current_contact_in_host_notification_period' : {
4683 'description' : 'Wether the contact is currently in his/her host notification period (0/1)',
4686 'current_contact_in_service_notification_period' : {
4687 'description' : 'Wether the contact is currently in his/her service notification period (0/1)',
4690 'current_contact_name' : {
4691 'description' : 'The login name of the contact person',
4694 'current_contact_pager' : {
4695 'description' : 'The pager address of the contact',
4698 'current_contact_service_notification_period' : {
4699 'description' : 'The time period in which the contact will be notified about service problems',
4702 'current_contact_service_notifications_enabled' : {
4703 'description' : 'Wether the contact will be notified about service problems in general (0/1)',
4706 'current_host_accept_passive_checks' : {
4707 'description' : 'Wether passive host checks are accepted (0/1)',
4710 'current_host_acknowledged' : {
4711 'description' : 'Wether the current host problem has been acknowledged (0/1)',
4714 'current_host_acknowledgement_type' : {
4715 'description' : 'Type of acknowledgement (0: none, 1: normal, 2: stick)',
4718 'current_host_action_url' : {
4719 'description' : 'An optional URL to custom actions or information about this host',
4722 'current_host_action_url_expanded' : {
4723 'description' : 'The same as action_url, but with the most important macros expanded',
4726 'current_host_active_checks_enabled' : {
4727 'description' : 'Wether active checks are enabled for the host (0/1)',
4730 'current_host_address' : {
4731 'description' : 'IP address',
4734 'current_host_alias' : {
4735 'description' : 'An alias name for the host',
4738 'current_host_check_command' : {
4739 'description' : 'Nagios command for active host check of this host',
4742 'current_host_check_freshness' : {
4743 'description' : 'Wether freshness checks are activated (0/1)',
4746 'current_host_check_interval' : {
4747 'description' : 'Number of basic interval lengths between two scheduled checks of the host',
4750 'current_host_check_options' : {
4751 'description' : 'The current check option, forced, normal, freshness... (0-2)',
4754 'current_host_check_period' : {
4755 'description' : 'Time period in which this host will be checked. If empty then the host will always be checked.',
4758 'current_host_check_type' : {
4759 'description' : 'Type of check (0: active, 1: passive)',
4762 'current_host_checks_enabled' : {
4763 'description' : 'Wether checks of the host are enabled (0/1)',
4766 'current_host_childs' : {
4767 'description' : 'A list of all direct childs of the host',
4770 'current_host_comments' : {
4771 'description' : 'A list of the ids of all comments of this host',
4774 'current_host_contacts' : {
4775 'description' : 'A list of all contacts of this host, either direct or via a contact group',
4778 'current_host_current_attempt' : {
4779 'description' : 'Number of the current check attempts',
4782 'current_host_current_notification_number' : {
4783 'description' : 'Number of the current notification',
4786 'current_host_custom_variable_names' : {
4787 'description' : 'A list of the names of all custom variables',
4790 'current_host_custom_variable_values' : {
4791 'description' : 'A list of the values of the custom variables',
4794 'current_host_display_name' : {
4795 'description' : 'Optional display name of the host - not used by Nagios\' web interface',
4798 'current_host_downtimes' : {
4799 'description' : 'A list of the ids of all scheduled downtimes of this host',
4802 'current_host_event_handler_enabled' : {
4803 'description' : 'Wether event handling is enabled (0/1)',
4806 'current_host_execution_time' : {
4807 'description' : 'Time the host check needed for execution',
4810 'current_host_first_notification_delay' : {
4811 'description' : 'Delay before the first notification',
4814 'current_host_flap_detection_enabled' : {
4815 'description' : 'Wether flap detection is enabled (0/1)',
4818 'current_host_groups' : {
4819 'description' : 'A list of all host groups this host is in',
4822 'current_host_hard_state' : {
4823 'description' : 'The effective hard state of the host (eliminates a problem in hard_state)',
4826 'current_host_has_been_checked' : {
4827 'description' : 'Wether the host has already been checked (0/1)',
4830 'current_host_high_flap_threshold' : {
4831 'description' : 'High threshold of flap detection',
4834 'current_host_icon_image' : {
4835 'description' : 'The name of an image file to be used in the web pages',
4838 'current_host_icon_image_alt' : {
4839 'description' : 'Alternative text for the icon_image',
4842 'current_host_icon_image_expanded' : {
4843 'description' : 'The same as icon_image, but with the most important macros expanded',
4846 'current_host_in_check_period' : {
4847 'description' : 'Wether this host is currently in its check period (0/1)',
4850 'current_host_in_notification_period' : {
4851 'description' : 'Wether this host is currently in its notification period (0/1)',
4854 'current_host_initial_state' : {
4855 'description' : 'Initial host state',
4858 'current_host_is_executing' : {
4859 'default' : 0, # value in scheduler is not real-time
4860 'description' : 'is there a host check currently running... (0/1)',
4863 'current_host_is_flapping' : {
4864 'description' : 'Wether the host state is flapping (0/1)',
4867 'current_host_last_check' : {
4868 'description' : 'Time of the last check (Unix timestamp)',
4871 'current_host_last_hard_state' : {
4872 'description' : 'Last hard state',
4875 'current_host_last_hard_state_change' : {
4876 'description' : 'Time of the last hard state change (Unix timestamp)',
4879 'current_host_last_notification' : {
4880 'description' : 'Time of the last notification (Unix timestamp)',
4883 'current_host_last_state' : {
4884 'description' : 'State before last state change',
4887 'current_host_last_state_change' : {
4888 'description' : 'Time of the last state change - soft or hard (Unix timestamp)',
4891 'current_host_latency' : {
4892 'description' : 'Time difference between scheduled check time and actual check time',
4895 'current_host_long_plugin_output' : {
4896 'description' : 'Complete output from check plugin',
4899 'current_host_low_flap_threshold' : {
4900 'description' : 'Low threshold of flap detection',
4903 'current_host_max_check_attempts' : {
4904 'description' : 'Max check attempts for active host checks',
4907 'current_host_name' : {
4909 'depythonize' : lambda x
: x
.get_name(),
4910 'description' : 'Host name',
4911 'prop' : 'log_host',
4914 'current_host_next_check' : {
4915 'description' : 'Scheduled time for the next check (Unix timestamp)',
4918 'current_host_next_notification' : {
4919 'description' : 'Time of the next notification (Unix timestamp)',
4922 'current_host_notes' : {
4923 'description' : 'Optional notes for this host',
4926 'current_host_notes_expanded' : {
4927 'description' : 'The same as notes, but with the most important macros expanded',
4930 'current_host_notes_url' : {
4931 'description' : 'An optional URL with further information about the host',
4934 'current_host_notes_url_expanded' : {
4935 'description' : 'Same es notes_url, but with the most important macros expanded',
4938 'current_host_notification_interval' : {
4939 'description' : 'Interval of periodic notification or 0 if its off',
4942 'current_host_notification_period' : {
4943 'description' : 'Time period in which problems of this host will be notified. If empty then notification will be always',
4946 'current_host_notifications_enabled' : {
4947 'description' : 'Wether notifications of the host are enabled (0/1)',
4950 'current_host_num_services' : {
4951 'description' : 'The total number of services of the host',
4954 'current_host_num_services_crit' : {
4955 'description' : 'The number of the host\'s services with the soft state CRIT',
4958 'current_host_num_services_hard_crit' : {
4959 'description' : 'The number of the host\'s services with the hard state CRIT',
4962 'current_host_num_services_hard_ok' : {
4963 'description' : 'The number of the host\'s services with the hard state OK',
4966 'current_host_num_services_hard_unknown' : {
4967 'description' : 'The number of the host\'s services with the hard state UNKNOWN',
4970 'current_host_num_services_hard_warn' : {
4971 'description' : 'The number of the host\'s services with the hard state WARN',
4974 'current_host_num_services_ok' : {
4975 'description' : 'The number of the host\'s services with the soft state OK',
4978 'current_host_num_services_pending' : {
4979 'description' : 'The number of the host\'s services which have not been checked yet (pending)',
4982 'current_host_num_services_unknown' : {
4983 'description' : 'The number of the host\'s services with the soft state UNKNOWN',
4986 'current_host_num_services_warn' : {
4987 'description' : 'The number of the host\'s services with the soft state WARN',
4990 'current_host_obsess_over_host' : {
4991 'description' : 'The current obsess_over_host setting... (0/1)',
4994 'current_host_parents' : {
4995 'description' : 'A list of all direct parents of the host',
4998 'current_host_pending_flex_downtime' : {
4999 'description' : 'Wether a flex downtime is pending (0/1)',
5002 'current_host_percent_state_change' : {
5003 'description' : 'Percent state change',
5006 'current_host_perf_data' : {
5007 'description' : 'Optional performance data of the last host check',
5010 'current_host_plugin_output' : {
5011 'description' : 'Output of the last host check',
5014 'current_host_process_performance_data' : {
5015 'description' : 'Wether processing of performance data is enabled (0/1)',
5018 'current_host_retry_interval' : {
5019 'description' : 'Number of basic interval lengths between checks when retrying after a soft error',
5022 'current_host_scheduled_downtime_depth' : {
5023 'description' : 'The number of downtimes this host is currently in',
5026 'current_host_state' : {
5027 'description' : 'The current state of the host (0: up, 1: down, 2: unreachable)',
5030 'current_host_state_type' : {
5031 'description' : 'Type of the current state (0: soft, 1: hard)',
5034 'current_host_statusmap_image' : {
5035 'description' : 'The name of in image file for the status map',
5038 'current_host_total_services' : {
5039 'description' : 'The total number of services of the host',
5042 'current_host_worst_service_hard_state' : {
5043 'description' : 'The worst hard state of all of the host\'s services (OK <= WARN <= UNKNOWN <= CRIT)',
5046 'current_host_worst_service_state' : {
5047 'description' : 'The worst soft state of all of the host\'s services (OK <= WARN <= UNKNOWN <= CRIT)',
5050 'current_host_x_3d' : {
5051 'description' : '3D-Coordinates: X',
5054 'current_host_y_3d' : {
5055 'description' : '3D-Coordinates: Y',
5058 'current_host_z_3d' : {
5059 'description' : '3D-Coordinates: Z',
5062 'current_service_accept_passive_checks' : {
5063 'description' : 'Wether the service accepts passive checks (0/1)',
5066 'current_service_acknowledged' : {
5067 'description' : 'Wether the current service problem has been acknowledged (0/1)',
5070 'current_service_acknowledgement_type' : {
5071 'description' : 'The type of the acknownledgement (0: none, 1: normal, 2: sticky)',
5074 'current_service_action_url' : {
5075 'description' : 'An optional URL for actions or custom information about the service',
5078 'current_service_action_url_expanded' : {
5079 'description' : 'The action_url with (the most important) macros expanded',
5082 'current_service_active_checks_enabled' : {
5083 'description' : 'Wether active checks are enabled for the service (0/1)',
5086 'current_service_check_command' : {
5087 'description' : 'Nagios command used for active checks',
5090 'current_service_check_interval' : {
5091 'description' : 'Number of basic interval lengths between two scheduled checks of the service',
5094 'current_service_check_options' : {
5095 'description' : 'The current check option, forced, normal, freshness... (0/1)',
5098 'current_service_check_period' : {
5099 'description' : 'The name of the check period of the service. It this is empty, the service is always checked.',
5102 'current_service_check_type' : {
5103 'description' : 'The type of the last check (0: active, 1: passive)',
5106 'current_service_checks_enabled' : {
5107 'description' : 'Wether active checks are enabled for the service (0/1)',
5110 'current_service_comments' : {
5111 'description' : 'A list of all comment ids of the service',
5114 'current_service_contacts' : {
5115 'description' : 'A list of all contacts of the service, either direct or via a contact group',
5118 'current_service_current_attempt' : {
5119 'description' : 'The number of the current check attempt',
5122 'current_service_current_notification_number' : {
5123 'description' : 'The number of the current notification',
5126 'current_service_custom_variable_names' : {
5127 'description' : 'A list of the names of all custom variables of the service',
5130 'current_service_custom_variable_values' : {
5131 'description' : 'A list of the values of all custom variable of the service',
5134 'current_service_description' : {
5136 'depythonize' : lambda x
: x
.get_name(),
5137 'description' : 'Description of the service (also used as key)',
5138 'prop' : 'log_service',
5141 'current_service_display_name' : {
5142 'description' : 'An optional display name (not used by Nagios standard web pages)',
5145 'current_service_downtimes' : {
5146 'description' : 'A list of all downtime ids of the service',
5149 'current_service_event_handler' : {
5150 'description' : 'Nagios command used as event handler',
5153 'current_service_event_handler_enabled' : {
5154 'description' : 'Wether and event handler is activated for the service (0/1)',
5157 'current_service_execution_time' : {
5158 'description' : 'Time the host check needed for execution',
5161 'current_service_first_notification_delay' : {
5162 'description' : 'Delay before the first notification',
5165 'current_service_flap_detection_enabled' : {
5166 'description' : 'Wether flap detection is enabled for the service (0/1)',
5169 'current_service_groups' : {
5170 'description' : 'A list of all service groups the service is in',
5173 'current_service_has_been_checked' : {
5174 'description' : 'Wether the service already has been checked (0/1)',
5177 'current_service_high_flap_threshold' : {
5178 'description' : 'High threshold of flap detection',
5181 'current_service_icon_image' : {
5182 'description' : 'The name of an image to be used as icon in the web interface',
5185 'current_service_icon_image_alt' : {
5186 'description' : 'An alternative text for the icon_image for browsers not displaying icons',
5189 'current_service_icon_image_expanded' : {
5190 'description' : 'The icon_image with (the most important) macros expanded',
5193 'current_service_in_check_period' : {
5194 'description' : 'Wether the service is currently in its check period (0/1)',
5197 'current_service_in_notification_period' : {
5198 'description' : 'Wether the service is currently in its notification period (0/1)',
5201 'current_service_initial_state' : {
5202 'description' : 'The initial state of the service',
5205 'current_service_is_executing' : {
5206 'default' : 0, # value in scheduler is not real-time
5207 'description' : 'is there a service check currently running... (0/1)',
5210 'current_service_is_flapping' : {
5211 'description' : 'Wether the service is flapping (0/1)',
5214 'current_service_last_check' : {
5215 'description' : 'The time of the last check (Unix timestamp)',
5218 'current_service_last_hard_state' : {
5219 'description' : 'The last hard state of the service',
5222 'current_service_last_hard_state_change' : {
5223 'description' : 'The time of the last hard state change (Unix timestamp)',
5226 'current_service_last_notification' : {
5227 'description' : 'The time of the last notification (Unix timestamp)',
5230 'current_service_last_state' : {
5231 'description' : 'The last state of the service',
5234 'current_service_last_state_change' : {
5235 'description' : 'The time of the last state change (Unix timestamp)',
5238 'current_service_latency' : {
5239 'description' : 'Time difference between scheduled check time and actual check time',
5242 'current_service_long_plugin_output' : {
5243 'description' : 'Unabbreviated output of the last check plugin',
5246 'current_service_low_flap_threshold' : {
5247 'description' : 'Low threshold of flap detection',
5250 'current_service_max_check_attempts' : {
5251 'description' : 'The maximum number of check attempts',
5254 'current_service_next_check' : {
5255 'description' : 'The scheduled time of the next check (Unix timestamp)',
5258 'current_service_next_notification' : {
5259 'description' : 'The time of the next notification (Unix timestamp)',
5262 'current_service_notes' : {
5263 'description' : 'Optional notes about the service',
5266 'current_service_notes_expanded' : {
5267 'description' : 'The notes with (the most important) macros expanded',
5270 'current_service_notes_url' : {
5271 'description' : 'An optional URL for additional notes about the service',
5274 'current_service_notes_url_expanded' : {
5275 'description' : 'The notes_url with (the most important) macros expanded',
5278 'current_service_notification_interval' : {
5279 'description' : 'Interval of periodic notification or 0 if its off',
5282 'current_service_notification_period' : {
5283 'description' : 'The name of the notification period of the service. It this is empty, service problems are always notified.',
5286 'current_service_notifications_enabled' : {
5287 'description' : 'Wether notifications are enabled for the service (0/1)',
5290 'current_service_obsess_over_service' : {
5291 'description' : 'Wether \'obsess_over_service\' is enabled for the service (0/1)',
5294 'current_service_percent_state_change' : {
5295 'description' : 'Percent state change',
5298 'current_service_perf_data' : {
5299 'description' : 'Performance data of the last check plugin',
5302 'current_service_plugin_output' : {
5303 'description' : 'Output of the last check plugin',
5306 'current_service_process_performance_data' : {
5307 'description' : 'Wether processing of performance data is enabled for the service (0/1)',
5310 'current_service_retry_interval' : {
5311 'description' : 'Number of basic interval lengths between checks when retrying after a soft error',
5314 'current_service_scheduled_downtime_depth' : {
5315 'description' : 'The number of scheduled downtimes the service is currently in',
5318 'current_service_state' : {
5319 'description' : 'The current state of the service (0: OK, 1: WARN, 2: CRITICAL, 3: UNKNOWN)',
5322 'current_service_state_type' : {
5323 'description' : 'The type of the current state (0: soft, 1: hard)',
5327 'description' : 'The name of the host the log entry is about (might be empty)',
5331 'description' : 'The number of the line in the log file',
5335 'description' : 'The complete message line including the timestamp',
5339 'description' : 'The part of the message after the \':\'',
5343 'description' : 'The output of the check, if any is associated with the message',
5346 'service_description' : {
5347 'description' : 'The description of the service log entry is about (might be empty)',
5352 'description' : 'The state of the host or service in question',
5357 'description' : 'The type of the state (varies on different log classes)',
5362 'description' : 'Time of the log event (UNIX timestamp)',
5367 'description' : 'The type of the message (text before the colon), the message itself for info messages',
5374 separators
= map(lambda x
: chr(int(x
)), [10, 59, 44, 124])
5377 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
):
5378 self
.configs
= configs
5379 self
.hostname_lookup_table
= hostname_lookup_table
5380 self
.servicename_lookup_table
= servicename_lookup_table
5382 self
.services
= services
5383 self
.contacts
= contacts
5384 self
.hostgroups
= hostgroups
5385 self
.servicegroups
= servicegroups
5386 self
.contactgroups
= contactgroups
5387 self
.timeperiods
= timeperiods
5388 self
.commands
= commands
5389 self
.schedulers
= schedulers
5390 self
.pollers
= pollers
5391 self
.reactionners
= reactionners
5392 self
.brokers
= brokers
5393 self
.dbconn
= dbconn
5394 LiveStatus
.pnp_path
= pnp_path
5396 self
.dbconn
.row_factory
= self
.row_factory
5397 self
.return_queue
= return_queue
5399 self
.create_out_map_delegates()
5400 self
.create_out_map_hooks()
5401 # add Host attributes to Hostsbygroup etc.
5402 for attribute
in LiveStatus
.out_map
['Host']:
5403 LiveStatus
.out_map
['Hostsbygroup'][attribute
] = LiveStatus
.out_map
['Host'][attribute
]
5404 for attribute
in self
.out_map
['Service']:
5405 LiveStatus
.out_map
['Servicesbygroup'][attribute
] = LiveStatus
.out_map
['Service'][attribute
]
5406 for attribute
in self
.out_map
['Service']:
5407 LiveStatus
.out_map
['Servicesbyhostgroup'][attribute
] = LiveStatus
.out_map
['Service'][attribute
]
5410 def row_factory(self
, cursor
, row
):
5411 """Handler for the sqlite fetch method."""
5412 return Logline(cursor
, row
)
5415 def handle_request(self
, data
):
5416 """Execute the livestatus request.
5418 This function creates a LiveStatusRequest method, calls the parser,
5419 handles the execution of the request and formatting of the result.
5422 request
= LiveStatusRequest(self
.configs
, self
.hostname_lookup_table
, self
.servicename_lookup_table
, self
.hosts
, self
.services
, self
.contacts
, self
.hostgroups
, self
.servicegroups
, self
.contactgroups
, self
.timeperiods
, self
.commands
, 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
=(',', ':'))))
5679 class LiveStatusRequest(LiveStatus
):
5681 """A class describing a livestatus request."""
5683 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
):
5684 # Runtime data form the global LiveStatus object
5685 self
.configs
= configs
5686 self
.hostname_lookup_table
= hostname_lookup_table
5687 self
.servicename_lookup_table
= servicename_lookup_table
5689 self
.services
= services
5690 self
.contacts
= contacts
5691 self
.hostgroups
= hostgroups
5692 self
.servicegroups
= servicegroups
5693 self
.contactgroups
= contactgroups
5694 self
.timeperiods
= timeperiods
5695 self
.commands
= commands
5696 self
.schedulers
= schedulers
5697 self
.pollers
= pollers
5698 self
.reactionners
= reactionners
5699 self
.brokers
= brokers
5700 self
.dbconn
= dbconn
5701 self
.pnp_path
= pnp_path
5702 self
.return_queue
= return_queue
5704 # Private attributes for this specific request
5705 self
.response
= LiveStatusResponse(responseheader
= 'off', outputformat
= 'csv', keepalive
= 'off', columnheaders
= 'undef', separators
= LiveStatus
.separators
)
5708 self
.filtercolumns
= []
5709 self
.prefiltercolumns
= []
5710 self
.stats_group_by
= []
5711 self
.stats_columns
= []
5715 self
.out_map
= self
.copy_out_map_hooks()
5717 # Initialize the stacks which are needed for the Filter: and Stats:
5718 # filter- and count-operations
5719 self
.filter_stack
= LiveStatusStack()
5720 self
.sql_filter_stack
= LiveStatusStack()
5721 self
.sql_filter_stack
.type = 'sql'
5722 self
.stats_filter_stack
= LiveStatusStack()
5723 self
.stats_postprocess_stack
= LiveStatusStack()
5724 self
.stats_request
= False
5726 # Set a timestamp for this specific request
5727 self
.tic
= time
.time()
5728 # Clients can also send their local time with the request
5729 self
.client_localtime
= time
.time()
5732 def find_converter(self
, attribute
):
5733 """Return a function that converts textual numbers
5734 in the request to the correct data type"""
5735 out_map
= LiveStatus
.out_map
[self
.out_map_name
]
5736 if attribute
in out_map
and 'type' in out_map
[attribute
]:
5737 if out_map
[attribute
]['type'] == 'int':
5739 elif out_map
[attribute
]['type'] == 'float':
5744 def set_default_out_map_name(self
):
5745 """Translate the table name to the corresponding out_map key."""
5746 self
.out_map_name
= {
5748 'services' : 'Service',
5749 'hostgroups' : 'Hostgroup',
5750 'servicegroups' : 'Servicegroup',
5751 'contacts' : 'Contact',
5752 'contactgroups' : 'Contactgroup',
5753 'comments' : 'Comment',
5754 'downtimes' : 'Downtime',
5755 'commands' : 'Command',
5756 'timeperiods' : 'Timeperiod',
5757 'hostsbygroup' : 'Hostsbygroup',
5758 'servicesbygroup' : 'Servicesbygroup',
5759 'servicesbyhostgroup' : 'Servicesbyhostgroup',
5760 'status' : 'Config',
5762 'schedulers' : 'SchedulerLink',
5763 'pollers' : 'PollerLink',
5764 'reactionners' : 'ReactionnerLink',
5765 'brokers' : 'BrokerLink',
5766 'problems' : 'Problem',
5767 'columns' : 'Config', # just a dummy
5771 def copy_out_map_hooks(self
):
5772 """Update the hooks for some out_map entries.
5774 Livestatus columns which have a fulldepythonize postprocessor
5775 need an updated argument list. The third argument needs to
5776 be the request object. (When the out_map is first supplied
5777 with hooks, the third argument is the Livestatus object.)
5781 for objtype
in LiveStatus
.out_map
:
5782 new_map
[objtype
] = {}
5783 for attribute
in LiveStatus
.out_map
[objtype
]:
5784 new_map
[objtype
][attribute
] = {}
5785 entry
= LiveStatus
.out_map
[objtype
][attribute
]
5786 if 'hooktype' in entry
:
5787 if 'prop' not in entry
or entry
['prop'] == None:
5790 prop
= entry
['prop']
5791 if 'default' in entry
:
5792 default
= entry
['default']
5794 if entry
['type'] == 'int' or entry
['type'] == 'float':
5798 func
= entry
['fulldepythonize']
5799 new_map
[objtype
][attribute
]['hook'] = self
.make_hook('get_prop_full_depythonize', prop
, default
, func
, None)
5801 new_map
[objtype
][attribute
]['hook'] = entry
['hook']
5806 output
= "LiveStatusRequest:\n"
5807 for attr
in ["table", "columns", "filtercolumns", "prefiltercolumns", "aliases", "stats_group_by", "stats_request"]:
5808 output
+= "request %s: %s\n" % (attr
, getattr(self
, attr
))
5812 def split_command(self
, line
, splits
=1):
5813 """Create a list from the words of a line"""
5814 return line
.split(' ', splits
)
5817 def split_option(self
, line
, splits
=1):
5818 """Like split_commands, but converts numbers to int data type"""
5819 #x = [int(i) if i.isdigit() else i for i in [token.strip() for token in re.split(r"[\s]+", line, splits)]]
5820 x
= map (lambda i
: (i
.isdigit() and int(i
)) or i
, [token
.strip() for token
in re
.split(r
"[\s]+", line
, splits
)])
5824 def split_option_with_columns(self
, line
):
5825 """Split a line in a command and a list of words"""
5826 cmd
, columns
= self
.split_option(line
)
5827 return cmd
, [self
.strip_table_from_column(c
) for c
in re
.compile(r
'\s+').split(columns
)]
5830 def strip_table_from_column(self
, column
):
5831 """Cut off the table name, because it is possible
5832 to say service_state instead of state"""
5833 bygroupmatch
= re
.compile('(\w+)by.*group').search(self
.table
)
5835 return re
.sub(re
.sub('s$', '', bygroupmatch
.group(1)) + '_', '', column
, 1)
5837 return re
.sub(re
.sub('s$', '', self
.table
) + '_', '', column
, 1)
5840 def parse_input(self
, data
):
5841 """Parse the lines of a livestatus request.
5843 This function looks for keywords in input lines and
5844 sets the attributes of the request object
5847 for line
in [line
.strip() for line
in data
.splitlines()]:
5848 # Tools like NagVis send KEYWORK:option, and we prefer to have
5849 # a space folowing the :
5850 if ':' in line
and not ' ' in line
:
5851 line
= line
.replace(':', ': ')
5852 keyword
= line
.split(' ')[0].rstrip(':')
5853 if keyword
== 'GET': # Get the name of the base table
5854 cmd
, self
.table
= self
.split_command(line
)
5855 self
.set_default_out_map_name()
5856 elif keyword
== 'Columns': # Get the names of the desired columns
5857 cmd
, self
.columns
= self
.split_option_with_columns(line
)
5858 self
.response
.columnheaders
= 'off'
5859 elif keyword
== 'ResponseHeader':
5860 cmd
, responseheader
= self
.split_option(line
)
5861 self
.response
.responseheader
= responseheader
5862 elif keyword
== 'OutputFormat':
5863 cmd
, outputformat
= self
.split_option(line
)
5864 self
.response
.outputformat
= outputformat
5865 elif keyword
== 'KeepAlive':
5866 cmd
, keepalive
= self
.split_option(line
)
5867 self
.response
.keepalive
= keepalive
5868 elif keyword
== 'ColumnHeaders':
5869 cmd
, columnheaders
= self
.split_option(line
)
5870 self
.response
.columnheaders
= columnheaders
5871 elif keyword
== 'Limit':
5872 cmd
, self
.limit
= self
.split_option(line
)
5873 elif keyword
== 'Filter':
5875 cmd
, attribute
, operator
, reference
= self
.split_option(line
, 3)
5877 cmd
, attribute
, operator
, reference
= self
.split_option(line
, 2) + ['']
5878 if operator
in ['=', '>', '>=', '<', '<=', '=~', '~', '~~', '!=', '!>', '!>=', '!<', '!<=']:
5879 # Cut off the table name
5880 attribute
= self
.strip_table_from_column(attribute
)
5881 # Some operators can simply be negated
5882 if operator
in ['!>', '!>=', '!<', '!<=']:
5883 operator
= { '!>' : '<=', '!>=' : '<', '!<' : '>=', '!<=' : '>' }[operator
]
5884 # Put a function on top of the filter_stack which implements
5885 # the desired operation
5886 self
.filtercolumns
.append(attribute
)
5887 self
.prefiltercolumns
.append(attribute
)
5888 self
.filter_stack
.put(self
.make_filter(operator
, attribute
, reference
))
5889 if self
.table
== 'log':
5890 if attribute
== 'time':
5891 self
.sql_filter_stack
.put(self
.make_sql_filter(operator
, attribute
, reference
))
5893 print "illegal operation", operator
5894 pass # illegal operation
5895 elif keyword
== 'And':
5896 cmd
, andnum
= self
.split_option(line
)
5897 # Take the last andnum functions from the stack
5898 # Construct a new function which makes a logical and
5899 # Put the function back onto the stack
5900 self
.filter_stack
.and_elements(andnum
)
5901 elif keyword
== 'Or':
5902 cmd
, ornum
= self
.split_option(line
)
5903 # Take the last ornum functions from the stack
5904 # Construct a new function which makes a logical or
5905 # Put the function back onto the stack
5906 self
.filter_stack
.or_elements(ornum
)
5907 elif keyword
== 'StatsGroupBy':
5908 cmd
, stats_group_by
= self
.split_option_with_columns(line
)
5909 self
.filtercolumns
.extend(stats_group_by
)
5910 self
.stats_group_by
.extend(stats_group_by
)
5911 # Deprecated. If your query contains at least one Stats:-header
5912 # then Columns: has the meaning of the old StatsGroupBy: header
5913 elif keyword
== 'Stats':
5914 self
.stats_request
= True
5916 cmd
, attribute
, operator
, reference
= self
.split_option(line
, 3)
5917 if attribute
in ['sum', 'min', 'max', 'avg', 'std'] and reference
.find('as ', 3) != -1:
5918 attribute
, operator
= operator
, attribute
5919 asas
, alias
= reference
.split(' ')
5920 self
.aliases
.append(alias
)
5921 elif attribute
in ['sum', 'min', 'max', 'avg', 'std'] and reference
== '=':
5922 # Workaround for thruk-cmds like: Stats: sum latency =
5923 attribute
, operator
= operator
, attribute
5926 cmd
, attribute
, operator
= self
.split_option(line
, 3)
5927 if attribute
in ['sum', 'min', 'max', 'avg', 'std']:
5928 attribute
, operator
= operator
, attribute
5930 attribute
= self
.strip_table_from_column(attribute
)
5931 if operator
in ['=', '>', '>=', '<', '<=', '=~', '~', '~~', '!=', '!>', '!>=', '!<', '!<=']:
5932 if operator
in ['!>', '!>=', '!<', '!<=']:
5933 operator
= { '!>' : '<=', '!>=' : '<', '!<' : '>=', '!<=' : '>' }[operator
]
5934 self
.filtercolumns
.append(attribute
)
5935 self
.stats_columns
.append(attribute
)
5936 self
.stats_filter_stack
.put(self
.make_filter(operator
, attribute
, reference
))
5937 self
.stats_postprocess_stack
.put(self
.make_filter('count', attribute
, None))
5938 elif operator
in ['sum', 'min', 'max', 'avg', 'std']:
5939 self
.stats_columns
.append(attribute
)
5940 self
.stats_filter_stack
.put(self
.make_filter('dummy', attribute
, None))
5941 self
.stats_postprocess_stack
.put(self
.make_filter(operator
, attribute
, None))
5943 print "illegal operation", operator
5944 pass # illegal operation
5945 elif keyword
== 'StatsAnd':
5946 cmd
, andnum
= self
.split_option(line
)
5947 self
.stats_filter_stack
.and_elements(andnum
)
5948 elif keyword
== 'StatsOr':
5949 cmd
, ornum
= self
.split_option(line
)
5950 self
.stats_filter_stack
.or_elements(ornum
)
5951 elif keyword
== 'Separators':
5952 cmd
, sep1
, sep2
, sep3
, sep4
= line
.split(' ', 5)
5953 self
.response
.separators
= map(lambda x
: chr(int(x
)), [sep1
, sep2
, sep3
, sep4
])
5954 elif keyword
== 'Localtime':
5955 cmd
, self
.client_localtime
= self
.split_option(line
)
5956 elif keyword
== 'COMMAND':
5957 cmd
, self
.extcmd
= line
.split(' ', 1)
5959 # This line is not valid or not implemented
5960 print "Received a line of input which i can't handle : '%s'" % line
5964 def launch_query(self
):
5965 """Prepare the request object's filter stacks"""
5967 # External command are send back to broker
5968 e
= ExternalCommand(self
.extcmd
)
5969 self
.return_queue
.put(e
)
5972 # A minimal integrity check
5976 # Make columns unique
5977 self
.filtercolumns
= list(set(self
.filtercolumns
))
5978 self
.prefiltercolumns
= list(set(self
.prefiltercolumns
))
5979 self
.stats_columns
= list(set(self
.stats_columns
))
5981 if self
.stats_request
:
5982 if len(self
.columns
) > 0:
5983 # StatsGroupBy is deprecated. Columns: can be used instead
5984 self
.stats_group_by
= self
.columns
5985 elif len(self
.stats_group_by
) > 0:
5986 self
.columns
= self
.stats_group_by
+ self
.stats_columns
5987 #if len(self.stats_columns) > 0 and len(self.columns) == 0:
5988 if len(self
.stats_columns
) > 0:
5989 self
.columns
= self
.stats_columns
+ self
.columns
5991 # Make one big filter where the single filters are anded
5992 self
.filter_stack
.and_elements(self
.filter_stack
.qsize())
5994 # Remember the number of stats filters. We need these numbers as columns later.
5995 # But we need to ask now, because get_live_data() will empty the stack
5996 num_stats_filters
= self
.stats_filter_stack
.qsize()
5997 if self
.table
== 'log':
5998 self
.sql_filter_stack
.and_elements(self
.sql_filter_stack
.qsize())
5999 result
= self
.get_live_data_log()
6001 # If the pnpgraph_present column is involved, then check
6002 # with each request if the pnp perfdata path exists
6003 if 'pnpgraph_present' in self
.columns
+ self
.filtercolumns
+ self
.prefiltercolumns
and self
.pnp_path
and os
.access(self
.pnp_path
, os
.R_OK
):
6004 self
.pnp_path_readable
= True
6006 self
.pnp_path_readable
= False
6007 # Apply the filters on the broker's host/service/etc elements
6009 result
= self
.get_live_data()
6010 if self
.stats_request
:
6011 self
.columns
= range(num_stats_filters
)
6012 if self
.stats_group_by
:
6013 self
.columns
= tuple(list(self
.stats_group_by
) + list(self
.columns
))
6014 if len(self
.aliases
) == 0:
6015 #If there were Stats: staments without "as", show no column headers at all
6016 self
.response
.columnheaders
= 'off'
6018 self
.response
.columnheaders
= 'on'
6021 except Exception, e
:
6023 print "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
6025 traceback
.print_exc(32)
6026 print "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
6029 def get_live_data(self
):
6030 """Find the objects which match the request.
6032 This function scans a list of objects (hosts, services, etc.) and
6033 applies the filter functions first. The remaining objects are
6034 converted to simple dicts which have only the keys that were
6035 requested through Column: attributes.
6039 # Get the function which implements the Filter: statements
6040 filter_func
= self
.filter_stack
.get_stack()
6041 out_map
= self
.out_map
[self
.out_map_name
]
6042 filter_map
= dict([(k
, out_map
.get(k
)) for k
in self
.filtercolumns
])
6043 output_map
= dict([(k
, out_map
.get(k
)) for k
in self
.columns
]) or out_map
6044 without_filter
= len(self
.filtercolumns
) == 0
6046 if self
.table
in ['hosts', 'services', 'downtimes', 'comments', 'hostgroups', 'servicegroups', 'hostsbygroup', 'servicesbygroup', 'servicesbyhostgroup']:
6047 #Scan through the objects and apply the Filter: rules
6048 if self
.table
== 'hosts':
6050 filtresult
= [self
.create_output(output_map
, y
) for y
in (x
for x
in self
.hosts
.values() if (without_filter
or filter_func(self
.create_output(filter_map
, x
))))]
6052 hosts
= sorted(self
.hosts
.values(), key
= lambda k
: k
.host_name
)
6053 filtresult
= [self
.create_output(output_map
, y
) for y
in (x
for x
in hosts
if (without_filter
or filter_func(self
.create_output(filter_map
, x
))))]
6054 filtresult
= filtresult
[:self
.limit
]
6055 elif self
.table
== 'hostsbygroup':
6056 # instead of self.hosts.values()
6057 # loop over hostgroups, then over members, then flatten the list, then add a hostgroup attribute to each host
6059 filtresult
= [self
.create_output(output_map
, x
) for x
in [
6061 setattr(hohg
[0], 'hostgroup', hohg
[1]) or hohg
[0] for hohg
in [
6062 # (host, hg), (host, hg), ... host objects are individuals
6063 (copy
.copy(item0
), inner_list0
[1]) for inner_list0
in [
6064 # ([host, host, ...], hg), ([host], hg), ...
6065 (sorted(hg1
.members
, key
= lambda k
: k
.host_name
), hg1
) for hg1
in
6066 # hostgroups sorted by hostgroup_name
6067 sorted([hg0
for hg0
in self
.hostgroups
.values() if hg0
.members
], key
= lambda k
: k
.hostgroup_name
)
6068 ] for item0
in inner_list0
[0]
6070 ] if (without_filter
or filter_func(self
.create_output(filter_map
, host
)))
6073 filtresult
= filtresult
[:self
.limit
]
6074 elif self
.table
== 'services':
6076 filtresult
= [self
.create_output(output_map
, y
) for y
in (x
for x
in self
.services
.values() if (without_filter
or filter_func(self
.create_output(filter_map
, x
))))]
6078 services
= sorted(self
.services
.values(), key
= lambda k
: (k
.host_name
, k
.service_description
))
6079 filtresult
= [self
.create_output(output_map
, y
) for y
in (x
for x
in services
if (without_filter
or filter_func(self
.create_output(filter_map
, x
))))]
6080 filtresult
= filtresult
[:self
.limit
]
6081 elif self
.table
== 'servicesbygroup':
6082 # Here we have more generators instead of list comprehensions, but in fact it makes no difference
6083 # (Tested with 2000 services)
6084 # Multisite actually uses this with limit. This is a temporary workaround because limiting requires sorting
6086 filtresult
= [self
.create_output(output_map
, x
) for x
in (
6088 setattr(servicesg
[0], 'servicegroup', servicesg
[1]) or servicesg
[0] for servicesg
in (
6089 # (service, sg), (service, sg), ... service objects are individuals
6090 (copy
.copy(item0
), inner_list0
[1]) for inner_list0
in (
6091 # ([service, service], sg), ([service, service, ...], sg), ... services are sorted
6092 (sorted(sg1
.members
, key
= lambda k
: k
.get_name()), sg1
) for sg1
in
6093 # servicegroups, sorted by their servicegroup_name
6094 sorted([sg0
for sg0
in self
.servicegroups
.values() if sg0
.members
], key
= lambda k
: k
.servicegroup_name
)
6095 ) for item0
in inner_list0
[0]
6097 ) if (without_filter
or filter_func(self
.create_output(filter_map
, svc
)))
6100 filtresult
= filtresult
[:self
.limit
]
6101 elif self
.table
== 'servicesbyhostgroup':
6102 # We will use prefiltercolumns here for some serious speedup.
6103 # For example, if nagvis wants Filter: host_groups >= hgxy
6104 # we don't have to use the while list of hostgroups in
6105 # the innermost loop
6106 # Filter: host_groups >= linux-servers
6107 # host_groups is a service attribute
6108 # We can get all services of all hosts of all hostgroups and filter at the end
6109 # But it would save a lot of time to already filter the hostgroups. This means host_groups must be hard-coded
6110 # Also host_name, but then we must filter the second step.
6111 # And a mixture host_groups/host_name with FilterAnd/Or? Must have several filter functions
6112 # This is still under construction. The code can be made simpler
6114 filtresult
= [self
.create_output(output_map
, x
) for x
in (
6116 setattr(svchgrp
[0], 'hostgroup', svchgrp
[1]) or svchgrp
[0] for svchgrp
in (
6117 # (service, hostgroup), (service, hostgroup), (service, hostgroup), ... service objects are individuals
6118 (copy
.copy(item1
), inner_list1
[1]) for inner_list1
in (
6119 # ([service, service, ...], hostgroup), ([service, ...], hostgroup), ... flattened by host. only if a host has services. sorted by service_description
6120 (sorted(item0
.services
, key
= lambda k
: k
.service_description
), inner_list0
[1]) for inner_list0
in (
6121 # ([host, host, ...], hostgroup), ([host, host, host, ...], hostgroup), ... sorted by host_name
6122 (sorted(hg1
.members
, key
= lambda k
: k
.host_name
), hg1
) for hg1
in # ([host, host], hg), ([host], hg),... hostgroup.members->explode->sort
6123 # hostgroups, sorted by hostgroup_name
6124 sorted([hg0
for hg0
in self
.hostgroups
.values() if hg0
.members
], key
= lambda k
: k
.hostgroup_name
)
6125 ) for item0
in inner_list0
[0] if item0
.services
6126 ) for item1
in inner_list1
[0]
6128 ) if (without_filter
or filter_func(self
.create_output(filter_map
, svc
)))
6131 filtresult
= filtresult
[:self
.limit
]
6132 elif self
.table
== 'downtimes':
6134 filtresult
= [self
.create_output(output_map
, y
) for y
in reduce(list.__add
__, [x
.downtimes
for x
in self
.services
.values() + self
.hosts
.values() if len(x
.downtimes
) > 0], [])]
6136 prefiltresult
= [d
for d
in reduce(list.__add
__, [x
.downtimes
for x
in self
.services
.values() + self
.hosts
.values() if len(x
.downtimes
) > 0], []) if filter_func(self
.create_output(filter_map
, d
))]
6137 filtresult
= [self
.create_output(output_map
, x
) for x
in prefiltresult
]
6138 elif self
.table
== 'comments':
6140 filtresult
= [self
.create_output(output_map
, y
) for y
in reduce(list.__add
__, [x
.comments
for x
in self
.services
.values() + self
.hosts
.values() if len(x
.comments
) > 0], [])]
6142 prefiltresult
= [c
for c
in reduce(list.__add
__, [x
.comments
for x
in self
.services
.values() + self
.hosts
.values() if len(x
.comments
) > 0], []) if filter_func(self
.create_output(filter_map
, c
))]
6143 filtresult
= [self
.create_output(output_map
, x
) for x
in prefiltresult
]
6144 elif self
.table
== 'hostgroups':
6146 filtresult
= [y
for y
in [self
.create_output(output_map
, x
) for x
in self
.hostgroups
.values()] if filter_func(y
)]
6148 prefiltresult
= [x
for x
in self
.hostgroups
.values() if filter_func(self
.create_output(filter_map
, x
))]
6149 filtresult
= [self
.create_output(output_map
, x
) for x
in prefiltresult
]
6150 elif self
.table
== 'servicegroups':
6152 filtresult
= [y
for y
in [self
.create_output(output_map
, x
) for x
in self
.servicegroups
.values()] if filter_func(y
)]
6154 prefiltresult
= [x
for x
in self
.servicegroups
.values() if filter_func(self
.create_output(filter_map
, x
))]
6155 filtresult
= [self
.create_output(output_map
, x
) for x
in prefiltresult
]
6158 elif self
.table
== 'contacts':
6159 filtresult
= [self
.create_output(output_map
, y
) for y
in (x
for x
in self
.contacts
.values() if (without_filter
or filter_func(self
.create_output(filter_map
, x
))))]
6161 filtresult
= filtresult
[:self
.limit
]
6162 elif self
.table
== 'commands':
6163 for c
in self
.commands
.values():
6164 result
.append(self
.create_output(output_map
, c
))
6165 elif self
.table
== 'schedulers':
6166 for s
in self
.schedulers
.values():
6167 result
.append(self
.create_output(output_map
, s
))
6168 elif self
.table
== 'pollers':
6169 for s
in self
.pollers
.values():
6170 result
.append(self
.create_output(output_map
, s
))
6171 elif self
.table
== 'reactionners':
6172 for s
in self
.reactionners
.values():
6173 result
.append(self
.create_output(output_map
, s
))
6174 elif self
.table
== 'brokers':
6175 for s
in self
.brokers
.values():
6176 result
.append(self
.create_output(output_map
, s
))
6177 elif self
.table
== 'problems':
6178 # We will crate a problems list first with all problems and source in it
6179 # TODO : create with filter
6181 for h
in self
.hosts
.values():
6183 pb
= Problem(h
, h
.impacts
)
6185 for s
in self
.services
.values():
6187 pb
= Problem(s
, s
.impacts
)
6191 result
.append(self
.create_output(output_map
, pb
))
6192 elif self
.table
== 'status':
6193 out_map
= self
.out_map
['Config']
6194 for c
in self
.configs
.values():
6195 result
.append(self
.create_output(output_map
, c
))
6196 elif self
.table
== 'columns':
6198 'description' : 'A description of the column' , 'name' : 'description' , 'table' : 'columns' , 'type' : 'string' })
6200 'description' : 'The name of the column within the table' , 'name' : 'name' , 'table' : 'columns' , 'type' : 'string' })
6202 'description' : 'The name of the table' , 'name' : 'table' , 'table' : 'columns' , 'type' : 'string' })
6204 'description' : 'The data type of the column (int, float, string, list)' , 'name' : 'type' , 'table' : 'columns' , 'type' : 'string' })
6205 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' }
6206 for obj
in sorted(LiveStatus
.out_map
, key
=lambda x
: x
):
6207 if obj
in tablenames
:
6208 for attr
in LiveStatus
.out_map
[obj
]:
6209 if 'description' in LiveStatus
.out_map
[obj
][attr
] and LiveStatus
.out_map
[obj
][attr
]['description']:
6210 result
.append({ 'description' : LiveStatus
.out_map
[obj
][attr
]['description'], 'name' : attr
, 'table' : tablenames
[obj
], 'type' : LiveStatus
.out_map
[obj
][attr
]['type'] })
6212 result
.append({'description' : 'to_do_desc', 'name' : attr
, 'table' : tablenames
[obj
], 'type' : LiveStatus
.out_map
[obj
][attr
]['type'] })
6214 if self
.stats_request
:
6215 result
= self
.statsify_result(result
)
6216 #print "result is", result
6220 def get_live_data_log(self
):
6221 """Like get_live_data, but for log objects"""
6222 filter_func
= self
.filter_stack
.get_stack()
6223 sql_filter_func
= self
.sql_filter_stack
.get_stack()
6224 out_map
= self
.out_map
[self
.out_map_name
]
6225 filter_map
= dict([(k
, out_map
.get(k
)) for k
in self
.filtercolumns
])
6226 output_map
= dict([(k
, out_map
.get(k
)) for k
in self
.columns
]) or out_map
6227 without_filter
= len(self
.filtercolumns
) == 0
6229 if self
.table
== 'log':
6230 out_map
= self
.out_map
['Logline']
6231 # We can apply the filterstack here as well. we have columns and filtercolumns.
6232 # the only additional step is to enrich log lines with host/service-attributes
6233 # A timerange can be useful for a faster preselection of lines
6234 filter_clause
, filter_values
= sql_filter_func()
6235 c
= self
.dbconn
.cursor()
6237 if sqlite3
.paramstyle
== 'pyformat':
6239 for m
in re
.finditer(r
"\?", filter_clause
):
6240 filter_clause
= re
.sub('\\?', '%(' + str(matchcount
) + ')s', filter_clause
, 1)
6242 filter_values
= dict(zip([str(x
) for x
in xrange(len(filter_values
))], filter_values
))
6243 c
.execute('SELECT * FROM logs WHERE %s' % filter_clause
, filter_values
)
6244 except sqlite3
.Error
, e
:
6245 print "An error occurred:", e
.args
[0]
6246 dbresult
= c
.fetchall()
6247 if sqlite3
.paramstyle
== 'pyformat':
6248 dbresult
= [self
.row_factory(c
, d
) for d
in dbresult
]
6250 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
)))]
6251 filtresult
= [self
.create_output(output_map
, x
) for x
in prefiltresult
]
6252 if self
.stats_request
:
6253 result
= self
.statsify_result(filtresult
)
6255 # Results are host/service/etc dicts with the requested attributes
6256 # Columns: = keys of the dicts
6259 #print "result is", result
6263 def create_output(self
, out_map
, elt
):
6264 """Convert an object to a dict with selected keys."""
6266 display_attributes
= out_map
.keys()
6267 for display
in display_attributes
:
6269 hook
= out_map
[display
]['hook']
6273 output
[display
] = value
6277 def statsify_result(self
, filtresult
):
6278 """Applies the stats filter functions to the result.
6281 stats_group_by is ["service_description", "host_name"]
6282 filtresult is a list of elements which have, among others, service_description and host_name attributes
6285 groupedresult is a dict where the keys are unique combinations of the stats_group_by attributes
6286 where the values are arrays of elements which have those attributes in common
6288 groupedresult[("host1","svc1")] = { host_name : "host1", service_description : "svc1", state : 2, in_downtime : 0 }
6289 groupedresult[("host1","svc2")] = { host_name : "host1", service_description : "svc2", state : 0, in_downtime : 0 }
6290 groupedresult[("host1","svc2")] = { host_name : "host1", service_description : "svc2", state : 1, in_downtime : 1 }
6292 resultdict is a dict where the keys are unique combinations of the stats_group_by attributes
6293 where the values are dicts
6294 resultdict values are dicts where the keys are attribute names from stats_group_by
6295 where the values are attribute values
6297 resultdict[("host1","svc1")] = { host_name : "host1", service_description : "svc1" }
6298 resultdict[("host1","svc2")] = { host_name : "host1", service_description : "svc2" }
6299 These attributes are later used as output columns
6302 Run the filters (1 filter for each Stats: statement) and the postprocessors (default: len)
6303 The filters are numbered. After each run, add the result to resultdictay as <filterno> : <result>
6304 Example for Stats: state = 0\nStats: state = 1\nStats: state = 2\nStats: state = 3\n
6305 resultdict[("host1","svc1")] = { host_name : "host1", service_description : "svc1", 0 : 0, 1 : 0, 2 : 1, 3 : 0 }
6306 resultdict[("host1","svc2")] = { host_name : "host1", service_description : "svc2", 0 : 1, 1 : 1, 2 : 0, 3 : 0 }
6309 Create the final result array from resultdict
6314 if self
.stats_group_by
:
6315 # stats_group_by is a list in newer implementations
6316 if isinstance(self
.stats_group_by
, list):
6317 self
.stats_group_by
= tuple(self
.stats_group_by
)
6319 self
.stats_group_by
= tuple([self
.stats_group_by
])
6320 # Break up filtresult and prepare resultdict
6321 # rseultarr is not a simple array (for a single result line)
6322 # It is a dict with the statsgroupyby: as key
6324 for elem
in filtresult
:
6325 # Make a tuple consisting of the stats_group_by values
6326 stats_group_by_values
= tuple([elem
[c
] for c
in self
.stats_group_by
])
6327 if not stats_group_by_values
in groupedresult
:
6328 groupedresult
[stats_group_by_values
] = []
6329 groupedresult
[stats_group_by_values
].append(elem
)
6330 for group
in groupedresult
:
6331 # All possible combinations of stats_group_by values. group is a tuple
6332 resultdict
[group
] = dict(zip(self
.stats_group_by
, group
))
6334 #The number of Stats: statements
6335 #For each statement there is one function on the stack
6336 maxidx
= self
.stats_filter_stack
.qsize()
6337 for i
in range(maxidx
):
6338 # Stats:-statements were put on a Lifo, so we need to reverse the number
6339 #stats_number = str(maxidx - i - 1)
6340 stats_number
= maxidx
- i
- 1
6341 # First, get a filter for the attributes mentioned in Stats: statements
6342 filtfunc
= self
.stats_filter_stack
.get()
6343 # Then, postprocess (sum, max, min,...) the results
6344 postprocess
= self
.stats_postprocess_stack
.get()
6345 if self
.stats_group_by
:
6346 # Calc statistics over _all_ elements of groups
6347 # which share the same stats_filter_by
6348 for group
in groupedresult
:
6349 resultdict
[group
][stats_number
] = postprocess(filter(filtfunc
, groupedresult
[group
]))
6351 # Calc statistics over _all_ elements of filtresult
6352 resultdict
[stats_number
] = postprocess(filter(filtfunc
, filtresult
))
6353 if self
.stats_group_by
:
6354 for group
in resultdict
:
6355 result
.append(resultdict
[group
])
6357 # Without StatsGroupBy: we have only one line
6358 result
= [resultdict
]
6362 def make_filter(self
, operator
, attribute
, reference
):
6363 if reference
!= None:
6364 # Reference is now datatype string. The referring object attribute on the other hand
6365 # may be an integer. (current_attempt for example)
6366 # So for the filter to work correctly (the two values compared must be
6367 # of the same type), we need to convert the reference to the desired type
6368 converter
= self
.find_converter(attribute
)
6370 reference
= converter(reference
)
6372 # The filters are closures.
6373 # Add parameter Class (Host, Service), lookup datatype (default string), convert reference
6375 return ref
[attribute
] == reference
6377 def eq_nocase_filter(ref
):
6378 return ref
[attribute
].lower() == reference
.lower()
6381 return ref
[attribute
] != reference
6384 return ref
[attribute
] > reference
6387 return ref
[attribute
] >= reference
6390 return ref
[attribute
] < reference
6393 return ref
[attribute
] <= reference
6395 def contains_filter(ref
):
6396 return reference
in ref
[attribute
].split(',')
6398 def match_filter(ref
):
6399 p
= re
.compile(reference
)
6400 return p
.search(ref
[attribute
])
6402 def match_nocase_filter(ref
):
6403 p
= re
.compile(reference
, re
.I
)
6404 return p
.search(ref
[attribute
])
6406 def ge_contains_filter(ref
):
6407 if isinstance(ref
[attribute
], list):
6408 return reference
in ref
[attribute
]
6410 return ref
[attribute
] >= reference
6412 def dummy_filter(ref
):
6415 def count_postproc(ref
):
6418 def extract_postproc(ref
):
6419 return [float(obj
[attribute
]) for obj
in ref
]
6421 def sum_postproc(ref
):
6422 return sum(float(obj
[attribute
]) for obj
in ref
)
6424 def max_postproc(ref
):
6426 return max(float(obj
[attribute
]) for obj
in ref
)
6429 def min_postproc(ref
):
6431 return min(float(obj
[attribute
]) for obj
in ref
)
6434 def avg_postproc(ref
):
6436 return sum(float(obj
[attribute
]) for obj
in ref
) / len(ref
)
6439 def std_postproc(ref
):
6444 elif operator
== '!=':
6446 elif operator
== '>':
6448 elif operator
== '>=':
6449 return ge_contains_filter
6450 elif operator
== '<':
6452 elif operator
== '<=':
6454 elif operator
== '=~':
6455 return eq_nocase_filter
6456 elif operator
== '~':
6458 elif operator
== '~~':
6459 return match_nocase_filter
6460 elif operator
== 'dummy':
6462 elif operator
== 'sum':
6464 elif operator
== 'max':
6466 elif operator
== 'min':
6468 elif operator
== 'avg':
6470 elif operator
== 'std':
6472 elif operator
== 'count':
6473 # postprocess for stats
6474 return count_postproc
6475 elif operator
== 'extract':
6476 # postprocess for max,min,...
6477 return extract_postproc
6479 raise "wrong operation", operator
6482 def make_sql_filter(self
, operator
, attribute
, reference
):
6483 # The filters are text fragments which are put together to form a sql where-condition finally.
6484 # Add parameter Class (Host, Service), lookup datatype (default string), convert reference
6487 return ['%s IS NULL' % attribute
, ()]
6489 return ['%s = ?' % attribute
, (reference
, )]
6492 return ['%s IS NOT NULL' % attribute
, ()]
6494 return ['%s != ?' % attribute
, (reference
, )]
6496 return ['%s > ?' % attribute
, (reference
, )]
6498 return ['%s >= ?' % attribute
, (reference
, )]
6500 return ['%s < ?' % attribute
, (reference
, )]
6502 return ['%s <= ?' % attribute
, (reference
, )]
6504 return ['%s LIKE ?' % attribute
, ('%'+reference
+'%', )]
6509 if operator
== '>=':
6513 if operator
== '<=':
6515 if operator
== '!=':