@@ -47,7 +47,7 @@ def protect(*args, **kwargs):
47
47
48
48
authenticated = False
49
49
50
- # A condition is just a callable that returns true or false
50
+ # A condition is just a callable that returns true or false
51
51
conditions = cherrypy .request .config .get ('auth.require' , None )
52
52
if conditions is not None :
53
53
app = cherrypy .request .app .root .app
@@ -72,6 +72,7 @@ def protect(*args, **kwargs):
72
72
# Now check if the request includes HTTP Authorization?
73
73
authorization = cherrypy .request .headers .get ('Authorization' )
74
74
if authorization :
75
+ print ("Got authorization header: %s" , authorization )
75
76
logger .debug ("Got authorization header: %s" , authorization )
76
77
ah = httpauth .parseAuthorization (authorization )
77
78
@@ -265,7 +266,7 @@ def alignak_map(self):
265
266
@cherrypy .tools .json_in ()
266
267
@cherrypy .tools .json_out ()
267
268
@require ()
268
- def host (self , name = None ):
269
+ def host (self , name = None ): # pylint: disable=too-many-return-statements
269
270
""" Declare an host and its data
270
271
:return:
271
272
"""
@@ -276,6 +277,9 @@ def host(self, name=None):
276
277
# Get an host
277
278
# ---
278
279
if cherrypy .request .method == "GET" :
280
+ if not self .app .backend_url :
281
+ return {'_status' : 'ERR' , '_error' : 'Not available without backend access.' }
282
+
279
283
logger .debug ("Get /host: %s" , cherrypy .request .params )
280
284
if cherrypy .request .params .get ('name' , None ) is not None :
281
285
name = cherrypy .request .params .get ('name' , None )
@@ -298,17 +302,26 @@ def host(self, name=None):
298
302
299
303
_ts = time .time ()
300
304
logger .debug ("Update /host: %s" , cherrypy .request .json )
301
- data = {
302
- 'active_checks_enabled' : cherrypy .request .json .get ('active_checks_enabled' , None ),
303
- 'passive_checks_enabled' : cherrypy .request .json .get ('passive_checks_enabled' , None ),
304
- 'check_freshness' : cherrypy .request .json .get ('check_freshness' , None ),
305
- 'template' : cherrypy .request .json .get ('template' , None ),
306
- 'livestate' : cherrypy .request .json .get ('livestate' , None ),
307
- 'variables' : cherrypy .request .json .get ('variables' , None ),
308
- 'services' : cherrypy .request .json .get ('services' , None )
309
- }
310
-
311
- response = self .app .update_host (name , data )
305
+ if not self .app .backend_url :
306
+ # Without a backend access, only update the livestate for host and its services
307
+ data = {
308
+ 'livestate' : cherrypy .request .json .get ('livestate' , None ),
309
+ 'services' : cherrypy .request .json .get ('services' , None )
310
+ }
311
+
312
+ response = self .app .update_host (name , data )
313
+ else :
314
+ data = {
315
+ 'active_checks_enabled' : cherrypy .request .json .get ('active_checks_enabled' , None ),
316
+ 'passive_checks_enabled' : cherrypy .request .json .get ('passive_checks_enabled' , None ),
317
+ 'check_freshness' : cherrypy .request .json .get ('check_freshness' , None ),
318
+ 'template' : cherrypy .request .json .get ('template' , None ),
319
+ 'livestate' : cherrypy .request .json .get ('livestate' , None ),
320
+ 'variables' : cherrypy .request .json .get ('variables' , None ),
321
+ 'services' : cherrypy .request .json .get ('services' , None )
322
+ }
323
+
324
+ response = self .app .update_host (name , data )
312
325
313
326
# Specific case where WS client credentials are not authorized
314
327
if response and '_issues' in response :
@@ -335,6 +348,12 @@ def hostgroup(self, name=None, embedded=False):
335
348
if cherrypy .request .method not in ["GET" ]:
336
349
return {'_status' : 'ERR' , '_error' : 'You must only GET on this endpoint.' }
337
350
351
+ if not self .app .backend_url :
352
+ return {'_status' : 'ERR' , '_error' : 'Not available without backend access.' }
353
+
354
+ if not self .app .authorization :
355
+ return {'_status' : 'ERR' , '_error' : 'Not available without authorized access.' }
356
+
338
357
# Get an hostgroup
339
358
# ---
340
359
logger .debug ("Get /hostgroup: %s" , cherrypy .request .params )
@@ -432,7 +451,12 @@ def command(self):
432
451
command_line = '%s;%s' % (command_line , parameters )
433
452
434
453
# Add a command to get managed
435
- self .app .to_q .put (ExternalCommand (command_line ))
454
+ # todo: directly in from_q is better, no?
455
+ # self.app.to_q.put(ExternalCommand(command_line))
456
+ # -----
457
+ logger .debug ("Got an external command: %s" , command_line )
458
+ self .app .from_q .put (ExternalCommand (command_line ))
459
+ self .app .received_commands += 1
436
460
437
461
return {'_status' : 'OK' , '_command' : command_line }
438
462
command .method = 'post'
@@ -446,6 +470,9 @@ def alignak_logs(self, start=0, count=25, search=''):
446
470
:return: True if is alive, False otherwise
447
471
:rtype: dict
448
472
"""
473
+ if not self .app .authorization :
474
+ return {'_status' : 'ERR' , '_error' : 'Not available without authorized access.' }
475
+
449
476
logger .debug ("Get /alignak_log: %s" , cherrypy .request .params )
450
477
start = int (cherrypy .request .params .get ('start' , '0' ))
451
478
count = int (cherrypy .request .params .get ('count' , '25' ))
0 commit comments