- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi Expert
I need to enhance a Linux Server Discovery Pattern using Pre and Post Scripts:
Pre-Script: Before running any discovery steps, check if the host is reachable. If not, log a message and stop further execution.
Post-Script: After the server CI is created/updated, write the current timestamp into a custom field u_discovery_timestamp on the CI.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
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);
}
}
If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!
Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI
YouTube: https://www.youtube.com/@learnservicenowwithravi
LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Check if network or credential-less discovery suits the purpose,
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
This is something I checked it seems not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
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);
}
}
If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!
Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI
YouTube: https://www.youtube.com/@learnservicenowwithravi
LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Let me try @Ravi Gaurav this one