This repository has been archived by the owner on Feb 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 145
Dashboard Examples
Bhinav Sura edited this page Dec 15, 2017
·
14 revisions
This example illustrates how to create a simple dashboard containing a single chart.
This simple example illustrates how to create a dashboard. While in this example, the markup is provided as a constant, users will likely will generate content using an HTML document framework of their choice.
- Create a new dashboard.
int maxConnections = 10;
try (
ArgusService service = ArgusService.getInstance(
"https://argus.mycompany.com/argusws",
maxConnections)
) {
String content =
"<ag-dashboard>\n"
+ " <ag-chart name='testChart'>\n"
+ " <ag-option name='yAxis.min' value='0'></ag-option>\n"
+ " <ag-metric name='testMetric'>\n"
+ " -1d:TestScope:TestMetric:TestNamespace{TestTag=TagValue}:min\n"
+ " </ag-metric>\n"
+ " </ag-chart>\n"
+ "</ag-dashboard>";
service.getAuthService().login("aUsername", "aPassword");
Dashboard dashboard = new Dashboard();
dashboard.setName("TestDashboard");
dashboard.setDescription("A test dashboard.");
dashboard.setShared(true);
dashboard.setContent(content);
try {
dashboard = service.getDashboardService().createDashboard(dashboard);
service.getAuthService().logout();
} catch(TokenExpiredException e) {
try {
// Looks like my access token has expired.
// So I will obtain a new access token using refresh token.
service.getAuthService().obtainNewAccessToken();
} catch(TokenExpiredException e1) {
// Looks like the refresh token itself has expired.
// So I will re-login to Argus using username and password.
service.getAuthService().login("aUsername", "aPassword");
} catch (IOException e1) {
// Handle IOException as you would normally do.
e1.printStackTrace();
}
} catch (IOException e) {
// Handle IOException as you would normally do.
e.printStackTrace();
}
}
- Update an existing dashboard.
int maxConnections = 10;
try (
ArgusService service = ArgusService.getInstance(
"https://argus.mycompany.com/argusws",
maxConnections)
) {
service.getAuthService().login("aUsername", "aPassword");
try {
Dashboard dashboard = service.getDashboardService().getDashboard(new BigInteger("12345"));
dashboard.setName("updatedDashboardName");
dashboard.setContent("updatedContent");
dashboard = service.getDashboardService().updateDashboard(dashboard.getId(), dashboard);
service.getAuthService().logout();
} catch(TokenExpiredException e) {
try {
// Looks like my access token has expired.
// So I will obtain a new access token using refresh token.
service.getAuthService().obtainNewAccessToken();
} catch(TokenExpiredException e1) {
// Looks like the refresh token itself has expired.
// So I will re-login to Argus using username and password.
service.getAuthService().login("aUsername", "aPassword");
} catch (IOException e1) {
// Handle IOException as you would normally do.
e1.printStackTrace();
}
} catch (IOException e) {
// Handle IOException as you would normally do.
e.printStackTrace();
}
}
This example shows how to create a simple dashboard displaying a single chart using curl.
#!/bin/bash
BASEURL=https://argus.mycompany.com/argusws/v2
# Get the refreshToken and accessToken
curl -X POST -H "Content-Type: application/json" \
-d '{"username":"aUsername","password":"aPassword"}' \
$BASEURL/auth/login \
-o tokens.out
# You can use any utility of your choice to extract the accessToken
# from the tokens.out file.
dashboardJS='{
"name":"TestDashboard",
"description":"A new dashboard",
"shared":false,
"content":"
<ag-dashboard>\n
<ag-chart name="ArgusChart">\n
<ag-metric name="ArgusMetric">\n
-1d:TestScope:TestMetric:min\n
</ag-metric>\n
</ag-chart>\n
</ag-dashboard>\n
"
}'
curl -H "Authorization: Bearer <accessToken from tokens.out>" \
-H "Content-Type: application/json" \
-X POST -d "$dashboardJS" \
$BASEURL/dashboards
curl -H "Authorization: Bearer <accessToken from tokens.out>" $BASEURL/auth/logout
For more information on authentication tokens, see Authentication.
If you are interested in using Python to interact with Argus, see the Argus Python client library.