alignak.http package

Submodules

alignak.http.arbiter_interface module

This module provide a specific HTTP interface for a Arbiter.

class alignak.http.arbiter_interface.ArbiterInterface(app)[source]

Bases: alignak.http.generic_interface.GenericInterface

Interface for HA Arbiter. The Slave/Master arbiter can get /push conf

do_not_run()[source]

Master tells to slave to not run (HTTP GET) Master will ignore this call

Returns:None
get_all_states()[source]

Return all the data of satellites

Returns:dict containing satellites data

Output looks like this

{'arbiter' : [{'schedproperty1':'value1' ..}, {'pollerproperty1', 'value11' ..}, ..],

‘scheduler’: [..], ‘poller’: [..], ‘reactionner’: [..], ‘receiver’: [..],

‘broker: [..]’

}

Return type:dict
get_config()[source]

Get the managed configuration (internal) (HTTP GET)

Returns:Currently managed configuration
Return type:object
get_objects_properties(table)[source]

‘Dump all objects of the type in [hosts, services, contacts, commands, hostgroups, servicegroups]

Parameters:table (str) – table name
Returns:list all properties of all objects
Return type:list
get_satellite_list(daemon_type='')[source]

Get the satellite names sorted by type (HTTP GET)

Parameters:daemon_type (str) – daemon type to filter
Returns:dict with key daemon_type and value list of daemon name

Example

{'poller': ['Poller1', 'Poller2']}
Return type:dict
have_conf(magic_hash)[source]

Does the daemon got a configuration (internal) (HTTP GET)

Parameters:magic_hash (int) – magic hash of configuration
Returns:True if the arbiter has the specified conf, False otherwise
Return type:bool
put_conf(conf)[source]

HTTP POST to the arbiter with the new conf (master send to slave)

Parameters:conf – pickled the new configuration
Returns:None
wait_new_conf()[source]

Ask the daemon to wait a new conf. Reset cur_conf to wait new one

Returns:None
what_i_managed()[source]

Dummy call for the arbiter

Returns:{}, always
Return type:dict

alignak.http.broker_interface module

This module provide a specific HTTP interface for a Broker.

class alignak.http.broker_interface.BrokerInterface(app)[source]

Bases: alignak.http.generic_interface.GenericInterface

This class provides specific HTTP functions for Broker.

get_raw_stats()[source]

Get stats (queue size) for each modules

Returns:list of modules with queue_size
Return type:list
push_broks(broks)[source]

Push broks objects to the daemon (internal) Only used on a Broker daemon by the Arbiter

Parameters:broks (list) – Brok list
Returns:None

alignak.http.cherrypy_extend module

This module provide extension functions for Cherrypy in order to parse specific HTTP content type See http://cherrypy.readthedocs.org/en/latest/pkg/cherrypy.html#module-cherrypy._cpreqbody for details about custom processors in Cherrypy

alignak.http.cherrypy_extend.zlib_processor(entity)[source]

Read application/zlib data and put content into entity.params for later use.

Parameters:entity (cherrypy._cpreqbody.Entity) – cherrypy entity
Returns:None

alignak.http.client module

This module provides HTTPClient class. Used by daemon to connect to HTTP servers (other daemons)

class alignak.http.client.HTTPClient(address='', port=0, use_ssl=False, timeout=3, data_timeout=120, uri='', strong_ssl=False, proxy='')[source]

Bases: object

HTTPClient class use python request to communicate over HTTP Basically used to get / post to other daemons

con[source]

Deprecated properrty of HTTPClient

Returns:connection
Return type:object
connection[source]

Get connection attribute

Returns:
Return type:
get(path, args={}, wait='short')[source]

Do a GET HTTP request

Parameters:
  • path (str) – path to do the request
  • args (dict) – args to add in the request
  • wait (int) – timeout policy (short / long)
Returns:

None

make_timeout(wait)[source]

Get timeout depending on wait time

