NTP servers used do not match across cluster members-fortinet-FortiOS

warn
high-availability
fortios
fortinet
NTP servers used do not match across cluster members-fortinet-FortiOS
0

#1

NTP servers used do not match across cluster members-fortinet-FortiOS

Vendor: fortinet

OS: FortiOS

Description:
Indeni will identify when two devices are part of a cluster and alert if the NTP servers they are using are different.

Remediation Steps:
Review the NTP configuration on each device to ensure they match.

How does this work?
This script logs into the FortiGate using SSH and retrieves the NTP servers configuration status information using the output of the “diagnose sys ntp status” command. The output includes the device’s servers configuration status as well as information about the NTP configured parameters.

Why is this important?
This metric shows if at least a NTP server is configured. NTP servers are used to sync the time across all hosts and network devices. This is critical for things such as event correlation and logging. Use Network Time Protocol (NTP) to set the date and time if possible. However, it is important to ensure the NTP UDP port is allowed through the firewalls on your network. FortiToken synchronization requires NTP in many situations. Check the link below for more information about NTP config in FortiOS: http://kb.fortinet.com/kb/documentLink.do?externalID=FD40266

Without Indeni how would you find this?
An administrator would need to log into the device and use the “diagnose sys ntp status” command to identify if the NTP servers are reachable from the device.

fortios-diagnose-sys-ntp-status

#! META
name: fortios-diagnose-sys-ntp-status
description: FortiGate Diagnose ntp status
type: monitoring
monitoring_interval: 20 minutes
requires:
    vendor: fortinet
    os.name: FortiOS
    product: firewall
    vdom_enabled: false
    vdom_root: true

# --------------------------------------------------------------------------------------------------
# Tested with FortiOS versions v5.4.6,build1165 & v5.6.0,build1449
#
# Script Information:
# The script publish the following metrics
#
# [ntp-is-synchronized]         [1 or 0, 1 in case of 'yes']
# [ntp-sync-is-enabled]         [1 or 0, 1 in case of 'enabled']
# [ntp-server-mode]             [disabled, (copy text)]
# [ntp-server-state]            [1 or 0, for each ntp-server, 0 if ipv4/ipv6 server is unreachable]
# [ntp-servers]                 [array of the ntp-servers with 'ipaddress', 'is_reachable' and 'name' tags]
#
# --------------------------------------------------------------------------------------------------


#! COMMENTS
ntp-is-synchronized:
    why: |
        It checks if the device is sync via NTP. NTP servers are used to sync the time across all hosts and network
        devices. This is critical for things such as event correlation and logging. Use Network Time Protocol (NTP) to
        set the date and time if possible.  However, it is important to ensure the NTP UDP port is allowed through the
        firewalls on your network. FortiToken synchronization requires NTP in many situations. Check the link below for
        more information about NTP config in FortiOS:
        http://kb.fortinet.com/kb/documentLink.do?externalID=FD40266
    how: |
        This script logs into the FortiGate using SSH and retrieves the NTP sync status information using the output of
        the "diagnose sys ntp status" command. The output includes the device's ntp sync status as well as information
        about all the NTP configured parameters.
    without-indeni: |
       An administrator would need to log into the device and use the "diagnose sys ntp status" command to identify if
       NTP is synchronized.
    can-with-snmp: false
    can-with-syslog: false

ntp-sync-is-enabled:
    why: |
        This metric monitors if the use of NTP is enabled. NTP servers are used to sync the time across all hosts and
        network devices. This is critical for things such as event correlation and logging. Use Network Time Protocol
        (NTP) to set the date and time if possible. However, it is important to ensure the NTP UDP port is allowed
        through the firewalls on your network. FortiToken synchronization requires NTP in many situations. Check the
        link below for more information about NTP config in FortiOS:
        http://kb.fortinet.com/kb/documentLink.do?externalID=FD40266
    how: |
        This script logs into the FortiGate using SSH and retrieves the NTP sync status information using the output of
        the "diagnose sys ntp status" command. The output includes the device's ntp sync status as well as information
        about the NTP configured parameters.
    without-indeni: |
       An administrator would need to log into the device and use the "diagnose sys ntp status" command to identify if
       the NTP is enabled.
    can-with-snmp: false
    can-with-syslog: false

ntp-server-mode:
    why: |
        This metric shows if the device is used as NTP server. This is applicable starting with FortiOS 5.0. NTP
        servers are used to sync the time across all hosts and network devices. This is critical for things such as
        event correlation and logging. Use Network Time Protocol (NTP) to set the date and time if possible.  However,
        it is important to ensure the NTP UDP port is allowed through the firewalls on your network. FortiToken
        synchronization requires NTP in many situations. Check the link below for more information about NTP config in
        FortiOS: http://kb.fortinet.com/kb/documentLink.do?externalID=FD40266
    how: |
        This script logs into the FortiGate using SSH and retrieves the NTP server status information using the output
        of the "diagnose sys ntp status" command. The output includes the device's server status as well as information
        about the NTP configured parameters.
    without-indeni: |
        An administrator would need to log into the device and use the "diagnose sys ntp status" command to identify if
        the device is configured as NTP server.
    can-with-snmp: false
    can-with-syslog: false

