vCO Workflow Script to Login to OpsView via REST – Part 2

he following script is part 2 of the login to OpsView via REST

 

System.log("==================================================");

var strJson;
	strJson = '';
	strJson += '{';			
	strJson += '}';

System.log("===== Attempting to Login to OpsView '" + strOpsViewServerName + "'");

var objRESTRequest;
	objRESTRequest = objRESTOperationOpsView.createRequest([], strJson);
	objRESTRequest.contentType = "application/json";
	objRESTRequest.setHeader("Accept","application/json");
	objRESTRequest.setHeader("X-Opsview-Username", strUserName);
	objRESTRequest.setHeader("X-Opsview-Token", strToken);

var objRESTResponse;
	objRESTResponse = objRESTRequest.execute();

var strContentAsString;
	strContentAsString = objRESTResponse.contentAsString;

var objJSON;
	objJSON = JSON.parse(strContentAsString);

if ( objRESTResponse.statusCode == 200 )
{
	System.log("===== Successfully Logged into OpsView '" + strOpsViewServerName + "'");

	if ( objJSON.object != null )
	{

	}
	else if ( ( objJSON.summary != null ) && ( objJSON.list != null ) )
	{
		var objSummary;
			objSummary = objJSON.summary;

		var intRows;
			intRows = objSummary.rows;

		var intPage;
			intPage = objSummary.page;

		var intTotalRows;
			intTotalRows = objSummary.totalrows;

		var intTotalPages;
			intTotalPages = objSummary.totalpages;

		var intAllRows;
			intAllRows = objSummary.allrows;

		var arrList;
			arrList = objJSON.list;

		for ( var i = 0; i < arrList.length; i++ )
		{
			var objListItem;
				objListItem = arrList[i];

			var strRef;
				strRef = objListItem.ref;

			var strName;
				strName = objListItem.name;

			var strID;
				strID = objListItem.id;

			var strDescription;
				strDescription = objListItem.description;
		}
	}
	else
	{
		System.warn("===== Failed to Login to OpsView '" + strOpsViewServerName + "'");

		var strMessage;
			strMessage = objJSON.message;

		var strDetail;
			strDetail = objJSONdetailmessage;
	}
}
else
{
	System.warn("===== Failed to Login to OpsView '" + strOpsViewServerName + "'");
}

System.log("==================================================");

Leave a Reply