Contrail Insights SDKs
The Contrail Insights software development kit (SDK) is a Python library that can be used to interact with the Contrail Insights Platform using the Contrail Insights REST API. The following steps describe how to install and use the Contrail Insights SDK.
Unpack the SDK TAR file.
$ tar -xvzf appformix-sdk.tar.gz $ ls sdk/ appformix README requirements.txt samples
Set HTTP proxy environment variables, if required for access to the Internet. Dependencies will be downloaded from the Internet in Step 4.
$ export http_proxy=<proxy URL> $ export https_proxy=<proxy UR>
Create a virtual environment (venv) for running the SDK.
$ virtualenv venv New python executable in /home/user/sdk/venv/bin/python Installing setuptools, pip, wheel...done. $ source venv/bin/activate (venv) $
Download the Python packages required for the SDK.
(venv) $ cd sdk (venv) $ pip install –r requirements.txt Collecting requests[security]==2.8.1 (from -r requirements.txt (line 1)) ... Successfully installed Babel-2.4.0 Jinja2-2.9.6 MarkupSafe-1.0 PrettyTable-0.7.2 Werkzeug-0.12.1 aniso8601-1.2.0 asn1crypto-0.22.0 cffi-1.10.0 cryptography-1.8.1 debtcollector-1.13.0 enum34-1.1.6 flask-0.10.1 flask-restful-0.3.5 funcsigs-1.0.2 idna-2.5 ipaddress-1.0.18 iso8601-0.1.11 itsdangerous-0.24 keystoneauth1-2.19.0 monotonic-1.3 msgpack-python-0.4.8 ndg-httpsclient-0.4.2 netaddr-0.7.19 netifaces-0.10.5 oslo.config-3.24.0 oslo.i18n-3.15.0 oslo.serialization-2.18.0 oslo.utils-3.25.0 pbr-3.0.0 positional-1.1.1 pyOpenSSL-17.0.0 pyasn1-0.2.3 pycparser-2.17 python-dateutil-2.6.0 python-keystoneclient-2.0.0 python-novaclient-3.1.0 pytz-2017.2 requests-2.8.1 rfc3986-0.4.1 simplejson-3.10.0 stevedore-1.21.0 wrapt-1.10.10
Unset the HTTP proxy environment variables (if set in Step 2).
(venv) $ unset http_proxy (venv) $ unset https_proxy
Set OpenStack variables required for Contrail Insights.
(venv) $ cd samples/ (venv) $ vi appformix_config.py # OpenStack Credentials of user OPENSTACK_USERNAME = <username of an OpenStack user> OPENSTACK_PASSWORD = <password of OpenStack user> OPENSTACK_PROJECT_NAME = <project that OpenStack user is a member of> OPENSTACK_USER_DOMAIN_NAME = <OpenStack user domain or ‘default’> OPENSTACK_PROJECT_DOMAIN_NAME = <OpenStack project domain or ‘default’> # Host where Contrail Insights Controller is running APPFORMIX_HOST = <IP or hostname of Contrail Insights Controller host> # Port for Contrail Insights Controller APPFORMIX_PORT = <Contrail Insights Controller port, default: 9000> # Authentication Type AUTH_TYPE = 'openstack’
The
PagerDuty Configuration
,Custom Notification Configuration
andServiceNow Configuration
sections are optional.Set the PYTHONPATH environment variable to include
appformix
directory.(venv) $ export PYTHONPATH=$PYTHONPATH:<SDK_ROOT_DIR>/sdk/appformix
Edit and run the sample scripts in the
samples
directory.Example: Script to get metrics for a host for a specific period.
(venv) $ cd samples (venv) $ vi get_data.py - Edit 'start_time_str' and 'end_time_str' to the desired values (venv) $ python get_data.py Data for server ace96 {u'entity_id': u'ace96', u'entity_type': u'host', u'api_version': u'v1.0', u'entries': [{u'metrics': {u'host': {u'memory': {u'usage': 12.8, u'page_fault': {u'rate': 18449.49}, u'page_in_out': {u'rate': 0}, u'swap': {u'usage': 0}, u'dirty': {u'rate': 9}}, u'disk': {u'read_response_time': 0, u'write_response_time': 0, u'io': {u'read': 0, u'write': 0}, u'response_time': 0, u'usage': {u'bytes': 15.3, u'percent': 1}}, u'network': {u'ingress': {u'bit_rate': 0.03, u'drops': ...
Example: Script to configure an alarm for CPU usage of hosts in an aggregate.
(venv) $ python configure_host_alarm.py Configured alarm host_alarm_rule1 for aggregate appformix_platform
Example: Script to generate usage reports for all hosts and all projects.
(venv) $ cd samples (venv) $ vi generate_reports.py - Edit 'start_time_str' and 'end_time_str' to the desired values (venv) $ python generate_reports.py Usage report for all_projects written to file all_projects_2016-07-13_2016-07-14.json Usage report for all_hosts written to file all_hosts_2016-07-13_2016-07-14.json
Example: Script to create a new host aggregate.
(venv)$ python create_host_aggregate.py Created aggregate aggregate1 with ID 10a0853e-2636-11e7-b1a9-0242ac120002