Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

SDK examples

kgowdru edited this page Jun 20, 2019 · 1 revision

Examples & Screencasts


Argus SDK

This simple example prints out the number of data points posted by the user over the trailing hour. It also prints all the policy infractions incurred by the user for the trailing hour. All warden policies have a corresponding time series. Substitute the policy name in the metric field of the expression for the policy to be inspected.

public static void main(String[] args) {

    int maxConnections = 10;
    ArgusService service = ArgusService.getInstance("https://argus.mycompany.com/argusws", maxConnections);
    service.getAuthService().login("aUsername", "aPassword");

    try {

        List<String> expressions = Arrays.asList(new String[] {
                        "-1h:argus.custom:warden.datapoints_per_hour{user=aUsername}:sum:1h-sum"});
        List<Metric> result = service.getMetricService().getMetrics(expressions);
        System.out.println(MessageFormat.format(
            "aUsername posted {0} datapoints last hour", 
            result.get(0).getDatapoints().values().iterator().next()
        ));
    
        expressions = Arrays.asList(new String[] {
                        "-1d:argus.core:triggers.warden{user=aUsername}:ALERT"});
        List<Annotation> events = service.getAnnotationService().getAnnotations(expressions);
        System.out.println(MessageFormat.format(
            "Warden infractions for aUsername:\n{0}", 
            Arrays.toString(events.toArray())
        ));

    } 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();
    } 
}
Clone this wiki locally