Parameters:wait (int) – wait is short or long (else)
Returns:self.timeout if wait is short, self.data_timeout otherwise
Return type:int
make_uri(path)[source]

Create uri from path

Parameters:path (str) – path to make uri
Returns:self.uri + path
Return type:str
post(path, args, wait='short')[source]

Do a POST HTTP request

Parameters:
  • path (str) – path to do the request
  • args (dict) – args to add in the request
  • wait (int) – timeout policy (short / long)
Returns:

Content of the HTTP response if server returned 200

Return type:

str

put(path, data, wait='short')[source]

Do a PUT HTTP request

Parameters:
  • path (str) – path to do the request
  • data – data to send in the request
  • args – args to add in the request
  • wait (int) – timeout policy (short / long)
Returns:

Content of the HTTP response if server returned 200

Return type:

str

set_proxy(proxy)[source]

Set HTTP proxy

Parameters:proxy (str) – proxy url
Returns:None
exception alignak.http.client.HTTPException[source]

Bases: exceptions.Exception

Simple HTTP Exception

alignak.http.daemon module

This module provide the HTTP daemon for Alignak inter daemon communication. It is mostly based on Cherrypy

class alignak.http.daemon.HTTPDaemon(host, port, http_interface, use_ssl, ca_cert, ssl_key, ssl_cert, daemon_thread_pool_size)[source]

Bases: object

HTTP Server class. Mostly based on Cherrypy It uses CherryPyWSGIServer and daemon http_interface as Application

request_stop()[source]

Wrapper to stop http daemon server

Returns:None
run()[source]

Wrapper to start http daemon server

Returns:None
exception alignak.http.daemon.InvalidWorkDir[source]

Bases: exceptions.Exception

Exception raised when daemon workdir is invalid

exception alignak.http.daemon.PortNotFree[source]

Bases: exceptions.Exception

Exception raised when port is already used by another application

alignak.http.generic_interface module

This module provide a generic HTTP interface for all satellites. Any Alignak satellite have at least those functions exposed over network See : http://cherrypy.readthedocs.org/en/latest/tutorials.html for Cherrypy basic HTPP apps.

class alignak.http.generic_interface.GenericInterface(app)[source]

Bases: object

Interface for inter satellites communications

api()[source]

List the methods available on the daemon

Returns:a list of methods available
Return type:list
api_full()[source]

List the api methods and their parameters

Returns:a list of methods and parameters
Return type:dict
get_broks(bname)[source]

Get broks from the daemon

Returns:Brok list serialized and b64encoded
Return type:str
get_external_commands()[source]

Get the external commands from the daemon (internal) Use a lock for this call (not a global one, just for this method)

Returns:Pickled external command list
Return type:str
get_log_level()[source]

Get the current log level in [NOTSET, DEBUG, INFO, WARNING, ERROR, CRITICAL, UNKNOWN]

Returns:current log level
Return type:str
get_raw_stats()[source]

Get raw stats from the daemon

Returns:daemon stats
Return type:dict
get_returns(sched_id)[source]

Get actions returns (serialized) for the scheduler with _id = sched_id

Parameters:sched_id (int) – id of the scheduler
Returns:serialized list
Return type:str
get_running_id()[source]

‘Get the current running id of the daemon (scheduler)’

Returns:running_ig
Return type:int
get_start_time()[source]

Get the start time of the daemon

Returns:start time
Return type:int
have_conf()[source]

Get the daemon cur_conf state

Returns:boolean indicating if the daemon has a conf
Return type:bool
index()[source]

Wrapper to call api from /

Returns:function list
ping()[source]

Test the connection to the daemon. Returns: pong

Returns:string ‘pong’
Return type:str
push_actions(actions, sched_id)[source]

Get new actions from scheduler(internal)

Parameters:
  • actions (list) – list of action to add
  • sched_id (int) – id of the scheduler sending actions

:return:None

put_conf(conf)[source]

