Skip to content

patwakeem/Asm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

47 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Java Library for Accessing the Apica Synthetic Monitoring API

Using this library requires an ASM auth ticket. You can find this by logging in to your ASM account and browsing here: https://wpm.apicasystem.com/Tools/ApiSettings

Feature list:

  • Create/Read/Delete Checks
  • Get Check Results
  • Create/Ready/Update/Delete Check Groups
  • Kick off check runs

Installation via Maven

<dependency>
    <groupId>com.github.patwakeem</groupId>
    <artifactId>asm</artifactId>
    <version>2017.10.14</version>
</dependency>

Samples

  • Create an ASM client object. This is the first step for all API operations.
class Example {
    
//  Environment variables: 
//  ASM_API_KEY = your auth ticket
//  ASM_API_SILO = 1 or 2
//  See note below to determine your silo. 
    public void connectWithEnvironmentVariables() {
        AsmAuthentication a = new AsmEnvironmentAuthentication();
        AsmApiClient asmApiClient = new AsmApiClient(a);
    }
    
    public void connectWithHardCodedVariables() {
        
        AsmAuthentication a = new AsmCredentialsAuthentication("auth-ticket", Silo.ONE);
        AsmApiClient asmApiClient = new AsmApiClient(a);
    }
}
  • Note: determining your silo If your API endpoint in this page is api-wpm.apicasystem.com then you should use silo one. If you have api-wpm2.apicasystem.com then you should use silo two.

  • Get a check

class Example {
    public void listTopLevelGroups() {
        AsmAuthentication a = new AsmEnvironmentAuthentication();
        AsmApiClient asmApiClient = new AsmApiClient(a);
        int checkId = 12345;
        
        Optional<AsmCheck> checkOptional = asmApiClient.getCheck(checkId);
        
//      Get check:
        checkOptional.get();        
    }
}
  • List check groups and view subgroups
class Example {
    public void listTopLevelGroups() {
        AsmAuthentication a = new AsmEnvironmentAuthentication();
        AsmApiClient asmApiClient = new AsmApiClient(a);
        
        Optional<List<AsmTopLevelGroup>> groupOptional = asmApiClient.getGroups();
        
        List<AsmTopLevelGroup> groups = groupOptional.get();
        
        AsmTopLevelGroup topLevelGroup = groups.get(0);
        
//      List subgroups:
        List<AsmSubGroup> subGroupList = topLevelGroup.getGroups();
    }
}
  • Create Top Level Check Group
class Example {
    public void createGroup() {
        AsmAuthentication a = new AsmEnvironmentAuthentication();
        AsmApiClient asmApiClient = new AsmApiClient(a);
        
        AddGroupBody addTopLevelGroupBody = new AddGroupBody();
        addTopLevelGroupBody.setName("New Top Group");
        addTopLevelGroupBody.setTopGroupId(null);
        
        asmApiClient.createGroup(addTopLevelGroupBody);
    }
    
}
  • Create Subgroup
class Example {
    public void createSubGroup() {
        AsmAuthentication a = new AsmEnvironmentAuthentication();
        AsmApiClient asmApiClient = new AsmApiClient(a);
        
        int groupId = 12345;
        
        AddGroupBody addSubGroupBody = new AddGroupBody();
        addTopLevelGroupBody.setName("New Sub Group");
        addTopLevelGroupBody.setTopGroupId(13223);
        
        asmApiClient.createGroup(addSubGroupBody);
    }
   
}
  • Delete Check Group
class Example {
    public void deleteGroups() {
        AsmAuthentication a = new AsmEnvironmentAuthentication();
        AsmApiClient asmApiClient = new AsmApiClient(a);
        
        int groupId = 12345;
        
//      By Id        
        asmApiClient.deleteGroup(groupId);
        
//      With group object
        asmApiClient.deleteGroup(groupObject);
        
    }
    
}
  • List Locations by CheckType
