Accessing the Nimsoft Database cm_computer from Lua Script

Document ID : KB000010040
Last Modified Date : 14/02/2018
Show Technical Document Details
Introduction:

Accessing the Nimsoft Database cm_computer from Lua Script

Environment:
CA UIM Version 8.4 or above
Instructions:

There is 2 different Scripts:

 

database.open("provider=nis;database=nis;driver=none")

query = database.query("select * from cm_computer_system where maintenance = 1")
if query == nil then
   print ("Query did not complete, or had no results")
else
   for idx,row in pairs (query) do
      printf("Hostname: %s \t IP: %s",row['name'],row['ip'])
   end
end

 

 

This other Script will show the HTML Output.  

Modify the Recipient line at the bottom for your environment:

 

 

--Devices in Maintenance Mode
ROW_FORMAT = -- multi-line quote...
[[
<TR>
<TD>%s</TD>
<TD>%s</TD>
</TR>
]]
html = -- multi-line quote...
[[
<HTML>
<HEAD>
<TITLE>Devices in Maintenance Mode</TITLE>
</HEAD>
<BODY>
<H2>Devices in Maintenance Mode</H2>
<TABLE BORDER="1" CELLSPACING="0" CELLPADDING="5" width='50%'>
<TR>
<TH>Device Name</TH>
<TH>IP Address</TH>
</TR>
]]

database.open("provider=nis;database=nis;driver=none")

query = database.query("select * from cm_computer_system where maintenance = 1")
if query == nil then
title = "No Devices in Maintenance Mode"
html = ""
else
for idx,row in pairs (query) do
html = html..sprintf(ROW_FORMAT,row['name'],row['ip'])
end
end
html = html..
[[
</TABLE>
</BODY>
</HTML>
]]
-- [Modify your recipient name]  recipient = "Operator"
title = "Nimsoft - Devices in Maintenance Mode"
action.email(recipient,title,html)

 
Additional Information:

NOTE: CA Support will not help on this script, if you need further help, please engage CA Services Team