ntp-server-state:
    why: |
        This metric shows if the NTP servers used by the FortiGate are reachable. NTP servers are used to sync the
        time across all hosts and network devices. This is critical for things such as event correlation and logging.
        Use Network Time Protocol (NTP) to set the date and time if possible.  However, it is important to ensure the
        NTP UDP port is allowed through the firewalls on your network. FortiToken synchronization requires NTP in many
        situations. Check the link below for more information about NTP config in FortiOS:
        http://kb.fortinet.com/kb/documentLink.do?externalID=FD40266
    how: |
        This script logs into the FortiGate using SSH and retrieves the NTP servers readhabilty status information
        using the output of the "diagnose sys ntp status" command. The output includes the device's server reachability
        status as well as information about the NTP  configured  parameters.
    without-indeni: |
        An administrator would need to log into the device and use the "diagnose sys ntp status" command to identify if
        the NTP servers are reachable from the device.
    can-with-snmp: false
    can-with-syslog: false

ntp-servers:
    why: |
        This metric shows if at least a NTP server is configured. NTP servers are used to sync the time across all
        hosts and network devices. This is critical for things such as event correlation and logging. Use Network Time
        Protocol (NTP) to set the date and time if possible. However, it is important to ensure the NTP UDP port is
        allowed through the firewalls on your network. FortiToken synchronization requires NTP in many situations.
        Check the link below for more information about NTP config in FortiOS:
        http://kb.fortinet.com/kb/documentLink.do?externalID=FD40266
    how: |
        This script logs into the FortiGate using SSH and retrieves the NTP servers configuration status information
        using the output of the "diagnose sys ntp status" command. The output includes the device's servers
        configuration status as well as information about the NTP configured  parameters.
    without-indeni: |
        An administrator would need to log into the device and use the "diagnose sys ntp status" command to identify if
        the NTP servers are reachable from the device.
    can-with-snmp: false
    can-with-syslog: false


#! REMOTE::SSH
diagnose sys ntp status

#! PARSER::AWK

# Initialize the variables
BEGIN {

    # Initialize the values of metrics to publish
    ntp_is_synchronized = 0
    ntp_sync_is_enabled = 0
    ntp_server_mode = ""

    # By default ntp_server_is_configured is 0
    ntp_server_is_configured = 0

    # By default is_all_reachable is 1. (Note that if ntp is not configured we will publish the is_all_reachable to 0)
    ntp_servers_are_all_reachable = 1

    ntp_table_index = 0

}

#synchronized: yes, ntpsync: enabled, server-mode: disabled
/^synchronized:/ {

    # Check if synchronized is 'yes'
    # The ntp_is_synchronized is initialized to 0
    if (trim($2) == "yes,") {
        ntp_is_synchronized = 1
    }


    # Check if ntpsync_status is 'enabled'
    # The ntp_sync_is_enabled is initialized to 0
    ntpsync_status = tolower(trim($4))
    if (ntpsync_status == "enabled,") {
        ntp_sync_is_enabled = 1
    }

    # Store 'server-mode:' value
    ntp_server_mode = $6

}

#ipv4 server(10.10.8.145) 10.10.8.145 -- reachable(0xff) S:0 T:0
/^ipv4 server/ || /^ipv6 server/{

    # Fortinet ntp-server is configured
    ntp_table_index++

    # Set 'ipaddress'
    ntp_table[ntp_table_index, "ipaddress"] = $3

    # Read server name for example "server(10.10.8.145)"
    ntp_server_name = $2

    # Extract from string "server(10.10.8.145)" the text inside the parenthesis
    # Avoid regex and use 'substring' (using the length of 'server(' and last character ')')
    ntp_server_name = substr(ntp_server_name, 8, length(ntp_server_name)-8)

    # Set 'name'
    ntp_table[ntp_table_index, "name"] = ntp_server_name

    # Check if ntp server is reachable
    is_reachable = 1
    if ($0 ~ / unreachable/) {
        ntp_servers_are_all_reachable = 0
        is_reachable = 0
    }

    ntp_table[ntp_table_index, "is_reachable"] = is_reachable

}

END {

    # Publishing metrics
    writeDoubleMetricWithLiveConfig("ntp-is-synchronized", null, "gauge", 60, ntp_is_synchronized, "NTP Synchronization Status", "state", "")
    writeDoubleMetricWithLiveConfig("ntp-sync-is-enabled", null, "gauge", 60, ntp_sync_is_enabled, "NTP Sync Enabled", "state", "")
    writeComplexMetricStringWithLiveConfig("ntp-server-mode", null,  ntp_server_mode, "NTP Server")
    writeComplexMetricObjectArray("ntp-servers", null, ntp_table)

    # For each ntp-server publish 'ntp-server-state'
    for(table_index=1; table_index < (ntp_table_index+1); table_index++ ){
        tags["name"] = ntp_table[table_index, "ipaddress"]
        writeDoubleMetricWithLiveConfig("ntp-server-state", tags, "gauge", 60, ntp_table[table_index, "is_reachable"], "NTP Servers Status", "state", "name")
    }


}




cross_vendor_ntp_servers_comparison

package com.indeni.server.rules.library.templatebased.crossvendor

import com.indeni.server.rules.RuleContext
import com.indeni.server.rules.library.SnapshotComparisonTemplateRule
import com.indeni.server.sensor.models.managementprocess.alerts.dto.AlertSeverity

/**
  *
  */
case class cross_vendor_ntp_servers_comparison(context: RuleContext) extends SnapshotComparisonTemplateRule(context,
  ruleName = "cross_vendor_ntp_servers_comparison",
  ruleFriendlyName = "Clustered Devices: NTP servers used do not match across cluster members",
  ruleDescription = "Indeni will identify when two devices are part of a cluster and alert if the NTP servers they are using are different.",
  severity = AlertSeverity.WARN,
  metricName = "ntp-servers",
  isArray = true,
  alertDescription = "Devices that are part of a cluster must have the same NTP servers used. Review the differences below.",
  baseRemediationText = "Review the NTP configuration on each device to ensure they match.")()