Skip to content

Commit 39f26d9

Browse files
authored
Create CiHealthApi.js
1 parent 79038b0 commit 39f26d9

File tree

1 file changed

+32
-0
lines changed
  • Client-Side Components/UX Client Script Include/CI health badges component

1 file changed

+32
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Script Include: CiHealthApi
2+
// Purpose: Return simple CI health data for a given sys_id.
3+
4+
var CiHealthApi = Class.create();
5+
CiHealthApi.prototype = {
6+
initialize: function() {},
7+
8+
getHealth: function(ciSysId) {
9+
if (!ciSysId) throw 'ciSysId required';
10+
11+
// Example: pretend we have a table x_ci_health with scores
12+
var gr = new GlideRecord('x_ci_health');
13+
gr.addQuery('ci', ciSysId);
14+
gr.orderByDesc('evaluated_at');
15+
gr.setLimit(1);
16+
gr.query();
17+
18+
if (!gr.next()) return { ok: false, message: 'No health data', score: 0, label: 'Unknown' };
19+
20+
var score = parseInt(gr.getValue('score'), 10) || 0;
21+
var label = score >= 80 ? 'Good' : score >= 50 ? 'Warning' : 'Critical';
22+
23+
return {
24+
ok: true,
25+
score: score,
26+
label: label,
27+
evaluated_at: gr.getDisplayValue('evaluated_at')
28+
};
29+
},
30+
31+
type: 'CiHealthApi'
32+
};

0 commit comments

Comments
 (0)