{"id":4886,"date":"2025-09-30T04:00:00","date_gmt":"2025-09-30T11:00:00","guid":{"rendered":"https:\/\/nl1g1e2381-staging.onrocket.site\/?p=4886"},"modified":"2025-09-29T10:06:10","modified_gmt":"2025-09-29T17:06:10","slug":"create-a-reusable-function-to-validate-configuration-settings-across-device-types","status":"publish","type":"post","link":"https:\/\/www.forwardnetworks.com\/blog\/2025\/09\/30\/create-a-reusable-function-to-validate-configuration-settings-across-device-types\/","title":{"rendered":"Create a Reusable Function to Validate Configuration Settings Across Device Types"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\" id=\"why_validate\">Why Validate NTP Servers Across Devices<\/h3>\n\n\n\n<p>In a typical enterprise environment, NTP server configurations may differ not just between vendors, but even across OS variants within the same vendor. Ensuring that these configurations are correct and standardized is critical for time synchronization, which underpins security, logging, and automation.<\/p>\n\n\n\n<p>Instead of building and maintaining separate validation queries for each device type, Forward Enterprise enables users to create a <strong>single exportable function<\/strong> that applies logic conditionally based on the OS.<\/p>\n\n\n\n<p>This approach streamlines configuration auditing and improves operational consistency across diverse infrastructure.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"nqe_functions\">How the NQE Function Works<\/h3>\n\n\n\n<p>The getNtpServers(device) function returns a list of NTP servers for any device type. Internally, it routes logic using a when statement to OS-specific functions such as getCiscoNtpServers, getFortinetNtpServers, and so on.<\/p>\n\n\n\n<p>The function checks whether NTP settings are present using platform-specific patterns and logic:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Cisco devices<\/strong>: Use running config from device.files.config<\/li>\n\n\n\n<li><strong>Fortinet and F5<\/strong>: Require a custom command such as show system ntp or list sys ntp<\/li>\n\n\n\n<li><strong>Junos, Palo Alto, Arista, Versa<\/strong>: Use structured pattern matching on config blocks<br><\/li>\n<\/ul>\n\n\n\n<p>Each OS-specific helper function returns a list of serverId values extracted from matching blocks.<\/p>\n\n\n\n<p>This modular design allows you to easily add support for new vendors or update patterns without rewriting the entire function.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"example\">Real Example: Using the Exported Function<\/h3>\n\n\n\n<p>After creating and exporting the getNtpServers(device) function, you can use it in any query by importing it from the Helper Functions folder in your Org Repository:<\/p>\n\n\n\n<pre class=\"wp-block-code codeBlock has-background\" style=\"background-color:#f2f2f2\"><code>import \"Helper Functions\/GET NTP Servers\";\n\nforeach device in network.devices\nwhere device.platform.vendor != Vendor.FORWARD_CUSTOM\nlet ntpServers = getNtpServers(device)\nselect {\n  violation: !isPresent (max(ntpServers)),\n  device: device.name,\n  vendor: device.platform.vendor,\n  OS: device.platform.os,\n  \"NTPSERVERS\": ntpServers\n}<\/code><\/pre>\n\n\n\n<p>This query will show a violation if no NTP servers are present, excluding Forward synthetic devices. The simplicity of the line let ntpServers = getNtpServers(device) demonstrates the power of reusable functions in NQE.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"organize\">Organizing Helper Functions for Reuse<\/h3>\n\n\n\n<p>To maintain a scalable query library, Forward Networks recommends saving commonly used functions in a folder named <strong>Helper Functions<\/strong> at the root of your Org Repository.<\/p>\n\n\n\n<p>Functions like getNtpServers, getDnsServers, and getSnmpSettings can then be imported as needed in multiple queries, reducing duplication and enabling faster onboarding for new team members.<\/p>\n\n\n\n<p>Following this structure also ensures consistency and allows teams to quickly adopt updates to centralized logic.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Learn how to build an exportable NQE function to check NTP server settings across multiple vendors and OS types in Forward Enterprise.<\/p>\n","protected":false},"author":26,"featured_media":4883,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"content-type":"","inline_featured_image":false,"footnotes":""},"categories":[17],"tags":[],"ppma_author":[706],"class_list":["post-4886","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog"],"acf":[],"aioseo_notices":[],"authors":[{"term_id":706,"user_id":26,"is_guest":0,"slug":"christopherhendrix","display_name":"Christopher Hendrix","avatar_url":{"url":"https:\/\/www.forwardnetworks.com\/wp-content\/uploads\/2025\/08\/Christopher-Hendrix.webp","url2x":"https:\/\/www.forwardnetworks.com\/wp-content\/uploads\/2025\/08\/Christopher-Hendrix.webp"},"author_category":"1","user_url":"","last_name":"Hendrix","first_name":"Christopher","job_title":"","description":"Senior Customer Solutions Engineer"}],"_links":{"self":[{"href":"https:\/\/www.forwardnetworks.com\/wp-json\/wp\/v2\/posts\/4886","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.forwardnetworks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.forwardnetworks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.forwardnetworks.com\/wp-json\/wp\/v2\/users\/26"}],"replies":[{"embeddable":true,"href":"https:\/\/www.forwardnetworks.com\/wp-json\/wp\/v2\/comments?post=4886"}],"version-history":[{"count":9,"href":"https:\/\/www.forwardnetworks.com\/wp-json\/wp\/v2\/posts\/4886\/revisions"}],"predecessor-version":[{"id":4898,"href":"https:\/\/www.forwardnetworks.com\/wp-json\/wp\/v2\/posts\/4886\/revisions\/4898"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.forwardnetworks.com\/wp-json\/wp\/v2\/media\/4883"}],"wp:attachment":[{"href":"https:\/\/www.forwardnetworks.com\/wp-json\/wp\/v2\/media?parent=4886"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.forwardnetworks.com\/wp-json\/wp\/v2\/categories?post=4886"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.forwardnetworks.com\/wp-json\/wp\/v2\/tags?post=4886"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.forwardnetworks.com\/wp-json\/wp\/v2\/ppma_author?post=4886"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}