The CreatorCon Call for Content is officially open! Get started here.

How to change operational state and status of CI from Non operational to operational and Retired to Install after most recent discovery performed on CI is present(current) date ?

Aakanksha B
Tera Expert

Hi,

I have written a after BR to change the operational state and status of CI to operational and Install on most recent discovery is done and the Ci is discovered within 10 days span. 

It isn't changing state and Operational status of CI.Is Business rule configured correctly?

 

find_real_file.png

find_real_file.png

 

TIA.

1 ACCEPTED SOLUTION

Hello Sai,

Thankyou for your response.

After multiple try. Below script worked for me.

var gr = new GlideRecord("cmdb_ci_win_server");
gr.addQuery("sys_id", "mention sys id");
gr.query();
while(gr.next())
{
var co = gr.last_discovered;
var dt = new GlideDateTime();
var ageing= gs.dateDiff(co, dt, true);
var ageingDurInMin = Math.round(ageing/(60*60*24));

gs.print(ageing);
gs.print(ageingDurInMin);
if(ageingDurInMin < 7){
gr.operational_status= 1;
gr.install_status= 1;
gr.update();
}

}

 

Regards,

AB.

 

View solution in original post

4 REPLIES 4

Sai Kumar B
Mega Sage

Hi @Aakanksha B 

Please try this, configure this as per your requirement 
sys_updated_onRELATIVELT@dayofweek@ago@10 -- I got this from filter condition at table list, Condition is "updated relative before 10 days ago" and copied that query in script

var gr = new GlideRecord('cmdb_ci_win_server');
gr.addEncodedQuery('sys_updated_onRELATIVELT@dayofweek@ago@10^sys_id='+current.cmdb_ci_win_server);
gr.query();
while(gr.next()){
gr.setValue('install_status','1');
gr.setValue('operational_status','1');
gr.update();
}

 

Please mark my answer as helpful/correct, if applicable

Best regards, Sai Kumar

Hello Sai,

 

I tried executing above script .Still there is no change in the CI.I am not sure why BR is not working.

Regards,

AB.

Hello Sai,

Thankyou for your response.

After multiple try. Below script worked for me.

var gr = new GlideRecord("cmdb_ci_win_server");
gr.addQuery("sys_id", "mention sys id");
gr.query();
while(gr.next())
{
var co = gr.last_discovered;
var dt = new GlideDateTime();
var ageing= gs.dateDiff(co, dt, true);
var ageingDurInMin = Math.round(ageing/(60*60*24));

gs.print(ageing);
gs.print(ageingDurInMin);
if(ageingDurInMin < 7){
gr.operational_status= 1;
gr.install_status= 1;
gr.update();
}

}

 

Regards,

AB.

 

Rahul Priyadars
Tera Sage

Hi Akansha

Before going Into Technical of Scripting my 2 cent questions is..

How and why Server is Retired when its still active and discoverable on its Old IP? Ask this question from Configuration Management Process team.

You should do the other way around . If a Server or CI is not discovered for lets say 4 weeks make it retired ,

Change the Status. This At least conforms in most of the cases - That given CI is not discovering meaning not on network.

Hope This helps.

Regards

RP