Script to Check if a CI is a Server or not
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2023 01:25 AM
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2023 02:01 AM
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.
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2023 02:11 AM
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