This is a minimal and thin layer of Python client code on top of the Argus webservices REST API. Most of the library API is 1:1 with that of REST API so it serves to be more of a convenience than an abstraction. This means you still need to be familiar with the underlying REST API to be effective. For more information on the REST API and data model, refer to the Argus - User Guide. Special thanks to Demian Brecht for giving a lot of feedback early and helping to shape the API and the project.
You can also browse the Python API documentation online at: https://salesforce.github.io/python-argusclient/
A quick primer to using argusclient
Below you will find functional and self-explanatory code that shows how to do the following:
Import the relevant pieces from argusclient
Create the main entry point and establish login session
Query for existing namespaces
Create a new namespace
Collect metrics and annotations
Post metrics and annotations
Query for existing dashboards
Update or Create dashboard
Query for existing alerts
Delete alert
Create an alert along with a trigger and a notification
In addition, also look at the bundled example named splunk_to_argus.py that shows how to extract metrics from Splunk and push them to Argus.
Some package imports and initializations that we use later
import sys, os, time, calendar, getpass, logging, random
import lxml.etree
from argusclient import *
from argusclient.dashboardtags import DASHBOARD, CHART, TITLE, METRIC, FLAGS
logging.basicConfig()
logging.root.setLevel(logging.INFO)
logging.getLogger("requests").setLevel(logging.WARN)
endpoint = "http://localhost:8080/argusws"
user = "hdara"
password = None
tags = { "host": "hdara-wsl" }
fields = { "user": user }
curtm = long(calendar.timegm(time.gmtime()))*1000
ns_name = "hdara-ns"
ns_access_addl_users = ("hdara",)
dashboard_name = "hdara.test.dashboard"
alert_name = "hdara.test.alert"
scope_name = "hdara"
metric_name = "test"
ans = []
Login to the service and establish session
argus = ArgusServiceClient(user,
password or getpass.getpass("SSO password for %s: " % user),
endpoint=endpoint)
logging.info("Logging in")
argus.login()
Check if a namespace exists and create one if missing
logging.info("Looking up existing namespace with name: %s", ns_name)
nss = dict((ns.qualifier, ns) for ns in argus.namespaces.values())
ns = nss.get(ns_name)
if not ns:
logging.info("Creating new namespace with name: %s", ns_name)
ns = argus.namespaces.add(Namespace(ns_name))
Generate some random metrics against hdara-ns:hdara:test and mark the start and end with annotations.
logging.info("Generating some metric and annotation data for the dashboard")
m = Metric(scope_name, metric_name, tags=tags, namespace=ns_name)
for t in xrange(10, 0, -1):
# Warden requires 1 minute gap between successive data points.
ts = curtm-t*60*1000
m.datapoints[ts] = random.randint(50, 100)
if not ans or t == 1:
ans.append(Annotation("script", "hdara", "test", ts, ts, "generated", tags=tags, fields=dict(event=ans and "start" or "end", **fields)))
Send metrics and annotations to Argus
logging.info("Adding metrics data to Argus")
am_resp = argus.metrics.add([m]);
if am_resp.error_count():
logging.error("Errors reported in metric data: errorCount: %s errorMessages: %s", am_resp.error_count(), am_resp.error_messages())
logging.info("Adding annotation data to Argus")
an_resp = argus.annotations.add(ans)
if an_resp.error_count():
logging.error("Errors reported in annotation data: errorCount: %s errorMessages: %s", an_resp.error_count(), an_resp.error_messages())
Generate dashboard content
mquery = str(MetricQuery(scope_name, metric_name, "sum", tags=tags, stTimeSpec="-1d", enTimeSpec="-0d", namespace=ns_name))
aquery = str(AnnotationQuery(scope_name, metric_name, "generated", tags=tags, stTimeSpec="-1d", enTimeSpec="-0d"))
content = lxml.etree.tostring(DASHBOARD(
CHART(
TITLE("hdara.test"),
METRIC(mquery, name="hdara.test.metric"),
FLAGS(aquery, name="hdara.test.annotation"),
name="Chart"
)
), method="html")
dashbobj.content = content
Update or Create dashboard
logging.info("Looking up existing dashboard with name: %s", dashboard_name)
dashbobj = argus.dashboards.get_user_dashboard(user, dashboard_name, shared=False)
if not dashbobj:
logging.info("Creating new dashboard with name: %s", dashboard_name)
dashbobj = Dashboard(dashboard_name, content, shared=True, description="A new dashboard")
dashbobj = argus.dashboards.add(dashbobj)
else:
logging.info("Updating dashboard with name: %s id %s", dashboard_name, dashbobj.argus_id)
dashbobj.content = content
argus.dashboards.update(dashbobj.argus_id, dashbobj)
logging.info("Dashboard url: %s", os.path.join(os.path.dirname(endpoint), "argus/#/dashboards", str(dashbobj.argus_id)).replace("-ws", "-ui"))
Look for an existing alert and delete it so that we can recreate it
logging.info("Looking up existing alert with name: %s owned by user: %s", alert_name, user)
alertobj = argus.alerts.get_user_alert(user, alert_name, shared=False)
if alertobj:
logging.info("Deleting existing alert with name: %s id: %s", alert_name, alertobj.argus_id)
argus.alerts.delete(alertobj.argus_id)
Finally, create alert with a trigger and a notification
logging.info("Creating new alert with alert name: %s", alert_name)
alertobj = argus.alerts.add(Alert(alert_name, mquery, "* */1 * * *",
trigger=Trigger("hdara.test.trigger", Trigger.GREATER_THAN, 100000, 600000),
notification=Notification("hdara.test.notification", Notification.EMAIL, subscriptions=["hdara@salesforce.com"]),
shared=True))
Metadata
Release files for argusclient 1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| argusclient-1.0.tar.gz | 19.5 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| argusclient-1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 38.9 kB
Release files / argusclient-1.0.tar.gz
| Download URL | argusclient-1.0.tar.gz |
|---|---|
| Size | 19.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
91a1346a5b0a3be2e9f26337215114fc025b6b00adf78f36bad32b0e02802a31
|
|
BLAKE2b-256 checksum How to use checksums |
a7b1d745d0e955584df84bdbaff2935d1a8de950f4319ebb4f784157d56dbee0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.23.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.7.3
|
Release files / argusclient-1.0-py3-none-any.whl
| Download URL | argusclient-1.0-py3-none-any.whl |
|---|---|
| Size | 19.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b064ab7d98482f3ad7508eec5932b3345d4b9bc7999e558db1362ed5310f7e99
|
|
BLAKE2b-256 checksum How to use checksums |
8ad4c6f4e63f810c9c6180e8a0926e1898a320bc98e16123f2c5704754fb0efc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.23.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.7.3
|
Security for argusclient 1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.