Skip to content

Commit 566d315

Browse files
committed
Some doc updates and several updates and fixes:
- fix serialization - improve arbiter/scheduler WS interface - improve retention test
1 parent 9e45095 commit 566d315

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1547
-848
lines changed

alignak/basemodule.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ def manage_signal(self, sig, frame): # pylint: disable=unused-argument
351351

352352
if sig == signal.SIGHUP:
353353
# if SIGHUP, reload configuration in arbiter
354-
logger.info("Module are not able to reload their configuration. "
354+
logger.info("Modules are not able to reload their configuration. "
355355
"Stopping the module...")
356356

357357
logger.info("Request to stop the module")

alignak/daemon.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ class Daemon(object):
356356
'alignak_monitor':
357357
StringProp(default=u''),
358358
'alignak_monitor_period':
359-
IntegerProp(default=30),
359+
IntegerProp(default=60),
360360
'alignak_monitor_username':
361361
StringProp(default=u''),
362362
'alignak_monitor_password':
@@ -651,6 +651,8 @@ def __init__(self, name, **kwargs):
651651
# Make it an absolute path file in the pid directory
652652
if self.pid_filename != os.path.abspath(self.pid_filename):
653653
self.pid_filename = os.path.abspath(os.path.join(self.workdir, self.pid_filename))
654+
self.workdir = os.path.dirname(self.pid_filename)
655+
print("Daemon working directory: %s" % self.workdir)
654656
print("Daemon '%s' pid file: %s" % (self.name, self.pid_filename))
655657
self.pre_log.append(("INFO",
656658
"Daemon '%s' pid file: %s" % (self.name, self.pid_filename)))
@@ -1342,6 +1344,7 @@ def check_parallel_run(self): # pragma: no cover, not with unit tests...
13421344
self.pre_log.append(("DEBUG", "Replacing former instance: %d" % pid))
13431345
try:
13441346
pgid = os.getpgid(pid)
1347+
# SIGQUIT to terminate and dump core
13451348
os.killpg(pgid, signal.SIGQUIT)
13461349
except os.error as err:
13471350
if err.errno != errno.ESRCH:

alignak/daemons/arbiterdaemon.py

+30-6
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,9 @@ def __init__(self, **kwargs):
121121
self.daemons_last_reachable_check = 0
122122
self.my_daemons = {}
123123

124-
# My report monitor interface
124+
# My report monitor interface and status
125125
self.my_monitor = None
126+
self.my_status = 0
126127

127128
super(Arbiter, self).__init__(kwargs.get('daemon_name', 'Default-Arbiter'), **kwargs)
128129

@@ -1546,8 +1547,8 @@ def do_loop_turn(self):
15461547
self.wait_for_master_death()
15471548
return
15481549

1549-
if self.alignak_monitor and (self.loop_count % self.alignak_monitor_period == 1):
1550-
self.push_passive_check(details=True)
1550+
if self.loop_count % self.alignak_monitor_period == 1:
1551+
self.get_alignak_status(details=True)
15511552

15521553
# Maybe an external process requested Alignak stop...
15531554
if self.kill_request:
@@ -1806,7 +1807,7 @@ def get_monitoring_problems(self):
18061807
if not satellite.active:
18071808
continue
18081809

1809-
if 'problems' in satellite.statistics:
1810+
if satellite.statistics and 'problems' in satellite.statistics:
18101811
res['problems'][satellite.name] = {
18111812
'_freshness': satellite.statistics['_freshness'],
18121813
'problems': satellite.statistics['problems']
@@ -1872,14 +1873,14 @@ def get_livesynthesis(self):
18721873
'livesynthesis': satellite.statistics['livesynthesis']
18731874
}
18741875
# Cumulated live synthesis
1875-
for prop in res['livesynthesis']['_overall']:
1876+
for prop in res['livesynthesis']['_overall']['livesynthesis']:
18761877
if prop in satellite.statistics['livesynthesis']:
18771878
res['livesynthesis']['_overall']['livesynthesis'][prop] += \
18781879
satellite.statistics['livesynthesis'][prop]
18791880

18801881
return res
18811882

1882-
def push_passive_check(self, details=False):
1883+
def get_alignak_status(self, details=False):
18831884
# pylint: disable=too-many-locals
18841885
"""Push the alignak overall state as a passive check
18851886
@@ -2020,6 +2021,22 @@ def push_passive_check(self, details=False):
20202021
][state],
20212022
"long_output": '\n'.join(long_output)
20222023
})
2024+
log_level = 'info'
2025+
if state == 1: # DOWN
2026+
log_level = 'error'
2027+
if state == 2: # UNREACHABLE
2028+
log_level = 'warning'
2029+
if self.conf.log_alignak_checks or state > 0:
2030+
self.add(make_monitoring_log(log_level, 'ALIGNAK CHECK;%s;%d;%s;%s' % (
2031+
self.alignak_name, state, res['livestate']['output'],
2032+
res['livestate']['long_output']
2033+
)))
2034+
if self.my_status != state:
2035+
self.my_status = state
2036+
self.add(make_monitoring_log(log_level, 'ALIGNAK ALERT;%s;%d;%s;%s' % (
2037+
self.alignak_name, state, res['livestate']['output'],
2038+
res['livestate']['long_output']
2039+
)))
20232040

20242041
if self.alignak_monitor:
20252042
logger.debug("Pushing Alignak passive check to %s: %s", self.alignak_monitor, res)
@@ -2036,6 +2053,13 @@ def push_passive_check(self, details=False):
20362053
else:
20372054
logger.debug("No configured Alignak monitor to receive: %s", res)
20382055

2056+
# Send our own events to the Alignak logger
2057+
for event in self.events:
2058+
event.prepare()
2059+
make_monitoring_log(event.data['level'], event.data['message'],
2060+
timestamp=event.creation_time, to_logger=True)
2061+
self.events = []
2062+
20392063
return res
20402064

20412065
def main(self):

alignak/daemons/brokerdaemon.py

-1
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,6 @@ def setup_new_conf(self):
326326
rs_conf)
327327
my_satellites[new_link.uuid] = new_link
328328
logger.info("I got a new %s satellite: %s", link_type[:-1], new_link)
329-
# print("My new %s satellite: %s" % (link_type, new_link))
330329

331330
new_link.running_id = running_id
332331
new_link.external_commands = external_commands

alignak/dispatcher.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ def get_scheduler_ordered_list(self, realm):
450450
List is ordered as: alive first, then spare (if any), then dead scheduler links
451451
452452
:param realm: realm we want scheduler from
453-
:type realm: object
453+
:type realm: alignak.objects.realm.Realm
454454
:return: sorted scheduler list
455455
:rtype: list[alignak.objects.schedulerlink.SchedulerLink]
456456
"""

alignak/http/arbiter_interface.py

+84-8
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from alignak.http.generic_interface import GenericInterface
2727
from alignak.util import split_semicolon
2828
from alignak.external_command import ExternalCommand
29+
from alignak.misc.serialization import serialize, unserialize
2930

3031
logger = logging.getLogger(__name__) # pylint: disable=invalid-name
3132

@@ -248,7 +249,7 @@ def wait_new_conf(self):
248249

249250
@cherrypy.expose
250251
@cherrypy.tools.json_out()
251-
def get_alignak_status(self, details=False):
252+
def alignak_status(self, details=False):
252253
"""Get the overall alignak status
253254
254255
Returns a list of the satellites as in:
@@ -259,19 +260,19 @@ def get_alignak_status(self, details=False):
259260
}
260261
261262
:param details: Details are required (different from 0)
262-
:type details str
263+
:type details bool
263264
264265
:return: dict with key *daemon_type* and value list of daemon name
265266
:rtype: dict
266267
"""
267268
if details is not False:
268269
details = bool(details)
269270

270-
return self.app.push_passive_check(details=details)
271+
return self.app.get_alignak_status(details=details)
271272

272273
@cherrypy.expose
273274
@cherrypy.tools.json_out()
274-
def get_satellites_list(self, daemon_type=''):
275+
def satellites_list(self, daemon_type=''):
275276
"""Get the arbiter satellite names sorted by type
276277
277278
Returns a list of the satellites as in:
@@ -302,7 +303,7 @@ def get_satellites_list(self, daemon_type=''):
302303

303304
@cherrypy.expose
304305
@cherrypy.tools.json_out()
305-
def get_satellites_configuration(self):
306+
def satellites_configuration(self):
306307
"""Return all the configuration data of satellites
307308
308309
:return: dict containing satellites data
@@ -360,7 +361,7 @@ def get_objects_properties(self, table): # pylint: disable=no-self-use, unused-
360361
:rtype: list
361362
"""
362363
return {'_status': u'ERR',
363-
'_message': u"Deprecated in favor of the get_stats endpoint."}
364+
'_message': u"Deprecated in favor of the stats endpoint."}
364365

365366
@cherrypy.expose
366367
@cherrypy.tools.json_in()
@@ -377,7 +378,7 @@ def push_external_command(self, command=None):
377378

378379
@cherrypy.expose
379380
@cherrypy.tools.json_out()
380-
def get_monitoring_problems(self):
381+
def monitoring_problems(self):
381382
"""Get Alignak detailed monitoring status
382383
383384
This will return an object containing the properties of the `get_id`, plus a `problems`
@@ -434,7 +435,7 @@ def get_monitoring_problems(self):
434435

435436
@cherrypy.expose
436437
@cherrypy.tools.json_out()
437-
def get_livesynthesis(self):
438+
def livesynthesis(self):
438439
"""Get Alignak live synthesis
439440
440441
This will return an object containing the properties of the `get_id`, plus a `livesynthesis`
@@ -524,3 +525,78 @@ def get_livesynthesis(self):
524525
res.update(self.get_start_time())
525526
res.update(self.app.get_livesynthesis())
526527
return res
528+
529+
@cherrypy.expose
530+
@cherrypy.tools.json_in()
531+
@cherrypy.tools.json_out()
532+
def object(self, o_type, o_name='None'):
533+
"""Get a monitored object from the arbiter.
534+
535+
Indeed, the arbiter requires the object from its schedulers. It will iterate in
536+
its schedulers list until a matching object is found. Else it will return a Json
537+
structure containing _status and _message properties.
538+
539+
When found, the result is a serialized object which is a Json structure containing:
540+
- content: the serialized object content
541+
- __sys_python_module__: the python class of the returned object
542+
543+
The Alignak unserialize function of the alignak.misc.serialization package allows
544+
to restore the initial object.
545+
546+
.. code-block:: python
547+
548+
from alignak.misc.serialization import unserialize
549+
from alignak.objects.hostgroup import Hostgroup
550+
raw_data = req.get("http://127.0.0.1:7768/object/hostgroup/allhosts")
551+
print("Got: %s / %s" % (raw_data.status_code, raw_data.content))
552+
assert raw_data.status_code == 200
553+
object = raw_data.json()
554+
group = unserialize(object, True)
555+
assert group.__class__ == Hostgroup
556+
assert group.get_name() == 'allhosts'
557+
558+
As an example:
559+
{
560+
"__sys_python_module__": "alignak.objects.hostgroup.Hostgroup",
561+
"content": {
562+
"uuid": "32248642-97dd-4f39-aaa2-5120112a765d",
563+
"name": "",
564+
"hostgroup_name": "allhosts",
565+
"use": [],
566+
"tags": [],
567+
"alias": "All Hosts",
568+
"notes": "",
569+
"definition_order": 100,
570+
"register": true,
571+
"unknown_members": [],
572+
"notes_url": "",
573+
"action_url": "",
574+
575+
"imported_from": "unknown",
576+
"conf_is_correct": true,
577+
"configuration_errors": [],
578+
"configuration_warnings": [],
579+
"realm": "",
580+
"downtimes": {},
581+
"hostgroup_members": [],
582+
"members": [
583+
"553d47bc-27aa-426c-a664-49c4c0c4a249",
584+
"f88093ca-e61b-43ff-a41e-613f7ad2cea2",
585+
"df1e2e13-552d-43de-ad2a-fe80ad4ba979",
586+
"d3d667dd-f583-4668-9f44-22ef3dcb53ad"
587+
]
588+
}
589+
}
590+
591+
:param o_type: searched object type
592+
:type o_type: str
593+
:param o_name: searched object name (or uuid)
594+
:type o_name: str
595+
:return: serialized object information
596+
:rtype: str
597+
"""
598+
for scheduler_link in self.app.conf.schedulers:
599+
o_found = scheduler_link.get_object(o_type, o_name)
600+
if isinstance(o_found, dict) and 'content' in o_found:
601+
return o_found
602+
return {'_status': u'ERR', '_message': u'Required %s not found.' % o_type}

alignak/http/generic_interface.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ def get_events(self):
390390
@cherrypy.expose
391391
@cherrypy.tools.json_in()
392392
@cherrypy.tools.json_out()
393-
def get_stats(self, details=False):
393+
def stats(self, details=False):
394394
"""Get statistics and information from the daemon
395395
396396
Returns an object with the daemon identity, the daemon start_time

0 commit comments

Comments
 (0)