Skip to content

Commit 8155a28

Browse files
authored
check duplicates from server class (#2504)
* Create script.js * Create readme.md
1 parent 426be40 commit 8155a28

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
Scan all Servers (cmdb_ci_server). For each one, check if there is another CI in cmdb_ci_computer with the same name but not a server (sys_class_name != cmdb_ci_server).
2+
3+
If found, log the server name and the duplicate CI’s class; keep a running duplicate count; finally log the total.
4+
5+
*******Descriton****
6+
1. var gr = new GlideRecord("cmdb_ci_server");
7+
2. Creates a record set for Server CIs.
8+
9+
10+
gr.addEncodedQuery("sys_class_name=cmdb_ci_server");
11+
3. Redundant: you’re already targeting the cmdb_ci_server table which is a class table. This filter doesn’t harm, but it’s unnecessary.
12+
13+
14+
while (gr.next()) { ... }
15+
4. Loops through each server CI.
16+
17+
18+
5.Inside loop:
19+
20+
Query cmdb_ci_computer for records with the same name but where sys_class_name != cmdb_ci_server.
21+
6. If found, log the duplicate and increment dupCount.
22+
23+
24+
25+
7. Finally logs total dupCount.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
var dupCount = 0;
2+
var gr = new GlideRecord("cmdb_ci_server");
3+
//gr.addQuery("name", "value");
4+
gr.addEncodedQuery("sys_class_name=cmdb_ci_server");
5+
gr.query();
6+
while (gr.next()) {
7+
var dup = new GlideRecord("cmdb_ci_computer");
8+
dup.addQuery("name", gr.name);
9+
dup.addQuery("sys_class_name", "!=", "cmdb_ci_server");
10+
dup.query();
11+
if (dup.next()) {
12+
gs.log("\t" + gr.name + "\t" + dup.sys_class_name);
13+
dupCount++;
14+
}
15+
16+
}
17+
gs.log("dup count=" + dupCount);

0 commit comments

Comments
 (0)