Running a REST query to populate a table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2014 12:39 PM
In the process of setting up an integration between a 3rd party CMDB and ServiceNow. They have provided a REST API to query their database.
I have used both SOAP and REST queries in the past to pull specific data on demand and use it, but in this case, I'm looking to take the response and put it into a data source so that I can transform it into the CMDB.
Does anyone have any suggestions for the following:
1. Where should the REST messages be called from? I was thinking a scheduled job since it does not need to be on demand.
2. What method should I use to take the response and write that to a table?
3. Where should I store the response form the REST message so that I can run a transform against it and populate various cmdb tables? I was thinking for servers and computers, I could use the imp_computer table and utilize the transform script (with some adjustments) that already exists.
Thanks for your input.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-08-2014 01:06 PM
The wiki has some good information on this.
In particular I think you are looking for the next line in the code, as shown below:
var response = r.execute();
var body = response.getBody();
The body (or response.getBody()) should have the data returned from the REST web service that you are calling. Any information you need to populate into a record should come from there.
Note that the RESTMessage and the RESTResponse objects are Script Includes provided in your instance - and you should be to look at the code to see what additional methods are available to you (I would not modify them without good cause).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2014 12:42 PM
John,
Were you ever able to get this working? I have a similar task where I need to pull in CI's from a 3rd party CMDB (JAMF Casper) and import them into ServiceNow. I have the REST query configured to get the data I need but I'm at a loss as to where to go next.
Any help would be greatly appreciated.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-08-2015 06:30 AM
Hi Matthew.
i am currently facing the same issue. Would you mind give me some hints ?
I got the REST Message working to the JSSResource/computers/subset/basic for Casper and able to get the informations.
I am just stuck with the Parsing and bring into the Import set table.
Many thanks in advance
Frank
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-08-2015 09:53 AM
I did get it to work for the most part.
The code below is run from a schedule job, pulling everything into a custom import table, then transforming over to cmdb_ci_computer (coalescing on serial_number).
It's not the best or prettiest, but it works. I plan on cleaning this up and also grabbing the software inventory but just haven't had the time to do either lately
var r = new RESTMessage('JAMF-CasperComputerInventory', 'get');
var response = r.execute();
var jsonString = response.getBody();
var parser = new JSONParser();
var parsed = parser.parse(jsonString);
for (i = 0; i < parsed.computer_reports.length; i++) {
var name = parsed.computer_reports[i].Computer_Name;
var make = parsed.computer_reports[i].Make;
var model = parsed.computer_reports[i].Model;
var number_of_processors = parsed.computer_reports[i].Number_of_Processors;
var processor_speed_mhz = parsed.computer_reports[i].Processor_Speed_MHz;
var processor_Type = parsed.computer_reports[i].Processor_Type;
var serial_number = parsed.computer_reports[i].Serial_Number;
var asset_tag = parsed.computer_reports[i].Serial_Number;
var total_ram_mb = parsed.computer_reports[i].Total_RAM_MB;
var operating_system = parsed.computer_reports[i].Operating_System;
var username = parsed.computer_reports[i].Username; //username field format in casper matches sys_user.user_name field format in ServiceNow
var drive_capacity_mb = parsed.computer_reports[i].Drive_Capacity_MB;
//var warranty_expiration = parsed.computer_reports[i].Warranty_Expiration; //work in progress. need to conver to proper date format before import
var rec = new GlideRecord('u_imp_casper_computer');
rec.initialize();
rec.computer_name = name;
rec.make = make;
rec.model = model;
rec.number_of_processors = number_of_processors;
rec.processor_speed_mhz = processor_speed_mhz;
rec.processor_Type = processor_Type;
rec.serial_number = serial_number;
rec.asset_tag = asset_tag;
rec.total_ram_mb = total_ram_mb;
rec.operating_system = operating_system;
rec.username = username;
//rec.warranty_expiration = warranty_expiration;
rec.drive_capacity_mb = drive_capacity_mb;
rec.insert();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-08-2015 10:05 AM
Hi Matthew,
thank you so much for your response.This will help me a lot. Once i get this working i will look also in the Software Part (as we have SAM Active) and if i am faster then you , i will for sure let you know what i did.
Thanks again.
Frank