Set up comprehensive OSPF network monitoring using FRRouting, Prometheus SNMP exporter, and Grafana dashboards to track network topology changes, LSA states, and routing convergence in real-time.
Prerequisites
- Root or sudo access
- Network interface with IP connectivity
- Basic understanding of OSPF routing concepts
- Minimum 2GB RAM for monitoring stack
What this solves
OSPF networks require constant visibility into topology changes, LSA propagation, and neighbor relationships to maintain optimal routing performance. This tutorial shows you how to implement comprehensive OSPF monitoring using FRRouting for OSPF routing, Prometheus SNMP exporter for metrics collection, and Grafana for visualization and alerting.
Step-by-step installation
Update system packages
Start by updating your package manager to ensure you get the latest versions of all components.
sudo apt update && sudo apt upgrade -y
sudo apt install -y curl wget gnupg2 software-properties-common
Install FRRouting for OSPF
FRRouting provides enterprise-grade OSPF routing capabilities with extensive SNMP monitoring support.
curl -s https://deb.frrouting.org/frr/keys.asc | sudo apt-key add -
echo "deb https://deb.frrouting.org/frr $(lsb_release -s -c) frr-stable" | sudo tee -a /etc/apt/sources.list.d/frr.list
sudo apt update
sudo apt install -y frr frr-pythontools frr-snmp
Configure FRRouting OSPF
Enable OSPF and SNMP support in FRRouting configuration. This enables routing daemon monitoring via SNMP.
zebra=yes
ospfd=yes
ospf6d=no
ripd=no
ripngd=no
isisد=no
babeld=no
pimd=no
ldpd=no
nhrpd=no
eigr=no
sharpd=no
pbrd=no
staticد=no
bfd=no
SNMP support
snmp=yes
Configure OSPF routing
Set up OSPF areas and networks. This creates the routing topology that we'll monitor.
!
frr version 8.4.2
frr defaults traditional
hostname frr-router
log syslog informational
no ipv6 forwarding
service integrated-vtysh-config
!
OSPF Configuration
router ospf
router-id 203.0.113.1
network 203.0.113.0/24 area 0.0.0.0
network 198.51.100.0/24 area 0.0.0.1
area 0.0.0.0 authentication message-digest
area 0.0.0.1 stub
passive-interface default
no passive-interface eth0
no passive-interface eth1
redistribute connected
redistribute static
!
SNMP Configuration
snmp-server community public ro
snmp-server community private rw
snmp-server location "Network Operations Center"
snmp-server contact "network-admin@example.com"
!
line vty
!
end
Start FRRouting services
Enable and start FRRouting to begin OSPF routing and SNMP data collection.
sudo systemctl enable frr
sudo systemctl start frr
sudo systemctl status frr
Install Prometheus
Prometheus will collect OSPF metrics via SNMP and store them for Grafana visualization.
wget https://github.com/prometheus/prometheus/releases/download/v2.45.0/prometheus-2.45.0.linux-amd64.tar.gz
tar -xzf prometheus-2.45.0.linux-amd64.tar.gz
sudo mv prometheus-2.45.0.linux-amd64 /opt/prometheus
sudo useradd -M -r -s /bin/false prometheus
sudo chown -R prometheus:prometheus /opt/prometheus
Install SNMP exporter
The SNMP exporter translates SNMP OIDs into Prometheus metrics, specifically for OSPF monitoring.
wget https://github.com/prometheus/snmp_exporter/releases/download/v0.24.1/snmp_exporter-0.24.1.linux-amd64.tar.gz
tar -xzf snmp_exporter-0.24.1.linux-amd64.tar.gz
sudo mv snmp_exporter-0.24.1.linux-amd64 /opt/snmp_exporter
sudo chown -R prometheus:prometheus /opt/snmp_exporter
Configure SNMP exporter for OSPF
Create SNMP exporter configuration with OSPF-specific OIDs for neighbor states, LSA counts, and topology changes.
auths:
public_v2:
community: public
security_level: noAuthNoPriv
auth_protocol: MD5
priv_protocol: DES
version: 2
modules:
frrouting_ospf:
walk:
# OSPF General Group
- 1.3.6.1.2.1.14.1.1 # ospfRouterId
- 1.3.6.1.2.1.14.1.2 # ospfAdminStat
- 1.3.6.1.2.1.14.1.3 # ospfVersionNumber
- 1.3.6.1.2.1.14.1.4 # ospfAreaBdrRtrStatus
- 1.3.6.1.2.1.14.1.5 # ospfASBdrRtrStatus
# OSPF Area Table
- 1.3.6.1.2.1.14.2.1.1 # ospfAreaId
- 1.3.6.1.2.1.14.2.1.2 # ospfAuthType
- 1.3.6.1.2.1.14.2.1.3 # ospfImportAsExtern
- 1.3.6.1.2.1.14.2.1.4 # ospfSpfRuns
- 1.3.6.1.2.1.14.2.1.5 # ospfAreaBdrRtrCount
- 1.3.6.1.2.1.14.2.1.6 # ospfAsBdrRtrCount
- 1.3.6.1.2.1.14.2.1.7 # ospfAreaLsaCount
# OSPF Interface Table
- 1.3.6.1.2.1.14.7.1.1 # ospfIfIpAddress
- 1.3.6.1.2.1.14.7.1.3 # ospfIfAreaId
- 1.3.6.1.2.1.14.7.1.5 # ospfIfState
- 1.3.6.1.2.1.14.7.1.6 # ospfIfDesignatedRouter
- 1.3.6.1.2.1.14.7.1.7 # ospfIfBackupDesignatedRouter
- 1.3.6.1.2.1.14.7.1.8 # ospfIfEvents
# OSPF Neighbor Table
- 1.3.6.1.2.1.14.10.1.1 # ospfNbrIpAddr
- 1.3.6.1.2.1.14.10.1.3 # ospfNbrRtrId
- 1.3.6.1.2.1.14.10.1.4 # ospfNbrOptions
- 1.3.6.1.2.1.14.10.1.5 # ospfNbrPriority
- 1.3.6.1.2.1.14.10.1.6 # ospfNbrState
- 1.3.6.1.2.1.14.10.1.7 # ospfNbrEvents
- 1.3.6.1.2.1.14.10.1.8 # ospfNbrLsRetransQLen
# OSPF LSA Database
- 1.3.6.1.2.1.14.4.1.1 # ospfLsdbAreaId
- 1.3.6.1.2.1.14.4.1.2 # ospfLsdbType
- 1.3.6.1.2.1.14.4.1.3 # ospfLsdbLsid
- 1.3.6.1.2.1.14.4.1.4 # ospfLsdbRouterId
- 1.3.6.1.2.1.14.4.1.5 # ospfLsdbSequence
- 1.3.6.1.2.1.14.4.1.6 # ospfLsdbAge
- 1.3.6.1.2.1.14.4.1.7 # ospfLsdbChecksum
lookups:
- source_indexes: [ospfNbrIpAddr]
lookup: 1.3.6.1.2.1.14.10.1.6 # ospfNbrState
- source_indexes: [ospfIfIpAddress]
lookup: 1.3.6.1.2.1.14.7.1.5 # ospfIfState
overrides:
ospfNbrState:
type: gauge
ospfIfState:
type: gauge
ospfAreaLsaCount:
type: gauge
ospfSpfRuns:
type: counter
Create Prometheus configuration
Configure Prometheus to scrape OSPF metrics from the SNMP exporter targeting your FRRouting instances.
global:
scrape_interval: 15s
evaluation_interval: 15s
rule_files:
- "/opt/prometheus/rules/*.yml"
alerting:
alertmanagers:
- static_configs:
- targets:
- alertmanager:9093
scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['localhost:9090']
- job_name: 'snmp-ospf'
static_configs:
- targets:
- 203.0.113.1 # FRRouting router 1
- 203.0.113.2 # FRRouting router 2
- 203.0.113.3 # FRRouting router 3
metrics_path: /snmp
params:
module: [frrouting_ospf]
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: instance
- target_label: __address__
replacement: 127.0.0.1:9116 # SNMP exporter address
- job_name: 'node-exporter'
static_configs:
- targets:
- 203.0.113.1:9100
- 203.0.113.2:9100
- 203.0.113.3:9100
Create OSPF alerting rules
Define Prometheus alerting rules for OSPF neighbor state changes and topology issues.
groups:
- name: ospf.rules
rules:
- alert: OSPFNeighborDown
expr: ospfNbrState != 8 # 8 = Full state
for: 30s
labels:
severity: critical
service: ospf
annotations:
summary: "OSPF neighbor {{ $labels.ospfNbrIpAddr }} is not in Full state"
description: "OSPF neighbor {{ $labels.ospfNbrIpAddr }} on router {{ $labels.instance }} is in state {{ $value }}, expected 8 (Full)"
- alert: OSPFInterfaceDown
expr: ospfIfState != 5 # 5 = DR/BDR state for broadcast networks
for: 1m
labels:
severity: warning
service: ospf
annotations:
summary: "OSPF interface {{ $labels.ospfIfIpAddress }} state changed"
description: "OSPF interface {{ $labels.ospfIfIpAddress }} on router {{ $labels.instance }} is in state {{ $value }}"
- alert: OSPFHighLSACount
expr: ospfAreaLsaCount > 1000
for: 5m
labels:
severity: warning
service: ospf
annotations:
summary: "High LSA count in OSPF area {{ $labels.ospfAreaId }}"
description: "OSPF area {{ $labels.ospfAreaId }} has {{ $value }} LSAs, investigate network stability"
- alert: OSPFHighSPFRuns
expr: increase(ospfSpfRuns[5m]) > 10
for: 1m
labels:
severity: warning
service: ospf
annotations:
summary: "High SPF calculation frequency in area {{ $labels.ospfAreaId }}"
description: "OSPF area {{ $labels.ospfAreaId }} had {{ $value }} SPF runs in 5 minutes, indicating network instability"
Create systemd services
Create systemd service files for Prometheus and SNMP exporter to ensure they start automatically.
[Unit]
Description=Prometheus
Wants=network-online.target
After=network-online.target
[Service]
User=prometheus
Group=prometheus
Type=simple
ExecStart=/opt/prometheus/prometheus \
--config.file=/opt/prometheus/prometheus.yml \
--storage.tsdb.path=/opt/prometheus/data \
--web.console.templates=/opt/prometheus/consoles \
--web.console.libraries=/opt/prometheus/console_libraries \
--web.listen-address=0.0.0.0:9090 \
--web.enable-lifecycle
[Install]
WantedBy=multi-user.target
Create SNMP exporter service
Configure the SNMP exporter as a systemd service for automatic startup and monitoring.
[Unit]
Description=SNMP Exporter
Wants=network-online.target
After=network-online.target
[Service]
User=prometheus
Group=prometheus
Type=simple
ExecStart=/opt/snmp_exporter/snmp_exporter --config.file=/opt/snmp_exporter/snmp.yml
Restart=always
[Install]
WantedBy=multi-user.target
Start monitoring services
Enable and start both Prometheus and SNMP exporter services.
sudo systemctl daemon-reload
sudo systemctl enable prometheus snmp-exporter
sudo systemctl start prometheus snmp-exporter
sudo systemctl status prometheus snmp-exporter
Install Grafana
Install Grafana for visualizing OSPF network topology and metrics collected by Prometheus.
wget -q -O - https://packages.grafana.com/gpg.key | sudo apt-key add -
echo "deb https://packages.grafana.com/oss/deb stable main" | sudo tee -a /etc/apt/sources.list.d/grafana.list
sudo apt update
sudo apt install -y grafana
Configure Grafana data source
Add Prometheus as a data source in Grafana to access OSPF metrics.
sudo systemctl enable grafana-server
sudo systemctl start grafana-server
Wait for Grafana to start, then configure data source
sleep 10
curl -X POST \
http://admin:admin@localhost:3000/api/datasources \
-H 'Content-Type: application/json' \
-d '{
"name": "Prometheus",
"type": "prometheus",
"url": "http://localhost:9090",
"access": "proxy",
"isDefault": true
}'
Import OSPF dashboard
Create a comprehensive OSPF monitoring dashboard in Grafana with network topology visualization.
{
"dashboard": {
"id": null,
"title": "OSPF Network Monitoring",
"tags": ["ospf", "networking", "frrouting"],
"timezone": "browser",
"panels": [
{
"id": 1,
"title": "OSPF Neighbor States",
"type": "stat",
"targets": [{
"expr": "count by (instance) (ospfNbrState == 8)",
"refId": "A",
"legendFormat": "{{instance}} - Full Neighbors"
}],
"gridPos": {"h": 8, "w": 12, "x": 0, "y": 0}
},
{
"id": 2,
"title": "LSA Database Size",
"type": "graph",
"targets": [{
"expr": "ospfAreaLsaCount",
"refId": "A",
"legendFormat": "Area {{ospfAreaId}} - LSA Count"
}],
"gridPos": {"h": 8, "w": 12, "x": 12, "y": 0}
},
{
"id": 3,
"title": "SPF Calculation Frequency",
"type": "graph",
"targets": [{
"expr": "rate(ospfSpfRuns[5m]) * 300",
"refId": "A",
"legendFormat": "{{instance}} - Area {{ospfAreaId}}"
}],
"gridPos": {"h": 8, "w": 24, "x": 0, "y": 8}
},
{
"id": 4,
"title": "OSPF Interface States",
"type": "table",
"targets": [{
"expr": "ospfIfState",
"refId": "A",
"format": "table",
"instant": true
}],
"gridPos": {"h": 8, "w": 24, "x": 0, "y": 16}
}
],
"time": {"from": "now-1h", "to": "now"},
"refresh": "30s"
}
}
Import the dashboard
Load the OSPF dashboard configuration into Grafana via the API.
curl -X POST \
http://admin:admin@localhost:3000/api/dashboards/db \
-H 'Content-Type: application/json' \
-d @/tmp/ospf-dashboard.json
sudo grafana-cli admin reset-admin-password newpassword or configure authentication through the web interface.Configure advanced OSPF monitoring
Enable detailed OSPF logging
Configure FRRouting to log detailed OSPF events for troubleshooting and analysis.
sudo vtysh -c 'configure terminal' \
-c 'log file /var/log/frr/ospfd.log' \
-c 'debug ospf event' \
-c 'debug ospf lsa' \
-c 'debug ospf neighbor' \
-c 'write memory'
Configure log rotation
Set up log rotation for OSPF logs to prevent disk space issues.
/var/log/frr/*.log {
daily
missingok
rotate 14
compress
delaycompress
notifempty
create 640 frr frr
postrotate
/bin/kill -USR1 cat /var/run/frr/*.pid 2> /dev/null 2> /dev/null || true
endscript
}
Set up network topology discovery
As mentioned in automated network topology discovery, you can enhance monitoring by adding LLDP data collection for complete network mapping.
# Install LLDP daemon
sudo apt install -y lldpd
Enable SNMP in LLDP configuration
echo 'configure system interface pattern *' | sudo lldpcli
echo 'configure system description "OSPF Router"' | sudo lldpcli
Start LLDP service
sudo systemctl enable lldpd
sudo systemctl start lldpd
Verify your setup
Confirm that all monitoring components are working correctly and collecting OSPF metrics.
# Check FRRouting OSPF status
sudo vtysh -c 'show ip ospf neighbor'
sudo vtysh -c 'show ip ospf database'
Verify SNMP is responding
snmpwalk -v2c -c public localhost 1.3.6.1.2.1.14.10.1.6 # OSPF neighbor states
Test SNMP exporter
curl http://localhost:9116/snmp?target=127.0.0.1&module=frrouting_ospf
Check Prometheus targets
curl http://localhost:9090/api/v1/targets
Verify Grafana is accessible
curl http://localhost:3000/api/health
Test OSPF metrics in Prometheus
curl 'http://localhost:9090/api/v1/query?query=ospfNbrState'
Common issues
| Symptom | Cause | Fix |
|---|---|---|
| SNMP exporter returns no metrics | SNMP community mismatch or firewall blocking | Verify /etc/frr/frr.conf SNMP community matches exporter config |
| OSPF neighbors not appearing | Network connectivity or authentication issues | Check sudo vtysh -c 'show ip ospf neighbor' and interface states |
| Grafana dashboard shows no data | Prometheus not scraping SNMP exporter | Check Prometheus targets at http://localhost:9090/targets |
| High memory usage on router | Too frequent SNMP polling | Increase scrape_interval in prometheus.yml to 30s or 60s |
| Missing LSA database metrics | OSPF not fully converged | Wait for OSPF convergence or check area configuration |
| Permission denied on log files | Incorrect file ownership | sudo chown frr:frr /var/log/frr/*.log |
Next steps
- Configure FRRouting route maps and prefix lists for advanced OSPF routing policies
- Implement network monitoring with SNMP and BGP metrics to extend monitoring to BGP
- Configure OSPF authentication and security hardening for production deployment
- Set up OSPF multi-area configuration for larger network topologies
- Implement OSPF traffic engineering for optimized network utilization
Running this in production?
Automated install script
Run this to automate the entire setup
#!/usr/bin/env bash
set -euo pipefail
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
# Configuration
PROMETHEUS_VERSION="2.45.0"
SNMP_EXPORTER_VERSION="0.24.1"
FRROUTING_USER="frr"
PROMETHEUS_USER="prometheus"
# Usage
usage() {
cat << EOF
Usage: $0 [OPTIONS]
Install OSPF monitoring with Prometheus and Grafana
OPTIONS:
-r, --router-id IP OSPF Router ID (default: auto-detect)
-n, --networks NETS OSPF networks comma-separated (default: auto-detect)
-h, --help Show this help
Example:
$0 --router-id 203.0.113.1 --networks "203.0.113.0/24,198.51.100.0/24"
EOF
exit 1
}
# Parse arguments
ROUTER_ID=""
NETWORKS=""
while [[ $# -gt 0 ]]; do
case $1 in
-r|--router-id) ROUTER_ID="$2"; shift 2 ;;
-n|--networks) NETWORKS="$2"; shift 2 ;;
-h|--help) usage ;;
*) echo -e "${RED}Unknown option: $1${NC}"; usage ;;
esac
done
# Detect distribution
if [ -f /etc/os-release ]; then
. /etc/os-release
case "$ID" in
ubuntu|debian)
PKG_MGR="apt"
PKG_UPDATE="apt update && apt upgrade -y"
PKG_INSTALL="apt install -y"
FIREWALL_CMD="ufw"
;;
almalinux|rocky|centos|rhel|ol|fedora)
PKG_MGR="dnf"
PKG_UPDATE="dnf update -y"
PKG_INSTALL="dnf install -y"
FIREWALL_CMD="firewall-cmd"
;;
amzn)
PKG_MGR="yum"
PKG_UPDATE="yum update -y"
PKG_INSTALL="yum install -y"
FIREWALL_CMD="firewall-cmd"
;;
*) echo -e "${RED}Unsupported distribution: $ID${NC}"; exit 1 ;;
esac
else
echo -e "${RED}Cannot detect distribution${NC}"; exit 1
fi
# Cleanup function
cleanup() {
echo -e "${RED}Installation failed. Cleaning up...${NC}"
systemctl stop prometheus snmp_exporter grafana-server frr 2>/dev/null || true
rm -rf /opt/prometheus /opt/snmp_exporter /tmp/prometheus* /tmp/snmp_exporter* 2>/dev/null || true
}
trap cleanup ERR
# Check prerequisites
if [[ $EUID -ne 0 ]]; then
echo -e "${RED}This script must be run as root${NC}"
exit 1
fi
echo -e "${GREEN}[1/10] Updating system packages...${NC}"
$PKG_UPDATE
echo -e "${GREEN}[2/10] Installing base packages...${NC}"
if [[ "$PKG_MGR" == "apt" ]]; then
$PKG_INSTALL curl wget gnupg2 software-properties-common net-tools
else
$PKG_INSTALL curl wget gnupg2 net-tools which
fi
# Auto-detect router ID if not provided
if [[ -z "$ROUTER_ID" ]]; then
ROUTER_ID=$(ip route get 8.8.8.8 | head -1 | awk '{print $7}')
echo -e "${YELLOW}Auto-detected router ID: $ROUTER_ID${NC}"
fi
# Auto-detect networks if not provided
if [[ -z "$NETWORKS" ]]; then
NETWORKS=$(ip route | grep -E "^[0-9]" | grep -v default | awk '{print $1}' | head -2 | tr '\n' ',' | sed 's/,$//')
echo -e "${YELLOW}Auto-detected networks: $NETWORKS${NC}"
fi
echo -e "${GREEN}[3/10] Installing FRRouting...${NC}"
if [[ "$PKG_MGR" == "apt" ]]; then
curl -s https://deb.frrouting.org/frr/keys.asc | apt-key add -
echo "deb https://deb.frrouting.org/frr $(lsb_release -s -c) frr-stable" > /etc/apt/sources.list.d/frr.list
apt update
$PKG_INSTALL frr frr-pythontools frr-snmp
else
$PKG_INSTALL "https://rpm.frrouting.org/repo/frr-stable-repo-1-0.el$(rpm -E %{rhel}).noarch.rpm"
$PKG_INSTALL frr frr-pythontools frr-snmp
fi
echo -e "${GREEN}[4/10] Configuring FRRouting daemons...${NC}"
cat > /etc/frr/daemons << 'EOF'
zebra=yes
ospfd=yes
ospf6d=no
ripd=no
ripngd=no
isisd=no
babeld=no
pimd=no
ldpd=no
nhrpd=no
eigrpd=no
sharpd=no
pbrd=no
staticd=no
bfdd=no
snmp=yes
EOF
echo -e "${GREEN}[5/10] Configuring OSPF routing...${NC}"
cat > /etc/frr/frr.conf << EOF
frr version 8.4.2
frr defaults traditional
hostname frr-router
log syslog informational
no ipv6 forwarding
service integrated-vtysh-config
!
router ospf
router-id $ROUTER_ID
$(echo "$NETWORKS" | tr ',' '\n' | awk -v area=0 '{printf " network %s area 0.0.0.%d\n", $0, area; area++}')
area 0.0.0.0 authentication message-digest
passive-interface default
redistribute connected
redistribute static
!
snmp-server community public ro
snmp-server location "Network Operations Center"
snmp-server contact "admin@localhost"
!
line vty
!
end
EOF
chown $FRROUTING_USER:$FRROUTING_USER /etc/frr/frr.conf
chmod 640 /etc/frr/frr.conf
systemctl enable frr
systemctl start frr
echo -e "${GREEN}[6/10] Installing Prometheus...${NC}"
useradd -M -r -s /bin/false $PROMETHEUS_USER 2>/dev/null || true
cd /tmp
wget "https://github.com/prometheus/prometheus/releases/download/v${PROMETHEUS_VERSION}/prometheus-${PROMETHEUS_VERSION}.linux-amd64.tar.gz"
tar -xzf "prometheus-${PROMETHEUS_VERSION}.linux-amd64.tar.gz"
mv "prometheus-${PROMETHEUS_VERSION}.linux-amd64" /opt/prometheus
chown -R $PROMETHEUS_USER:$PROMETHEUS_USER /opt/prometheus
mkdir -p /var/lib/prometheus
chown $PROMETHEUS_USER:$PROMETHEUS_USER /var/lib/prometheus
echo -e "${GREEN}[7/10] Installing SNMP Exporter...${NC}"
wget "https://github.com/prometheus/snmp_exporter/releases/download/v${SNMP_EXPORTER_VERSION}/snmp_exporter-${SNMP_EXPORTER_VERSION}.linux-amd64.tar.gz"
tar -xzf "snmp_exporter-${SNMP_EXPORTER_VERSION}.linux-amd64.tar.gz"
mv "snmp_exporter-${SNMP_EXPORTER_VERSION}.linux-amd64" /opt/snmp_exporter
chown -R $PROMETHEUS_USER:$PROMETHEUS_USER /opt/snmp_exporter
echo -e "${GREEN}[8/10] Configuring SNMP Exporter...${NC}"
cat > /opt/snmp_exporter/snmp.yml << 'EOF'
auths:
public_v2:
community: public
security_level: noAuthNoPriv
version: 2
modules:
frrouting_ospf:
walk:
- 1.3.6.1.2.1.14.1.1
- 1.3.6.1.2.1.14.1.2
- 1.3.6.1.2.1.14.1.3
- 1.3.6.1.2.1.14.2.1
- 1.3.6.1.2.1.14.10.1
metrics:
- name: ospf_router_id
oid: 1.3.6.1.2.1.14.1.1
type: gauge
- name: ospf_admin_stat
oid: 1.3.6.1.2.1.14.1.2
type: gauge
EOF
chown -R $PROMETHEUS_USER:$PROMETHEUS_USER /opt/snmp_exporter/snmp.yml
echo -e "${GREEN}[9/10] Creating systemd services...${NC}"
cat > /etc/systemd/system/prometheus.service << EOF
[Unit]
Description=Prometheus
After=network.target
[Service]
User=$PROMETHEUS_USER
Group=$PROMETHEUS_USER
Type=simple
ExecStart=/opt/prometheus/prometheus \\
--config.file=/opt/prometheus/prometheus.yml \\
--storage.tsdb.path=/var/lib/prometheus/ \\
--web.console.templates=/opt/prometheus/consoles \\
--web.console.libraries=/opt/prometheus/console_libraries \\
--web.listen-address=0.0.0.0:9090
[Install]
WantedBy=multi-user.target
EOF
cat > /etc/systemd/system/snmp_exporter.service << EOF
[Unit]
Description=SNMP Exporter
After=network.target
[Service]
User=$PROMETHEUS_USER
Group=$PROMETHEUS_USER
Type=simple
ExecStart=/opt/snmp_exporter/snmp_exporter --config.file=/opt/snmp_exporter/snmp.yml
[Install]
WantedBy=multi-user.target
EOF
cat > /opt/prometheus/prometheus.yml << EOF
global:
scrape_interval: 15s
scrape_configs:
- job_name: 'snmp'
static_configs:
- targets:
- 127.0.0.1
metrics_path: /snmp
params:
module: [frrouting_ospf]
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: instance
- target_label: __address__
replacement: 127.0.0.1:9116
EOF
chown -R $PROMETHEUS_USER:$PROMETHEUS_USER /opt/prometheus/prometheus.yml
systemctl daemon-reload
systemctl enable prometheus snmp_exporter
systemctl start prometheus snmp_exporter
echo -e "${GREEN}[10/10] Configuring firewall...${NC}"
if [[ "$FIREWALL_CMD" == "ufw" ]]; then
ufw allow 9090/tcp comment "Prometheus"
ufw allow 9116/tcp comment "SNMP Exporter"
elif [[ "$FIREWALL_CMD" == "firewall-cmd" ]]; then
firewall-cmd --permanent --add-port=9090/tcp
firewall-cmd --permanent --add-port=9116/tcp
firewall-cmd --reload
fi
echo -e "${GREEN}Installation completed successfully!${NC}"
echo -e "${YELLOW}Verification:${NC}"
echo "- OSPF Status: vtysh -c 'show ip ospf neighbor'"
echo "- Prometheus: http://localhost:9090"
echo "- SNMP Exporter: http://localhost:9116"
echo "- FRRouting Status: systemctl status frr"
# Verification
sleep 5
if systemctl is-active --quiet frr prometheus snmp_exporter; then
echo -e "${GREEN}✓ All services are running${NC}"
else
echo -e "${RED}✗ Some services failed to start${NC}"
exit 1
fi
Review the script before running. Execute with: bash install.sh