scout_api package

Submodules

scout_api.version module

Module contents

class scout_api.ScoutAPI(api_key)

Bases: object

Create object to interact with the Scout REST API

Parameters:api_key (str) – API key generated by Scout to access the API
api_key

str

API key generated by Scout to access the API

log

logging

logger used by the class

add_marker(notes)

Add the given list of roles to a server

Parameters:notes (str) – notes to add with the marker
Returns:repsonse data from ScoutApp REST API
Return type:dict
Raises:TypeError – notes must is a str
add_roles_to_server(hostname, roles)

Add the given list of roles to a server

Parameters:
  • hostname (str) – server to delete
  • roles (list) – list of roles to tadd
Returns:

repsonse data from ScoutApp REST API

Return type:

dict

Raises:
  • TypeError – hostname must is a str
  • TypeError – roles must is a list
delete_server(hostname)

Delete a server from Scout

Parameters:hostname (str) – server to delete
Returns:repsonse data from ScoutApp REST API
Return type:dict
Raises:TypeError – hostname must is a str
get_alerts(lifecycle='all')

Get the metric data based on the given filters. More info about the metrics API endpoint can be found here: http://help.scoutapp.com/v1.2/docs/api#fetching-metrics

lifecycle options
  • start: returns only open alerts
  • end: returns only closed alerts
  • oneoff: returns only alerts that are simple messages, without an open/closed state. Alerts generated internally by plugins are one-offs
  • all: returns all alerts
Parameters:lifecycle (str, optional) – one of the following: start, end, oneoff, all (default all)
Returns:list of dicts containing alert data
[{u’body’: None,
u’id’: 123456789, u’lifecycle’: u’end’, u’metric_name’: u’% Memory Used’, u’metric_value’: 81.0, u’plugin_name’: u’Memory Profiler’, u’server_hostname’: u’hostname’, u’server_name’: u’hostname’, u’severity’: u’not applicable’, u’sparkline_url’: u’https://scoutapp.com/account/alerts/123456789/sparkline.png‘, u’time’: u‘1970-01-01T00:00:00.000-00:00’, u’title’: u’% memory used met or exceeded 80%’, u’trigger’: u’when % memory used meets or exceeds 80% for 60 minutes or more’, u’trigger_id’: 12345678, u’trigger_template_id’: 123456, u’type’: u’alert’, u’url’: u’https://scoutapp.com/a/123456789‘}]
Return type:array
Raises:ValueError – lifecycle not a valid option
get_metrics(**kwargs)

Get the metric data based on the given filters. More info about the metrics API endpoint can be found here: http://help.scoutapp.com/v1.2/docs/api#fetching-metrics

Parameters:
  • metric_name (str) – the non-humanized metric name
  • metric_type (str) – disk|memory|network|process|plugin
  • metric_source_name (str) – if plugin, the plugin name. If process, the process name. if disk|network, the volume/interface name
  • environment (str, optional) – environment name (exact match required). DEFAULT: no filtering by environment
  • role (str, optional) – role name (exact match required.) DEFAULT: no filtering by role
  • server (str, optional) – server hostname (exact match, wildcard, or regex ok)
  • duration (str, optional) – one of: “30 minutes”, “5 hours”, “12 hours”, “1 day”, “1 week”, “2 weeks”, “1 month”, “3 months”, “6 months”, “1 year”. DEFAULT: 5 hours
  • display (str, optional) – range|breakout. DEFAULT: range
Returns:

result from the api call in the below format

{u’metrics’: [{u’label’: u’hostname1’,
u’points’: [[0.0, 0.0, 0.0],

[0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]],

u’precision’: 2, u’units’: u’‘},

{u’label’: u’hostname2’,
u’points’: [[1.0, 1.0, 1.0],

[1.0, 1.0, 1.0], [1.0, 1.0, 1.0], [1.0, 1.0, 1.0], [1.0, 1.0, 1.0], [1.0, 1.0, 1.0], [1.0, 1.0, 1.0], [1.0, 1.0, 1.0], [1.0, 1.0, 1.0], [1.0, 1.0, 1.0], [1.0, 1.0, 1.0], [1.0, 1.0, 1.0], [1.0, 1.0, 1.0], [1.0, 1.0, 1.0], [1.0, 1.0, 1.0], [1.0, 1.0, 1.0], [1.0, 1.0, 1.0], [1.0, 1.0, 1.0], [1.0, 1.0, 1.0], [1.0, 1.0, 1.0], [1.0, 1.0, 1.0], [1.0, 1.0, 1.0], [1.0, 1.0, 1.0], [1.0, 1.0, 1.0], [1.0, 1.0, 1.0], [1.0, 1.0, 1.0], [1.0, 1.0, 1.0], [1.0, 1.0, 1.0], [1.0, 1.0, 1.0], [1.0, 1.0, 1.0]],

u’precision’: 2, u’units’: u’‘}],

u’num_servers’: 2, u’step’: 60, u’timestamps’: [1433266800000,

1433266860000, 1433266920000, 1433266980000, 1433267040000, 1433267100000, 1433267160000, 1433267220000, 1433267280000, 1433267340000, 1433267400000, 1433267460000, 1433267520000, 1433267580000, 1433267640000, 1433267700000, 1433267760000, 1433267820000, 1433267880000, 1433267940000, 1433268000000, 1433268060000, 1433268120000, 1433268180000, 1433268240000, 1433268300000, 1433268360000, 1433268420000, 1433268480000, 1433268540000]}

Return type:

dict

Raises:

None

get_role()

Get the list of roles with their included servers

Returns:list of roles
Return type:dict
get_role_list()

Get the list of roles

Returns:list of roles
Return type:array
get_role_server_list(role)

Get the list of servers in a given role

Parameters:role (str) – role to lookup server list of
Returns:server hostname list
Return type:array
Raises:ValueError – role does not exist
set_server_notifications(hostname, enabled)

Enable or disable notifications based on server hostname

Parameters:
  • hostname (str) – server to change notifcations of
  • enabled (bool) – notifications enabled if true, disabled if false
Returns:

repsonse data from ScoutApp REST API

Return type:

dict

Raises:
  • TypeError – hostname must is a str
  • TypeError – enabled must is a bool

Table Of Contents

This Page