From 2a91867330c46d3c656cd0efe6285a593e3e5b9c Mon Sep 17 00:00:00 2001 From: unkin-agent Date: Mon, 16 Nov 2026 22:10:00 +1100 Subject: [PATCH] feat: add ntopng passive dpi to the router role - add profiles::metrics::ntopng (package, config, redis prefs, service) - add ntop + ntop-noarch artifactapi repos, enabled for the router role only - capture enp1s0, enp2s0, bond0.10 and bond0.201 on prodnxsr0020 --- .../nodes/prodnxsr0020.main.unkin.net.yaml | 7 +++ hieradata/os/AlmaLinux/all_releases.yaml | 18 ++++++ hieradata/roles/infra/network/router.yaml | 8 +++ site/profiles/manifests/metrics/ntopng.pp | 62 +++++++++++++++++++ 4 files changed, 95 insertions(+) create mode 100644 site/profiles/manifests/metrics/ntopng.pp diff --git a/hieradata/nodes/prodnxsr0020.main.unkin.net.yaml b/hieradata/nodes/prodnxsr0020.main.unkin.net.yaml index 43308fe..8cac96d 100644 --- a/hieradata/nodes/prodnxsr0020.main.unkin.net.yaml +++ b/hieradata/nodes/prodnxsr0020.main.unkin.net.yaml @@ -45,3 +45,10 @@ frrouting::ospf_preferred_source_enable: true frrouting::ospf_preferred_source: "%{hiera('networking_loopback1_ip')}" frrouting::ospf_connected_exclude: - 0.0.0.0/0 + +# ntopng: wan uplink plus lan vlans +profiles::metrics::ntopng::interfaces: + - enp1s0 + - enp2s0 + - bond0.10 + - bond0.201 diff --git a/hieradata/os/AlmaLinux/all_releases.yaml b/hieradata/os/AlmaLinux/all_releases.yaml index c09e0ee..ed2c3a5 100644 --- a/hieradata/os/AlmaLinux/all_releases.yaml +++ b/hieradata/os/AlmaLinux/all_releases.yaml @@ -124,6 +124,24 @@ profiles::yum::global::repos: gpgcheck: false mirrorlist: absent + # ntop repositories + ntop: + ensure: absent + name: ntop + descr: ntop repository + target: /etc/yum.repos.d/ntop.repo + baseurl: https://artifactapi.k8s.syd1.au.unkin.net/api/v1/remote/ntop/%{facts.os.release.major}/%{facts.os.architecture}/ + gpgkey: https://artifactapi.k8s.syd1.au.unkin.net/api/v1/remote/ntop/RPM-GPG-KEY-deri + mirrorlist: absent + ntop-noarch: + ensure: absent + name: ntop-noarch + descr: ntop-noarch repository + target: /etc/yum.repos.d/ntop-noarch.repo + baseurl: https://artifactapi.k8s.syd1.au.unkin.net/api/v1/remote/ntop/%{facts.os.release.major}/noarch/ + gpgkey: https://artifactapi.k8s.syd1.au.unkin.net/api/v1/remote/ntop/RPM-GPG-KEY-deri + mirrorlist: absent + # PostgreSQL repositories postgresql-15: ensure: absent diff --git a/hieradata/roles/infra/network/router.yaml b/hieradata/roles/infra/network/router.yaml index 8838da7..8f7980b 100644 --- a/hieradata/roles/infra/network/router.yaml +++ b/hieradata/roles/infra/network/router.yaml @@ -2,6 +2,7 @@ hiera_include: - frrouting - exporters::frr_exporter + - profiles::metrics::ntopng profiles::puppet::migrate::enabled: true @@ -30,3 +31,10 @@ profiles::consul::client::node_rules: - resource: service segment: frr_exporter disposition: write + +# ntopng passive dpi; capture interfaces are per-host +profiles::yum::global::repos: + ntop: + ensure: present + ntop-noarch: + ensure: present diff --git a/site/profiles/manifests/metrics/ntopng.pp b/site/profiles/manifests/metrics/ntopng.pp new file mode 100644 index 0000000..702c5f4 --- /dev/null +++ b/site/profiles/manifests/metrics/ntopng.pp @@ -0,0 +1,62 @@ +# passive ntopng community dpi on the given interfaces, local redis, web ui on localhost only +# - influx_url: influxdb-compatible write base url (ntopng appends /write?db=...); unset keeps the local rrd driver +# timeseries are interface-level ndpi protocol + category only; per-host series stay off for cardinality +class profiles::metrics::ntopng ( + Array[String[1], 1] $interfaces, + Optional[Stdlib::HTTPUrl] $influx_url = undef, + String[1] $influx_dbname = 'ntopng', + String[1] $http_listen = '127.0.0.1:3000', +) { + include redis + + package { 'ntopng': + ensure => installed, + } + + $conf = ($interfaces.map |$i| { "-i=${i}" } + [ + '-r=127.0.0.1:6379', + "-w=${http_listen}", + '-W=0', + ]).join("\n") + + file { '/etc/ntopng/ntopng.conf': + ensure => file, + owner => 'root', + group => 'root', + mode => '0644', + content => "${conf}\n", + require => Package['ntopng'], + notify => Service['ntopng'], + } + + # timeseries settings are runtime prefs held in redis, not config-file options + $ts_prefs = { + 'hosts_ts_creation' => 'off', + 'host_ndpi_timeseries_creation' => 'none', + 'interface_ndpi_timeseries_creation' => 'both', + } + $influx_prefs = $influx_url ? { + undef => {}, + default => { + 'timeseries_driver' => 'influxdb', + 'ts_post_data_url' => $influx_url, + 'influx_dbname' => $influx_dbname, + }, + } + + ($ts_prefs + $influx_prefs).each |$key, $value| { + exec { "ntopng_pref_${key}": + provider => shell, + command => "/usr/bin/redis-cli set ntopng.prefs.${key} '${value}'", + unless => "/usr/bin/test \"$(/usr/bin/redis-cli get ntopng.prefs.${key})\" = '${value}'", + require => Class['redis'], + notify => Service['ntopng'], + } + } + + service { 'ntopng': + ensure => running, + enable => true, + require => [Package['ntopng'], Class['redis']], + } +} -- 2.47.3