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

The following script is part 1 of the login to OpsView via REST

 

 

var strOpsViewServerName;
	strOpsViewServerName = "";

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

var strJson;
	strJson = '';
	strJson += '{';			
	strJson += '	"username": "' + strUserName + '",';
	strJson += '	"password": "' + strPassWord + '"';
	strJson += '}';

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

var objRESTRequest;
	objRESTRequest = objRESTOperationOpsView.createRequest([], strJson);
	objRESTRequest.contentType = "application/json";
	objRESTRequest.setHeader("Accept","application/json");

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 + "'");

	var strToken;
		strToken = objJSON.token;
}
else
{
	System.warn("===== Failed to Login to OpsView '" + strOpsViewServerName + "'");

	var strMessage;
		strMessage = objJSON.message;

	var strDetail;
		strDetail = objJSONdetailmessage;
}

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

Leave a Reply