Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Script to Check if a CI is a Server or not

Meloper
Kilo Sage

as I understand it server OOTB are inherited from class "Server" or "VM".
Is there a script or a FUnction in a script include with which I can check if a CI is a server?

I can write one for myself and go through the "sys_db_object" but maybe someone of you already wrote one, is there something like that already in a script include?

2 REPLIES 2

Harshal Aditya
Mega Sage

Hi @Meloper ,

 

Hope you are doing good.

You can find out if a device is a server or not by looking at class field on the cmdb_ci table.

 

HarshalAditya_0-1677492038367.png

 

 

Please find the script below -

 

var server = "your CI's sys_id";
var getServer = new GlideRecord("cmdb_ci_server");
getServer.addQuery("sys_id",server);
getServer.query();
if(getServer.next()){
gs.log("Device is a Server");
}
else
gs.log("Device is not a server");

 

In the above script we are checking if the device is in cmdb_ci_server table or not. If yes it's a server else not. 

 

Please Mark My Response as Correct/Helpful based on Impact

Regards,
Harshal

priyasunku
Mega Sage

Hi @Meloper 

 

You can check script include 'GlideRecordUtil' this OOB and there is a function which can be used to check CI class.

 

If my answer solved your issue, please mark my answer as Correct & 👍Helpful