Skip to content

Commit

Permalink
Added integration with CMDB.
Browse files Browse the repository at this point in the history
  • Loading branch information
fjaviernieto committed Jun 1, 2016
1 parent 831b23b commit e09fd11
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package org.indigo.occiprobe.openstack;

import java.util.ArrayList;
import java.util.Iterator;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.Invocation;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.Response;

import org.glassfish.jersey.client.ClientConfig;
import org.glassfish.jersey.client.JerseyClientBuilder;

import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;

public class CMDBClient
{
private Client client = null;
private String CMDBUrl;

public CMDBClient()
{
// Retrieve properties
PropertiesManager myProp = new PropertiesManager();
CMDBUrl = myProp.getProperty(PropertiesManager.CMDB_URL);

// Create the Client
ClientConfig cc = new ClientConfig();
client = JerseyClientBuilder.newClient(cc);
}

public String[] getProvidersList()
{
// Call to CMDB API
WebTarget target = client.target(CMDBUrl + "/provider/list");
Invocation.Builder invocationBuilder = target.request();
Response response = invocationBuilder.get();
String message = response.readEntity(String.class);

// Retrieve the providers list
JsonElement jelement = new JsonParser().parse(message);
JsonObject parsedRes = jelement.getAsJsonObject();
JsonArray listArray = parsedRes.getAsJsonArray("rows");

ArrayList<String> providersList = new ArrayList<String> ();
Iterator <JsonElement> myIter = listArray.iterator();
while (myIter.hasNext())
{
JsonObject currentResource = myIter.next().getAsJsonObject();
String providerId = currentResource.get("id").getAsString();
providersList.add(providerId);
}

// Prepare the result
providersList.trimToSize();
String[] resultList = new String[providersList.size()];
providersList.toArray(resultList);

return resultList;
}

public void getProviderData (String providerId)
{
// Call to CMDB API
WebTarget target = client.target(CMDBUrl + "/provider/" + providerId);
Invocation.Builder invocationBuilder = target.request();
Response response = invocationBuilder.get();
String message = response.readEntity(String.class);

// Retrieve the providers list
JsonElement jelement = new JsonParser().parse(message);
JsonObject parsedRes = jelement.getAsJsonObject();
}

public static void main(String[] args)
{
CMDBClient myClient = new CMDBClient();
myClient.getProvidersList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class PropertiesManager
public static final String JAVA_KEYSTORE = "java.keystore";
public static final String ZABBIX_IP = "zabbix.ip";
public static final String ZABBIX_SENDER = "zabbix.sender.location";
public static final String CMDB_URL = "cmdb.location";

private HashMap <String, String> propertiesList;

Expand Down
3 changes: 2 additions & 1 deletion occi-zabbix-probe/src/main/resources/occiprobe.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ openstack.user=
openstack.password=
java.keystore=C:/Program Files/Java/jdk1.7.0_80/jre/lib/security/cacerts
zabbix.ip=90.147.102.197
zabbix.sender.location=C:/Zabbix_Agent/bin/win64
zabbix.sender.location=C:/Zabbix_Agent/bin/win64
cmdb.location=http://indigo.cloud.plgrid.pl/cmdb

0 comments on commit e09fd11

Please sign in to comment.