class Example {
    public void listLocations() {
        AsmAuthentication a = new AsmEnvironmentAuthentication();
        AsmApiClient asmApiClient = new AsmApiClient(a);
        
        Optional<List<AsmLocation>> browserLocations = asmApiClient.getLocationsByCheckType(CheckType.BROWSER);
        Optional<List<AsmLocation>> pingLocations = asmApiClient.getLocationsByCheckType(CheckType.PING);
        Optional<List<AsmLocation>> portLocations = asmApiClient.getLocationsByCheckType(CheckType.PORT);
        Optional<List<AsmLocation>> urlLocations = asmApiClient.getLocationsByCheckType(CheckType.URL);
    }
}
  • List Checks
class Example {
    public void listChecks() {
        AsmAuthentication a = new AsmEnvironmentAuthentication();
        AsmApiClient asmApiClient = new AsmApiClient(a);
        
        Optional<List<AsmCheck>> allChecks = asmApiClient.getAllChecks();
    }
}
  • Create Check
class Example {
    public void createCheck() {
        AsmAuthentication a = new AsmEnvironmentAuthentication();
        AsmApiClient asmApiClient = new AsmApiClient(a);
        
        List<Integer> groupIds = new ArrayList<>();
        integers.add(23425);
        
        CreateCheckBody createCheckBody = new CreateBrowserCheckBody();
        createCheckBody.setLocationCode(asmLocation.getLocationCode());
        
        createCheckBody.setIntervalSeconds(AsmCheckInterval.FIVE_MIN);
  
        createCheckBody.setMaxAttempts(5);
        createCheckBody.setName("test test test");
        createCheckBody.setTarget("www.google.com");
        createCheckBody.setMonitorGroupsIds(groupIds);
        
        CreateCheckRequest createCheckRequest = new CreateCheckRequest(CheckType.BROWSER, createCheckBody);
        asmApiClient.createCheck(createCheckRequest);
    }
}
  • Run Check
class Example {
    public void connectWithEnvironmentVariables() {
        AsmAuthentication a = new AsmEnvironmentAuthentication();
        AsmApiClient asmApiClient = new AsmApiClient(a);
        
        int checkId = 12345;
        
//      By Id        
        asmApiClient.runCheck(checkId);
        
//      With Object        
        asmApiClient.runCheck(asmCheckObject);
        
    }
}
  • Delete Check
class Example {
   
    public void connectWithEnvironmentVariables() {
        AsmAuthentication a = new AsmEnvironmentAuthentication();
        AsmApiClient asmApiClient = new AsmApiClient(a);
        
        int checkId = 12345;
        
//      By Id        
        asmApiClient.deleteCheck(checkId);
        
//      With Object        
        asmApiClient.deleteCheck(asmCheckObject);
    }
    
}
  • Get Check History
class Example {
    public void getCheckHistory() {
        AsmAuthentication a = new AsmEnvironmentAuthentication();
        AsmApiClient asmApiClient = new AsmApiClient(a);
        
        int checkId = 12345;
        
        String fromUtc = DateHelper.formatUnixTimeForAsmApi(System.currentTimeMillis() - 36000);
        String toUtc = DateHelper.formatUnixTimeForAsmApi(System.currentTimeMillis());
        
        GetCheckHistoryRequest getCheckHistoryRequest = new GetCheckHistoryRequest(fromUtc, toUtc, checkId);
        Optional<List<AsmCheckDetailHistory>> checkHistory = asmApiClient.getCheckHistory(getCheckHistoryRequest);
    }
}
  • Get URL Data for Check Result
class Example {
    public void getDetailedUrlResultsFromResultId() {
        AsmAuthentication a = new AsmEnvironmentAuthentication();
        AsmApiClient asmApiClient = new AsmApiClient(a);
        
        int checkId = 12345;
        
        GetFprResultByIdBody getFprResultByIdBody = new GetFprResultByIdBody();
        getFprResultByIdBody.setResultIds(listOfResultIds);
        
        Optional<FprUrlResults> fprUrlDetailsByResultId = asmApiClient.getFprUrlDetailsByResultId(checkId, getFprResultByIdBody);
    }
}

Libraries used:

  • Retrofit Awesome REST client.
  • Gson Mapping JSON to objects.

About

Apica Synthetic Monitoring Java Client

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages