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

Event Collection Examples

Bhinav Sura edited this page Jul 8, 2017 · 8 revisions

Examples & Screencasts


Argus Web

Collection of event data is not supported within the web interface, only the web services.

Argus SDK

This simple example illustrates how to post annotations. The actual annotation objects being posted in this example are returned as the result of the createAnnotationObjects method and not explicitly shown here.

public static void main(String[] args) {

    int maxConnections = 10;
    ArgusService service = ArgusService.getInstance("https://argus.mycompany.com/argusws", maxConnections);
    service.getAuthService().login("aUsername", "aPassword");
    
    while(<there is data to post>) {
        postAnnotations(service, annotations);
    }

}

void postAnnotations(ArgusService service, List<Annotation> annotations) {
    try {
        PutResult result = service.getAnnotationService().putAnnotations(annotations);
        System.out.println(MessageFormat.format("Succeeded: {0}, Failed: {1}.",
                           result.getSuccessCount(), result.getFailCount()));
    } 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();
    } 
}

Curl

This simple example uses curl to post a single event.

#!/bin/bash

payload='[{
  "scope": "TestScope",
  "metric": "TestMetric",
  "tags": {
    "TestTag": "TestValue"
  },
  "source": "TestSource",
  "id": "TestID-0001",
  "timestamp": 1476490800000,
  "type": "TestType",
  "fields": {
    "Event Name": "TestName",
    "Notification Name": "TestNotification",
    "Trigger Name": "TestTrigger",
    "user": "aUsername",
    "Notification status": "TestStatus"
  }
}]'

curl -X POST -H "Content-Type: application/json" \
     -d '{"username":"aUsername","password":"aPassword"}' \
     https://argus.mycompany.com/argusws/v2/auth/login \
     -o tokens.out

# You can use any utility of your choice to extract the accessToken 
# from the tokens.out file. 

curl -H "Authorization: Bearer <accessToken from tokens.out>" \
     -H "Content-Type: application/json" \
     -X POST -d "$payload" \
     https://argus.mycompany.com/argusws/collection/annotations
Clone this wiki locally