3/10 Q. ITOM Project Help !! (Please No Paste CHATGPT ANSWER)

SandeepKSingh
Kilo Sage

Hi Expert

 

I need to enhance a Linux Server Discovery Pattern using Pre and Post Scripts:

  1. Pre-Script: Before running any discovery steps, check if the host is reachable. If not, log a message and stop further execution.

  2. Post-Script: After the server CI is created/updated, write the current timestamp into a custom field u_discovery_timestamp on the CI.

1 ACCEPTED SOLUTION

Ravi Gaurav
Giga Sage

Hi @SandeepKSingh 

Add a Pre-Script

Open Discovery Patterns > Linux Server Pattern.

Add a Pre-script step before the identification section.

Script should:

  • Use Snmp or PingProbe utility to check if the host is reachable.

  • If not reachable, log: "Pre-check failed: Host not reachable. Skipping pattern."

  • Exit gracefully without creating any CIs.

Expected Output: Pattern log showing the pre-script execution and skip behavior when the host is down.

Normal Pattern Execution

  • Run the default steps (classification, identification, exploration).

  • Server details are collected as usual when the host is reachable.

Expected Output: CMDB Linux Server CI updated with OS details.

 

Add a Post-Script

After the Set Attributes step that creates/updates the Linux Server CI, add a Post-script.

Script should:

Capture current date/time with gs.nowDateTime()

Update the current CI context with the field u_discovery_timestamp.


Example :

  • var ciSysId = current.sys_id; 
    if (ciSysId) {
    var gr = new GlideRecord('cmdb_ci_linux_server');
    if (gr.get(ciSysId)) {
    gr.u_discovery_timestamp = gs.nowDateTime();
    gr.update();
    pattern.log("Post-script: Discovery timestamp updated for " + gr.name);
    }
    }

 

View solution in original post

9 REPLIES 9

Bhuvan
Giga Patron

@SandeepKSingh 

 

Check if network or credential-less discovery suits the purpose,

 

https://www.servicenow.com/docs/bundle/zurich-it-operations-management/page/product/discovery/concep...

 

https://www.servicenow.com/docs/bundle/yokohama-it-operations-management/page/product/discovery/conc...

 

1. If you want to use custom method outside discovery, create a batch or powershell script that can be used from MID server to ping target machines and log the output

 

2. This is automatically done via sys_created_on and sys_updated_on fields. If for learning purposes you are doing this, check probes and sensors payload & map the custom field or create a business rule, when record is inserted or updated, log the current time using GlideDateTime function

 

If this helped to answer your query, please mark it helpful & accept the solution.

 

Thanks,

Bhuvan

This is something I checked it seems not working

Ravi Gaurav
Giga Sage

Hi @SandeepKSingh 

Add a Pre-Script

Open Discovery Patterns > Linux Server Pattern.

Add a Pre-script step before the identification section.

Script should:

  • Use Snmp or PingProbe utility to check if the host is reachable.

  • If not reachable, log: "Pre-check failed: Host not reachable. Skipping pattern."

  • Exit gracefully without creating any CIs.

Expected Output: Pattern log showing the pre-script execution and skip behavior when the host is down.

Normal Pattern Execution

  • Run the default steps (classification, identification, exploration).

  • Server details are collected as usual when the host is reachable.

Expected Output: CMDB Linux Server CI updated with OS details.

 

Add a Post-Script

After the Set Attributes step that creates/updates the Linux Server CI, add a Post-script.

Script should:

Capture current date/time with gs.nowDateTime()

Update the current CI context with the field u_discovery_timestamp.


Example :

  • var ciSysId = current.sys_id; 
    if (ciSysId) {
    var gr = new GlideRecord('cmdb_ci_linux_server');
    if (gr.get(ciSysId)) {
    gr.u_discovery_timestamp = gs.nowDateTime();
    gr.update();
    pattern.log("Post-script: Discovery timestamp updated for " + gr.name);
    }
    }

 

Let me try @Ravi Gaurav  this one