26
26
from alignak .http .generic_interface import GenericInterface
27
27
from alignak .util import split_semicolon
28
28
from alignak .external_command import ExternalCommand
29
+ from alignak .misc .serialization import serialize , unserialize
29
30
30
31
logger = logging .getLogger (__name__ ) # pylint: disable=invalid-name
31
32
@@ -248,7 +249,7 @@ def wait_new_conf(self):
248
249
249
250
@cherrypy .expose
250
251
@cherrypy .tools .json_out ()
251
- def get_alignak_status (self , details = False ):
252
+ def alignak_status (self , details = False ):
252
253
"""Get the overall alignak status
253
254
254
255
Returns a list of the satellites as in:
@@ -259,19 +260,19 @@ def get_alignak_status(self, details=False):
259
260
}
260
261
261
262
:param details: Details are required (different from 0)
262
- :type details str
263
+ :type details bool
263
264
264
265
:return: dict with key *daemon_type* and value list of daemon name
265
266
:rtype: dict
266
267
"""
267
268
if details is not False :
268
269
details = bool (details )
269
270
270
- return self .app .push_passive_check (details = details )
271
+ return self .app .get_alignak_status (details = details )
271
272
272
273
@cherrypy .expose
273
274
@cherrypy .tools .json_out ()
274
- def get_satellites_list (self , daemon_type = '' ):
275
+ def satellites_list (self , daemon_type = '' ):
275
276
"""Get the arbiter satellite names sorted by type
276
277
277
278
Returns a list of the satellites as in:
@@ -302,7 +303,7 @@ def get_satellites_list(self, daemon_type=''):
302
303
303
304
@cherrypy .expose
304
305
@cherrypy .tools .json_out ()
305
- def get_satellites_configuration (self ):
306
+ def satellites_configuration (self ):
306
307
"""Return all the configuration data of satellites
307
308
308
309
:return: dict containing satellites data
@@ -360,7 +361,7 @@ def get_objects_properties(self, table): # pylint: disable=no-self-use, unused-
360
361
:rtype: list
361
362
"""
362
363
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." }
364
365
365
366
@cherrypy .expose
366
367
@cherrypy .tools .json_in ()
@@ -377,7 +378,7 @@ def push_external_command(self, command=None):
377
378
378
379
@cherrypy .expose
379
380
@cherrypy .tools .json_out ()
380
- def get_monitoring_problems (self ):
381
+ def monitoring_problems (self ):
381
382
"""Get Alignak detailed monitoring status
382
383
383
384
This will return an object containing the properties of the `get_id`, plus a `problems`
@@ -434,7 +435,7 @@ def get_monitoring_problems(self):
434
435
435
436
@cherrypy .expose
436
437
@cherrypy .tools .json_out ()
437
- def get_livesynthesis (self ):
438
+ def livesynthesis (self ):
438
439
"""Get Alignak live synthesis
439
440
440
441
This will return an object containing the properties of the `get_id`, plus a `livesynthesis`
@@ -524,3 +525,78 @@ def get_livesynthesis(self):
524
525
res .update (self .get_start_time ())
525
526
res .update (self .app .get_livesynthesis ())
526
527
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 }
0 commit comments