Send a new configuration to the daemon (internal)

Parameters:conf – new conf to send
Returns:None
remove_from_conf(sched_id)[source]

Remove a scheduler connection (internal)

Parameters:sched_id (int) – scheduler id to remove
Returns:None
set_log_level(loglevel)[source]

Set the current log level in [NOTSET, DEBUG, INFO, WARNING, ERROR, CRITICAL, UNKNOWN]

Parameters:loglevel (str) – a value in one of the above
Returns:None
wait_new_conf()[source]

Ask the daemon to drop its configuration and wait for a new one

Returns:None
what_i_managed()[source]

Arbiter ask me which scheduler id I manage

Returns:managed configuration ids
Return type:dict

alignak.http.receiver_interface module

This module provide a specific HTTP interface for a Receiver.

class alignak.http.receiver_interface.ReceiverInterface(app)[source]

Bases: alignak.http.generic_interface.GenericInterface

This class provides specific HTTP functions for Receiver.

get_raw_stats()[source]

Get raw stats from the daemon:

* command_buffer_size: external command buffer size
Returns:external command length
Return type:dict
push_host_names(sched_id, hnames)[source]

Push hostname/scheduler links Use by the receivers to got the host names managed by the schedulers

Parameters:
  • sched_id (int) – scheduler_id that manages hnames
  • hnames (list) – host names list
Returns:

None

alignak.http.scheduler_interface module

This module provide a specific HTTP interface for a SCheduler.

class alignak.http.scheduler_interface.SchedulerInterface(app)[source]

Bases: alignak.http.generic_interface.GenericInterface

This module provide a specific HTTP interface for a Scheduler.

fill_initial_broks(bname)[source]

Get initial_broks type broks from scheduler, used by brokers Do not send broks, only make scheduler internal processing

Parameters:bname (str) – broker name, used to filter broks
Returns:None

TODO: Maybe we should check_last time we did it to prevent DDoS

get_broks(bname)[source]

Get checks from scheduler, used by brokers

Parameters:bname (str) – broker name, used to filter broks
Returns:64 zlib compress pickled brok list
Return type:str
get_checks(do_checks=False, do_actions=False, poller_tags=['None'], reactionner_tags=['None'], worker_name='none', module_types=['fork'])[source]

Get checks from scheduler, used by poller or reactionner (active ones)

Parameters:
  • do_checks (bool) – used for poller to get checks
  • do_actions (bool) – used for reactionner to get actions
  • poller_tags (list) – pollers tags to filter on this poller
  • reactionner_tags (list) – reactionner tags to filter on this reactionner
  • worker_name (str) – Worker name asking (so that the scheduler add it to actions objects)
  • module_types (list) – Module type to filter actions/checks
Returns:

base64 zlib compress pickled check/action list

Return type:

str

get_raw_stats()[source]

Get raw stats from the daemon:

* nb_scheduled: number of scheduled checks (to launch in the future)
* nb_inpoller: number of check take by the pollers
* nb_zombies: number of zombie checks (should be close to zero)
* nb_notifications: number of notifications+event handlers
* latency: avg,min,max latency for the services (should be <10s)
Returns:stats for scheduler
Return type:dict
put_conf(conf)[source]

Post conf to scheduler (from arbiter)

Parameters:conf (dict) – new configuration to load
Returns:None
put_results(results)[source]

Put results to scheduler, used by poller and reactionners

Parameters:results – results to handle
Returns:True or ?? (if lock acquire fails)
Return type:bool
run_external_commands(cmds)[source]

Post external_commands to scheduler (from arbiter) Wrapper to to app.sched.run_external_commands method

Parameters:cmds (list) – external commands list ro run
Returns:None
wait_new_conf()[source]

Ask to scheduler to wait for new conf (HTTP GET from arbiter)

Returns:None

Module contents

This module provide all class for Alignak HTTP communation. Most of files are for server side HTTP. Only client.py is for client side http