7 years ago
API/Script
Hi
I want to create device group named as "Fileserver" in /device/servers This is the first time I am running the script, so could you please check if my script is ok.
Also please le...
14 hours ago, Tanvir said:Text file entries like as follows:
'{"name":"460-UNIVERSITY HALL - SIR GEORGE CURRIE HALL","parentId":150}'
'{"name":"452-AFTER SCHOOL CARE CENTRE (18 PARKWAY)","parentId":150}'
'{"name":"453-INDIAN OCEAN MARINE RESEARCH CENTRE (IOMRC)","parentId":150}'
When Python iterates through your text file, it interprets each line of the file as a literal string. With each line, all characters are being assigned to the line variable, including the single quote characters. The extra single quotes are being escaped so what you are sending to LogicMonitor is just a plain ol' string data it can't interpret instead of a formatted JSON string.
For Example, with the given script snippet
data = '{"name":"463-UNIVERSITY HALL - B HOUSE","parentId":150}' build_data = [] #create empty list with open('c:\\test\\build.txt') as f: for line in f: build_data.append(line)
... the console output would look like this:
>>> data
{"name":"463-UNIVERSITY HALL - B HOUSE","parentId":150}
>>> build_data[0] #output first element in the list
'\'{"name":"460-UNIVERSITY HALL - SIR GEORGE CURRIE HALL","parentId":150}\'\n'
TL; DR
Your build.txt needs to look like this in Notepad / your favorite text editor---
{"name":"460-UNIVERSITY HALL - SIR GEORGE CURRIE HALL","parentId":150} {"name":"452-AFTER SCHOOL CARE CENTRE (18 PARKWAY)","parentId":150} {"name":"453-INDIAN OCEAN MARINE RESEARCH CENTRE (IOMRC)","parentId":150}