zenossapi
- Zenoss API client module¶
zenossapi is a python module for interacting with the Zenoss API an an object-oriented way. The philosophy here is to use objects to work with everything in the Zenoss API, and to try to normalize the various calls to the different routers. Thus get methods will always return an object, list methods will return data. All methods to add or create start with add, all remove or delete start with delete. As much as possible the methods try to hide the idiosyncrasies of the JSON API, and to do the work for you, for example by letting you use a device name instead of having to provide the full device UID for every call.
zenossapi¶
apiclient
Class¶
Zenoss API Client Class
-
class
zenossapi.apiclient.
Client
(host=None, user=None, password=None, ssl_verify=None)[source]¶ Bases:
object
Client class to access the Zenoss JSON API
-
get_router
(router)[source]¶ Instantiates and returns a Zenoss router object
Parameters: router (str) – The API router to use
-
zenossapi Routers¶
routers
Base Class¶
Device Router¶
Zenoss device_router
-
class
zenossapi.routers.device.
DeviceRouter
(url, headers, ssl_verify)[source]¶ Bases:
zenossapi.routers.ZenossRouter
Class for interacting with the Zenoss device router
-
get_device_class
(device_class)[source]¶ Get a device class
Parameters: device_class (str) – The name of the device class Returns: Return type: ZenossDeviceClass
-
-
class
zenossapi.routers.device.
ZenossComponent
(url, headers, ssl_verify, device_data)[source]¶ Bases:
zenossapi.routers.device.DeviceRouter
Class for Zenoss component objects
-
lock
(updates=False, deletion=False, send_event=False)[source]¶ Lock the component for changes.
Parameters: - updates (bool) – Lock for updates
- deletion (bool) – Lock for deletion
- send_event (bool) – Send an event when an action is blocked by locking
Returns: Response message
Return type: str
-
lock_for_deletion
(send_event=False)[source]¶ Lock the component for updates.
Parameters: send_event (bool) – Send an event when deletion is blocked by locking Returns: Response message Return type: str
-
-
class
zenossapi.routers.device.
ZenossDevice
(url, headers, ssl_verify, device_data)[source]¶ Bases:
zenossapi.routers.device.DeviceRouter
Class for Zenoss device objects
-
add_local_template
(template)[source]¶ Add a local template to the device.
Parameters: template (str) – Name of the new local template
-
bind_or_unbind_template
(path, template)[source]¶ Binds a template to the device if it’s unbound, or unbinds it if it’s bound.
Parameters: - path (str) – Template’s path, as given in the display label
- template (str) – Name of the template to bind/unbind
-
delete
(action, del_events=False, del_perf=True)[source]¶ Remove a device from its organizer, or delete it from Zenoss altogether.
Parameters: - action (str) – ‘remove’ to remove the devices from their organizer, ‘delete’ to delete them from Zenoss
- del_events (bool) – Remove all events for the devices
- del_perf (bool) – Remove all perf data for the devices
Returns: Return type: bool
-
delete_local_template
(template)[source]¶ Remove a local template from the device.
Parameters: template (str) – Name of the template to remove
-
get_active_templates
()[source]¶ Get ZenossTemplate objects for all active templates on a device.
Returns: Return type: list(ZenossTemplate)
-
get_bound_templates
()[source]¶ Get ZenossTemplate objects templates that are bound to the device.
Returns: Return type: list(ZenosTemplate)
-
get_component
(component)[source]¶ Get a component object.
Parameters: component (str) – Name of the component, e.g. ‘hw/cpus/0’ Returns: Return type: ZenossComponent
-
get_components
(meta_type=None, start=0, limit=50, sort='name', dir='ASC', name=None)[source]¶ Get component objects for all components on the device. Supports Pagination.
Parameters: - meta_type (str) – Meta type of components to list
- start (int) – Offset to start device list from, default 0
- limit (int) – The number of results to return, default 50
- sort (str) – Sort key for the list, default is ‘name’
- dir (str) – Sort order, either ‘ASC’ or ‘DESC’, default is ‘ASC’
- name (str) – Regular expression pattern to filter on
Returns: Return type: list(ZenossComponent)
-
get_local_templates
()[source]¶ Get ZenossTemplate objects for all locally defined templates.
Returns: Return type: list(ZenossTemplate)
-
get_overridable_templates
()[source]¶ Get ZenossTemplate objects for templates that can be overridden.
Returns: Return type: list(ZenossTemplate)
-
get_unbound_templates
()[source]¶ Get ZenossTemplate objects for available templates that are not bound to the device.
Returns: Return type: list(ZenossTemplate)
-
list_active_templates
()[source]¶ Get the list of templates active on a device, both bound and local.
Returns: { 'name': Template name, 'label': Display label for the template, }
Return type: list(dict(str, str))
-
list_bound_templates
()[source]¶ Get the list of templates bound to a device, does not include local templates.
Returns: { 'name': Template name, 'label': Display label for the template, }
Return type: list(dict(str, str))
-
list_components
(meta_type=None, start=0, limit=50, sort='name', dir='ASC', name=None)[source]¶ Get a list of all the components on a device. Supports pagination.
Parameters: - meta_type (str) – Meta type of components to list
- start (int) – Offset to start device list from, default 0
- limit (int) – The number of results to return, default 50
- sort (str) – Sort key for the list, default is ‘name’
- dir (str) – Sort order, either ‘ASC’ or ‘DESC’, default is ‘ASC’
- name (str) – Regular expression pattern to filter on
Returns: { 'total': Total number of components found. 'hash': Hash check to determine if components have changed 'components': List of components found }
Return type: dict(int, str, list)
-
list_local_templates
()[source]¶ Get the list of monitoring templates defined locally on a device.
Returns: Return type: list
-
list_overridable_templates
()[source]¶ Get the list of available templates on a device that can be overridden.
Returns: { 'name': Template name, 'label': Display label for the template, }
Return type: list(dict(str, str))
-
list_unbound_templates
()[source]¶ Get the list of available templates that are not bound to the device.
Returns: { 'name': Template name, 'label': Display label for the template, }
Return type: list(dict(str, str))
-
list_user_commands
()[source]¶ Get the list of user commands for a device.
Returns: { name: Name of the user command description: Command description }
Return type: dict(str, str)
-
lock
(updates=False, deletion=False, send_event=False)[source]¶ Lock the device for changes.
Parameters: - updates (bool) – Lock for updates
- deletion (bool) – Lock for deletion
- send_event (bool) – Send an event when an action is blocked by locking
Returns: Response message
Return type: str
-
lock_for_deletion
(send_event=False)[source]¶ Lock the device for updates.
Parameters: send_event (bool) – Send an event when deletion is blocked by locking Returns: Response message Return type: str
-
lock_for_updates
(send_event=False)[source]¶ Lock the device for updates.
Parameters: send_event (bool) – Send an event when updates are blocked by locking Returns: Response message Return type: str
-
move
(device_class)[source]¶ Move the device to a different device class
Parameters: device_class (str) – Name of the device class to move the device into Returns: uuid of the Job Manager job for the move Return type: str
-
reidentify
(new_id)[source]¶ Change the device’s id in Zenoss. Note that changing the device id will cause the loss of all graph data for the device.
Parameters: new_id (str) – New ID for the device
-
remodel
()[source]¶ Remodel the device.
Returns: uuid of the Job Manager job for the remodel Return type: str
-
reset_ip_address
(ip_address='')[source]¶ Reset the IP address of the device to ip_address if specified or to the result of a DNS lookup if not.
Parameters: ip_address (str) – IP address to set device to Returns: Response message Return type: str
-
set_bound_templates
(templates)[source]¶ Set a list of templates as bound to a device.
Parameters: templates (list) – List of template names
-
set_collector
(collector)[source]¶ Set the collector for the device.
Parameters: collector (str) – The collector to use for the device Returns: uuid of the Job Manager job for the change Return type: str
-
-
class
zenossapi.routers.device.
ZenossDeviceClass
(url, headers, ssl_verify, device_class_data)[source]¶ Bases:
zenossapi.routers.device.DeviceRouter
Class for Zenoss device class objects
-
add_device
(device_name, title='', ip_address='', location=None, systems=None, groups=None, model=False, collector='localhost', production_state=500, comments='', priority=3, snmp_community='', snmp_port=161, rack_slot='', hw_manufacturer='', hw_product_name='', os_manufacturer='', os_product_name='', asset_tag='', serial_number='', windows_user='', windows_password='', zcommand_user='', zcommand_password='', configuration_properties=None, custom_properties=None)[source]¶ Add a new device to the device class.
Parameters: - device_name (str) – Name of the new device, will be the device id
- title (str) – Optional title for the device, default is to match the device_name
- ip_address (str) – Ip address for the device, default is to derive this from DNS based on device_name
- location (str) – Location for the device
- systems (list[(str) – List of systems for the device
- groups (list[(str) – List of groups for the device
- model (bool) – Set to True to model the device automatically after creation
- collector (str) – Collector to use for the device
- production_state (int) – Numerical production state for the device, default is 500 (Pre-Production)
- comments (str) – Comments for the device
- priority (int) – Numerical priority for the device, default is 3 (Normal)
- snmp_community (str) – SNMP community string for the device
- snmp_port (int) – SNMP port for the device
- rack_slot (str) – Rack slot description
- hw_manufacturer (str) – Hardware manufacturer name, default is to derive by modeling
- hw_product_name (str) – Hardware product name, default is to derive by modeling
- os_manufacturer (str) – Operating system developer, default is to derive by modeling
- os_product_name (str) – Operating system name, default is to derive by modeling
- asset_tag (str) – Device’s inventory asset tag
- serial_number (str) – Device’s serial number
- windows_user (str) – Username for Windows device monitoring
- windows_password (str) – Password for the windows_user
- zcommand_user (str) – Username for SSH-based monitoring user
- zcommand_password (str) – Password for the zcommand_user
- configuration_properties (dict) – Key/value pairs for setting Configuration Properties for the device
- custom_properties (dict) – Key/value pairs for setting Custom Properties for the device
Returns: ID of the add device job
Return type: str
-
add_subclass
(name, description='', connection_info=None)[source]¶ Add a new subclass to the device class.
Parameters: - name (str) – Name of the new subclass
- description (str) – Description for the new subclass
- connection_info (list) – zProperties that represent the credentials for access in the subclass
-
get_device
(device_name)[source]¶ Get a device from the device class
Parameters: device_name (str) – The name of the device to get Returns: Return type: ZenossDevice
-
get_devices
(params=None, start=0, limit=50, sort='name', dir='ASC')[source]¶ Get the devices contained in a device class. Supports pagination.
Parameters: - params (dict) – Key/value filters for the search, options are name, ipAddress, deviceClass, or productionState
- start (int) – Offset to start device list from, default 0
- limit (int) – The number of results to return, default 50
- sort (str) – Sort key for the list, default is ‘name’
- dir (str) – Sort order, either ‘ASC’ or ‘DESC’, default is ‘ASC’
Returns: { 'total': Total number of devices found 'hash': Hashcheck to determine if any devices have changed, 'devices': ZenossDevice objects, }
Return type: dict(int, str, list(ZenossDevice))
-
list_devices
(params=None, start=0, limit=50, sort='name', dir='ASC')[source]¶ List the devices contained in a device class. Supports pagination.
Parameters: - params (dict) – Key/value filters for the search, options are name, ipAddress, deviceClass, or productionState
- start (int) – Offset to start device list from, default 0
- limit (int) – The number of results to return, default 50
- sort (str) – Sort key for the list, default is ‘name’
- dir (str) – Sort order, either ‘ASC’ or ‘DESC’, default is ‘ASC’
Returns: Return type: dict
-
Events Router¶
Zenoss evconsole_router
-
class
zenossapi.routers.events.
EventsRouter
(url, headers, ssl_verify)[source]¶ Bases:
zenossapi.routers.ZenossRouter
Class for interacting with Zenoss events.
-
add_event
(summary, device, severity, component=None, event_class_key=None, event_class='/Status')[source]¶ Create a new Zenoss event.
Parameters: - summary (str) – Summary for the new event
- device (str) – Device ID for the new event
- component (str) – Component UID for the new event
- severity (str) – Severity to assign the new event, must be one of Critical, Error, Warning, Info, Debug, or Clear
- event_class_key (str) – The Event Class Key to assign to the event
- event_class (str) – Event Class for the event
Returns: Return type:
-
clear_heartbeat
(collector, daemon)[source]¶ Clear a heartbeat event for a specific daemon.
Parameters: - collector (str) – Collector the daemon is running in, e.g. slvcollector
- daemon (str) – Monitoring daemon to clear the heartbeat event for, e.g. zencommand
-
get_event_by_evid
(evid)[source]¶ Get an event by its event id
Parameters: evid (str) – The event id Returns: Return type: ZenossEvent
-
get_open_events
(limit=10, start=0, sort='lastTime', sort_dir='DESC')[source]¶ Get all open events (new or acknowledged state)
Parameters: - limit (int) – Maximum number of events to return
- start (int) – Minimum index of events to get
- sort (str) – Sort key for events list
- sort_dir (str) – Sort direction, ASC or DESC
Returns: Return type: list(ZenossEvent)
-
get_open_production_events
(limit=10, start=0, sort='lastTime', sort_dir='DESC')[source]¶ Get all open events (new or acknowledged state) for devices with a production state of Production
Parameters: - limit (int) – Maximum number of events to return
- start (int) – Minimum index of events to get
- sort (str) – Sort key for events list
- sort_dir (str) – Sort direction, ASC or DESC
Returns: Return type: list(ZenossEvent)
-
list_open_events
(limit=10, start=0, sort='lastTime', sort_dir='DESC')[source]¶ Get a list of all open events (new or acknowledged state)
Parameters: - limit (int) – Maximum number of events to return
- start (int) – Minimum index of events to get
- sort (str) – Sort key for events list
- sort_dir (str) – Sort direction, ASC or DESC
Returns: Return type: dict
-
list_open_production_events
(limit=10, start=0, sort='lastTime', sort_dir='DESC')[source]¶ Get a list of all open events (new or acknowledged state) for devices with a production state of Production
Parameters: - limit (int) – Maximum number of events to return
- start (int) – Minimum index of events to get
- sort (str) – Sort key for events list
- sort_dir (str) – Sort direction, ASC or DESC
Returns: Return type: dict
-
-
class
zenossapi.routers.events.
ZenossEvent
(url, headers, ssl_verify, event_data)[source]¶ Bases:
zenossapi.routers.events.EventsRouter
Class for Zenoss event objects
Jobs Router¶
Zenoss jobs_router
-
class
zenossapi.routers.jobs.
JobsRouter
(url, headers, ssl_verify)[source]¶ Bases:
zenossapi.routers.ZenossRouter
Class for interacting with the Zenoss device router
-
get_job
(job)[source]¶ Get a ZenossJob object by the job’s uuid
Parameters: job (str) – uuid of the job Returns: Return type: ZenossJob
-
get_jobs
(start=0, limit=50, sort='scheduled', dir='ASC')[source]¶ Get ZenossJob objects for Job Manager jobs. Supports pagination.
Parameters: - start (int) – Offset to start device list from, default 0
- limit (int) – The number of results to return, default 50
- sort (str) – Sort key for the list, default is ‘scheduled’. Other sort keys are ‘started, ‘finished’, ‘status’, ‘type’ and ‘user’
- dir (str) – Sort order, either ‘ASC’ or ‘DESC’, default is ‘ASC’
Returns: Return type: list(ZenossJob)
-
list_jobs
(start=0, limit=50, sort='scheduled', dir='DESC')[source]¶ List all Job Manager jobs, supports pagination.
Parameters: - start (int) – Offset to start device list from, default 0
- limit (int) – The number of results to return, default 50
- sort (str) – Sort key for the list, default is ‘scheduled’. Other sort keys are ‘started, ‘finished’, ‘status’, ‘type’ and ‘user’
- dir (str) – Sort order, either ‘ASC’ or ‘DESC’, default is ‘DESC’
Returns: { 'total': (int) Total number of jobs, 'jobs': { 'description': (str) Job description, 'finished': (int) Time the job finished in timestamp format, 'scheduled': (int) Time the job was scheduled in timestamp format, 'started': (int) Time the job started in timestamp format, 'status': (str) Status of the job, 'type': (str) Job type, 'uid': (str) JobManager UID - /zport/dmd/JobManager, 'user': (str) User who scheduled the job, 'uuid': (str) UUID of the job, } }
Return type: dict(int, dict(str, int, int, int, str, str, str, str, str))
-
-
class
zenossapi.routers.jobs.
ZenossJob
(url, headers, ssl_verify, job_data)[source]¶ Bases:
zenossapi.routers.jobs.JobsRouter
Class for Zenoss job objects
Template Router¶
Zenoss template_router
-
class
zenossapi.routers.template.
TemplateRouter
(url, headers, ssl_verify)[source]¶ Bases:
zenossapi.routers.ZenossRouter
Class for interacting with the Zenoss template router
-
add_data_point_to_graph
(datapoint, graph, include_thresholds=False)[source]¶ Adds a data point to a graph.
Parameters: - datapoint (str) – Uid of the data point to add
- graph (str) – Uid of the graph to add the data point to
- include_thresholds (bool) – Set to True to include the related thresholds for the data point
Returns: Return type: dict
-
add_local_template
(zenoss_object, name)[source]¶ Adds a local template to an object.
Parameters: - zenoss_object (str) – Uid of the object to add the local template to
- name – Unique name for the new local template
-
add_template
(target, name)[source]¶ Adds a template to a device class.
Parameters: - target (str) – The uid of the target device class
- name (str) – Unique name of the template to add
Returns: Return type:
-
delete_local_template
(zenoss_object, name)[source]¶ Builds the request data for deleting a local template to an object.
Parameters: - object (str) – Uid of the object to remove the local template from
- name – Unique name of the new local template
-
delete_template
(device_class, template)[source]¶ Removes a template.
Parameters: - device_class (str) – Name of the device class where the template is defined
- template (str) – Name of the template to remove
Returns: Return type: dict
-
get_all_templates
()[source]¶ Returns all defined templates.
Returns: Return type: list(ZenossTemplate)
-
get_data_source_types
()[source]¶ Gets the list of available data source types.
Returns: Return type: list
-
get_device_class_templates
(device_class)[source]¶ Gets the defined templates for a device class
Parameters: device_class (str) – Device class to get templates for Returns: Return type: list(ZenossTemplate)
-
get_object_templates
(zenoss_object)[source]¶ Gets the templates bound to a specific object (monitored resource or component)
Parameters: zenoss_object (str) – The uid of the object, e.g. Devices/Server/Zuora/Aspose/devices/10.aspose.prod.slv.zuora Returns: Return type: list(ZenossTemplate)
-
get_template
(device_class, template)[source]¶ Get a Zenoss template
Parameters: - device_class (str) – Name of the device class where the template is defined
- template (str) – Name of the template to get
Returns: Return type:
-
get_threshold_types
()[source]¶ Gets the list of available threshold types.
Returns: Return type: list
-
list_all_templates
()[source]¶ Returns all defined templates as a list of tuples containing the template UID and description.
Returns: Return type: list(ZenossTemplate)
-
-
class
zenossapi.routers.template.
ZenossDataPoint
(url, headers, ssl_verify, dp_data)[source]¶ Bases:
zenossapi.routers.template.TemplateRouter
Class for Zenoss data points
-
add_to_graph
(graph, include_thresholds=False)[source]¶ Adds a data point to a graph.
Parameters: - graph (str) – Name of the graph to add the data point to
- include_thresholds (bool) – Set to True to include the related thresholds for the data point
Returns: Return type: dict
-
-
class
zenossapi.routers.template.
ZenossDataSource
(url, headers, ssl_verify, ds_data)[source]¶ Bases:
zenossapi.routers.template.TemplateRouter
Class for Zenoss template data sources
-
add_data_point
(datapoint)[source]¶ Adds a data point to a data source.
Parameters: datapoint (str) – Name of the new data point Returns: Return type: ZenossDataPoint
-
delete_data_point
(datapoint)[source]¶ Deletes a data point from a template.
Parameters: datapoint (str) – Name of the data point to remove Returns: Return type: dict
-
get_data_point
(datapoint)[source]¶ Get a particular data point.
Parameters: datapoint (str) – Name of the data point to get details for Returns: Return type: ZenossDataPoint
-
get_data_points
()[source]¶ Get all the data points for a datasource.
Returns: Return type: list(ZenossDataPoint)
-
-
class
zenossapi.routers.template.
ZenossGraph
(url, headers, ssl_verify, graph_data)[source]¶ Bases:
zenossapi.routers.template.TemplateRouter
Class for Zenoss graphs
-
add_graph_threshold
(threshold)[source]¶ Adds a threshold to a graph.
Parameters: threshold (str) – Uid of the threshold to add Returns: Return type: dict
-
add_point
(datasource, datapoint, include_thresholds=False)[source]¶ Adds a data point to a graph.
Parameters: - datasource (str) – Name of the data source holding the data point
- datapoint (str) – Name of the data point to add
- include_thresholds (bool) – Set to True to include the related thresholds for the data point
Returns: Return type: dict
-
delete_point
(datapoint)[source]¶ Deletes a data point from a graph.
Parameters: datapoint (str) – Name of the data point to remove Returns: Return type: dict
-
get_points
()[source]¶ Gets the data points of a graph.
Returns: Return type: list(ZenossDataPoint)
-
set_graph_properties
(properties)[source]¶ Set the properties for a graph.
Parameters: properties (dict) – Properties and values to set Returns: Return type: dict
-
-
class
zenossapi.routers.template.
ZenossTemplate
(url, headers, ssl_verify, template_data)[source]¶ Bases:
zenossapi.routers.template.TemplateRouter
Class for Zenoss Template objects
-
add_data_source
(datasource, type)[source]¶ Adds a data source to a template.
Parameters: - datasource (str) – Name of the new data source
- type (str) – Type of the new data source, must be one of the types returned by get_data_source_types()
Returns: Return type:
-
add_graph
(graph)[source]¶ Add a new graph to a template.
Parameters: graph (str) – Name for the new graph Returns: Return type: ZenossGraph
-
add_threshold
(threshold, threshold_type, datapoints)[source]¶ Adds a threshold to a template.
Parameters: - threshold (str) – Name of the new threshold
- threshold_type (str) – Type of the new threshold, must be one of the types returned by get_threshold_types()
- datapoints (list) – List of datapoints to select for the threshold
Returns: Return type:
-
copy
(target)[source]¶ Copy a template to another device or device class.
Parameters: target (str) – Uid of the device or device class to copy to Returns: Return type: ZenossTemplate
-
delete_data_source
(datasource)[source]¶ Deletes a data source from a template.
Parameters: datasource (str) – Name the data source to remove Returns: Return type: dict
-
delete_threshold
(threshold)[source]¶ Deletes a threshold.
Parameters: threshold (str) – Name of the threshold to remove Returns: Return type: dict
-
get_data_points
()[source]¶ Get all the data points in a template.
Returns: Return type: list(ZenossDataPoint)
-
get_data_source
(datasource)[source]¶ Get a particular data source.
Parameters: datasource (str) – Name of the data source to get Returns: Return type: ZenossDataSource
-
get_data_sources
()[source]¶ Gets data sources configured for a template.
Returns: Return type: list(ZenossDataSource)
-
get_graph
(graph)[source]¶ Get a particular graph.
Parameters: graph (str) – Name of the graph to get the definition of Returns: Return type: ZenossGraph
-
get_graphs
()[source]¶ Get the graphs defined for a template.
Returns: Return type: list(ZenossGraph)
-
get_threshold
(threshold)[source]¶ Get a particular threshold.
Parameters: threshold (str) – Name of the threshold to get details on Returns: Return type: ZenossThreshold
-
get_thresholds
()[source]¶ Gets the thresholds of a template.
Returns: Return type: list(ZenossThresholds)
-
list_data_points
()[source]¶ Returns all the data points in a template as a list.
Returns: Return type: list(str)
-
list_data_sources
()[source]¶ Rerturns data sources configured for a template as a list.
Returns: Return type: list(str)
-
-
class
zenossapi.routers.template.
ZenossThreshold
(url, headers, ssl_verify, threshold_data)[source]¶ Bases:
zenossapi.routers.template.TemplateRouter
Class for Zenoss thresholds