Creating the automation script to import services from Claroty into Maximo IT
About this task
An automation script is created for importing services from Claroty into Maximo IT.
Follow the steps below to create the automation script:
Procedure
- Open the Automation Scripts application.
-
On the navigation panel, click Create and select
Script with Action Launch Point : Step 1 of 3, and
enter data in the fields as follows:
- Launch Point: Specify the launch point name, for example, KEYMAPPER
- Object: Search for the ASSET object and select it
- Action: Specify the Action name same as the name given for Launch Point, for example, ISERVICES.
- Check the checkbox for Active? and click Next.
-
On the Create Script with Action Launch Point : Step 2 of 3 pop-up, enter the
details in the fields as follows:
- Script: Specify as jython
- Script Language: Search and select jython
- Log level: Search and select ERROR.
- Click Next.
-
On the Create Script with Action Launch Point : Step 3 of
3
In the Script box, enter the following script and click Create.
Note: The below script is a sample and for reference only, update the script as per your custom field ID's and other changes as necessary.from java.io import BufferedReader, IOException, InputStreamReader, BufferedInputStream, FileWriter from java.lang import System, Class, String, StringBuffer, Integer # from java.nio.charset import Charset from java.util import Date, Properties, List, ArrayList,HashMap # from org.apache.commons.codec.binary import Base64 from org.apache.http import HttpEntity, HttpHeaders, HttpResponse, HttpVersion from org.apache.http.client import ClientProtocolException, HttpClient from org.apache.http.client.entity import UrlEncodedFormEntity from org.apache.http.client.methods import HttpGet from org.apache.http.entity import StringEntity from org.apache.http.util import EntityUtils from org.apache.http.impl.client import DefaultHttpClient from org.apache.http.message import BasicNameValuePair from org.apache.http.params import BasicHttpParams, HttpParams, HttpProtocolParamBean from com.google.gson import JsonParser, JsonElement,JsonObject from psdi.mbo import Mbo, MboRemote, MboSet, MboSetRemote from psdi.security import UserInfo from psdi.server import MXServer from psdi.mbo import SqlFormat from psdi.mbo import MboConstants from sys import * def createAsset(res,element,assetSet): #get asset mbo data and add new # list of key name from asset table key_set= res.keySet() assetId=element.get('asset_id') assetNum = assetId.toString().replace('"',"") assetkey=str(assetNum) start=1 end=assetSet.count() map=HashMap() assetMbo = assetSet.add() for i in range(start, end+1): asset = assetSet.getMbo(i); assetnum = asset.getString("ASSETNUM") map.put(assetnum,"assetnum") if assetkey in map.keys(): System.out.println("Asset exist") else: for key in key_set: if(key == "ASSETNUM"): value=res.get(key).getAsString() numval = element.get(value).getAsString() if(key == "DESCRIPTION"): dval=res.get(key).getAsString() if element.get(dval).isJsonNull(): descval = element.get(dval) else: descval = element.get(dval).getAsString() if(key == "SERIALNUM"): sval=res.get(key).getAsString() if element.get(sval).isJsonNull(): serialval = element.get(sval) else: serialval = element.get(sval).getAsString() if(key == "ASSETTAG"): tagkey = res.get(key).getAsString() if element.get(tagkey).isJsonNull(): tagval = element.get(tagkey) else: tagval = element.get(tagkey).getAsString() if(key == "DEVICETYPE"): devicetypekey = res.get(key).getAsString() if element.get(devicetypekey).isJsonNull(): devicetypeval = element.get(devicetypekey) else: devicetypeval = element.get(devicetypekey).getAsString() assetMbo.setValue("assetnum",numval) assetMbo.setValue("serialnum",str(serialval)) assetMbo.setValue("assettag",str(tagval)) assetMbo.setValue("devicetype",str(devicetypeval)) assetMbo.setValue("description",str(devicetypeval)) assetMbo.setValue("orgid","PMSCIBM") assetMbo.setValue("ASSETSOURCE","claroty") assetSet.save() return "success" def getAssetStr(element): # get all the value key from claroty with open('C:/Discovery/data1.json', 'r') as myfile: data=myfile.read() jsonElement = JsonParser().parse(data) jsonObject = jsonElement.getAsJsonObject() result=jsonObject.get('result') mxServer = MXServer.getMXServer() # Get the MboSet for the Asset table assetSet = mxServer.getMboSet("ASSET", mxServer.getSystemUserInfo()) asset_data = [createAsset(el,element,assetSet)for el in result] return "get value successfully" def mappingdata(resp): # read mapping file jsonElement = JsonParser().parse(resp) jsonObject = jsonElement.getAsJsonObject() result=jsonObject.get('devices') asset_data = [getAssetStr(element)for element in result] return "Assets" # Main part mappingdata(respData)