Icinga is an open-source monitoring system that extends Nagios with additional features and a modern architecture. Icinga 2 uses a flexible configuration language and supports distributed monitoring setups.
| File/Directory | Path | Purpose |
|---|---|---|
| Main config | /etc/icinga2/icinga2.conf |
Primary Icinga 2 configuration |
| Constants | /etc/icinga2/constants.conf |
Global constants and paths |
| Zones | /etc/icinga2/zones.conf |
Zone and endpoint definitions |
| Objects | /etc/icinga2/conf.d/ |
Object configuration files |
| Templates | /etc/icinga2/conf.d/templates.conf |
Object templates |
| Hosts | /etc/icinga2/conf.d/hosts.conf |
Host definitions |
| Services | /etc/icinga2/conf.d/services.conf |
Service definitions |
| Commands | /etc/icinga2/conf.d/commands.conf |
Check command definitions |
| Notifications | /etc/icinga2/conf.d/notifications.conf |
Notification settings |
| Features | /etc/icinga2/features-available/ |
Available features |
| Features enabled | /etc/icinga2/features-enabled/ |
Enabled features (symlinks) |
| Check commands | /etc/icinga2/conf.d/check_commands.conf |
Plugin commands |
| Icinga Classic | /etc/icinga/icinga.cfg |
Icinga Classic config |
| CGI config | /etc/icinga/cgi.cfg |
Icinga Classic CGI settings |
| Resource file | /etc/icinga2/resource.conf |
Macro definitions |
| Log files | /var/log/icinga2/ |
Icinga log files |
/*
* /etc/icinga2/icinga2.conf
* Icinga 2 Main Configuration File
*/
/* Include constants */
include <constants>
/* Include the Zoning configuration */
include <zones>
/* Include feature setup */
include <features>
/* Include local object configuration */
include "/etc/icinga2/conf.d"
/* Global variables */
globals {
/* Enable performance data */
PerfdataWriter {
enable = true
}
/* Enable command execution */
ExternalCommandListener {
enable = true
}
}
/* Logging configuration */
library "perfdata"
/* Error handling */
ErrorLog {
enable = true
}
/* Debug logging (disable in production) */
/*
DebugLogger {
enable = true
}
*/
/*
* /etc/icinga2/constants.conf
* Global Constants
*/
/* Directory paths */
const ConfDir = "/etc/icinga2/conf.d"
const DataDir = "/var/lib/icinga2"
const LogDir = "/var/log/icinga2"
const CacheDir = "/var/cache/icinga2"
const RunDir = "/var/run/icinga2"
/* Check plugin paths */
const PluginDir = "/usr/lib/nagios/plugins"
const ContribPluginDir = "/usr/share/icinga2-ido-mysql/contrib"
/* Include directories */
const IncludeConfDir = "/etc/icinga2/conf.d"
/* Node name */
const NodeName = "icinga-master.example.com"
/* API credentials */
const ApiUsername = "icingaadmin"
const ApiPassword = "SecureApiPassword123!"
/* Database credentials */
const DBUser = "icinga"
const DBPass = "SecureDbPassword123!"
const DBName = "icinga"
/* Email settings */
const AdminEmail = "admin@example.com"
const AlertEmail = "alerts@example.com"
/*
* /etc/icinga2/zones.conf
* Zone and Endpoint Definitions
*/
/* Master zone */
object Zone "master" {
endpoints = [ "icinga-master" ]
}
/* Master endpoint */
object Endpoint "icinga-master" {
host = "icinga-master.example.com"
port = "5665"
}
/* Satellite zone */
object Zone "satellite-dc1" {
endpoints = [ "satellite-dc1" ]
parent = "master"
}
/* Satellite endpoint */
object Endpoint "satellite-dc1" {
host = "satellite-dc1.example.com"
port = "5665"
}
/* Agent zone */
object Zone "agent-webserver01" {
parent = "satellite-dc1"
}
/* Agent endpoint */
object Endpoint "webserver01" {
host = "192.168.1.10"
port = "5665"
log_duration = 0 /* Disable command log for agents */
}
/* Additional agent zones */
object Zone "agent-dbserver01" {
parent = "satellite-dc1"
}
object Endpoint "dbserver01" {
host = "192.168.1.20"
port = "5665"
log_duration = 0
}
/*
* /etc/icinga2/resource.conf
* Macro Definitions
*/
/* Database credentials */
$DBUser = "icinga"
$DBPass = "SecureDbPassword123!"
$DBName = "icinga"
/* API credentials */
$ApiUser = "icingaadmin"
$ApiPass = "SecureApiPassword123!"
/* Email settings */
$AdminEmail = "admin@example.com"
$AlertEmail = "alerts@example.com"
$SmtpServer = "smtp.example.com"
$SmtpPort = "587"
$SmtpUser = "icinga@example.com"
$SmtpPass = "EmailPassword123!"
/* Plugin paths */
$PluginDir = "/usr/lib/nagios/plugins"
$ContribPluginDir = "/usr/share/icinga2-ido-mysql/contrib"
/* Custom macros */
$SlackWebhook = "https://hooks.slack.com/services/XXX/YYY/ZZZ"
$PagerDutyKey = "your-pagerduty-key"
/*
* /etc/icinga2/conf.d/commands.conf
* Check Command Definitions
*/
object CheckCommand "hostalive" {
import "plugin-check-command"
command = [ PluginDir + "/check_ping" ]
arguments = {
"-H" = "$address$"
"-w" = {
value = "3000.0,80%"
description = "Warning threshold"
}
"-c" = {
value = "5000.0,100%"
description = "Critical threshold"
}
}
}
object CheckCommand "http" {
import "plugin-check-command"
command = [ PluginDir + "/check_http" ]
arguments = {
"-H" = "$address$"
"-u" = {
value = "$http_uri$"
default = "/"
}
"-p" = {
value = "$http_port$"
default = "80"
}
"-s" = {
value = "$http_expect$"
description = "Expected string in response"
}
"--ssl" = {
set_if = "$http_ssl$"
}
}
vars.http_uri = "/"
vars.http_port = "80"
vars.http_ssl = false
}
object CheckCommand "ssh" {
import "plugin-check-command"
command = [ PluginDir + "/check_ssh" ]
arguments = {
"-H" = "$address$"
"-p" = {
value = "$ssh_port$"
default = "22"
}
}
vars.ssh_port = "22"
}
object CheckCommand "disk" {
import "plugin-check-command"
command = [ PluginDir + "/check_disk" ]
arguments = {
"-w" = {
value = "$disk_warn$"
default = "20%"
}
"-c" = {
value = "$disk_crit$"
default = "10%"
}
"-p" = {
value = "$disk_partition$"
default = "/"
}
}
vars.disk_warn = "20%"
vars.disk_crit = "10%"
vars.disk_partition = "/"
}
object CheckCommand "mysql" {
import "plugin-check-command"
command = [ PluginDir + "/check_mysql" ]
arguments = {
"-H" = "$address$"
"-u" = "$mysql_user$"
"-p" = "$mysql_password$"
"-d" = {
value = "$mysql_database$"
default = "mysql"
}
}
vars.mysql_user = "monitoring"
vars.mysql_password = "MonitoringPass123!"
vars.mysql_database = "mysql"
}
object CheckCommand "check_api" {
import "plugin-check-command"
command = [ PluginDir + "/check_http" ]
arguments = {
"-H" = "$address$"
"-u" = "$api_uri$"
"-p" = "$api_port$"
"-k" = "Authorization: Bearer $api_token$"
"--expect" = "$api_expect$"
}
vars.api_uri = "/api/health"
vars.api_port = "8080"
}
/*
* /etc/icinga2/conf.d/templates.conf
* Object Templates
*/
/* Host Templates */
template Host "generic-host" {
check_command = "hostalive"
check_interval = 60s
retry_interval = 15s
max_check_attempts = 5
check_period = "24x7"
enable_active_checks = true
enable_passive_checks = true
enable_event_handler = true
enable_notifications = true
event_command = "host-event-handler"
}
template Host "linux-host" {
import "generic-host"
check_command = "hostalive"
vars.os = "linux"
vars.os_version = "unknown"
}
template Host "windows-host" {
import "generic-host"
check_command = "hostalive"
vars.os = "windows"
}
template Host "network-device" {
import "generic-host"
check_command = "hostalive"
vars.os = "network"
}
/* Service Templates */
template Service "generic-service" {
max_check_attempts = 3
check_interval = 60s
retry_interval = 15s
check_period = "24x7"
enable_active_checks = true
enable_passive_checks = true
enable_event_handler = true
enable_notifications = true
}
template Service "http-service" {
import "generic-service"
check_command = "http"
vars.http_ssl = false
vars.http_expect = "200"
}
template Service "https-service" {
import "http-service"
vars.http_ssl = true
vars.http_port = "443"
}
template Service "ssh-service" {
import "generic-service"
check_command = "ssh"
}
template Service "disk-service" {
import "generic-service"
check_command = "disk"
}
/*
* /etc/icinga2/conf.d/hosts.conf
* Host Definitions
*/
/* Web Server */
object Host "webserver01" {
import "linux-host"
address = "192.168.1.10"
display_name = "Web Server 01"
vars.os = "linux"
vars.os_version = "Ubuntu 22.04"
vars["ssh_port"] = 22
vars["http_port"] = 80
vars["https_port"] = 443
vars.disks["disk /"] = {
disk_partition = "/"
disk_warn = "20%"
disk_crit = "10%"
}
vars.disks["disk /var"] = {
disk_partition = "/var"
disk_warn = "25%"
disk_crit = "15%"
}
vars.urls["main-site"] = {
http_uri = "/"
http_expect = "200"
http_ssl = true
}
vars.notification_email = "webteam@example.com"
vars.slack_channel = "#web-alerts"
groups = [ "webservers", "production" ]
}
/* Database Server */
object Host "dbserver01" {
import "linux-host"
address = "192.168.1.20"
display_name = "Database Server 01"
vars.os = "linux"
vars.os_version = "Ubuntu 22.04"
vars["mysql_port"] = 3306
vars["mysql_user"] = "monitoring"
vars["mysql_password"] = "MonitoringPass123!"
vars.disks["disk /"] = {
disk_partition = "/"
disk_warn = "20%"
disk_crit = "10%"
}
vars.disks["disk /var/lib/mysql"] = {
disk_partition = "/var/lib/mysql"
disk_warn = "30%"
disk_crit = "20%"
}
vars.notification_email = "dba@example.com"
vars.slack_channel = "#db-alerts"
groups = [ "databases", "production" ]
}
/* Network Device */
object Host "switch-core-01" {
import "network-device"
address = "192.168.1.1"
display_name = "Core Switch 01"
vars.os = "cisco-ios"
vars.snmp_community = "public"
groups = [ "network", "core" ]
}
/*
* /etc/icinga2/conf.d/services.conf
* Service Definitions
*/
/* HTTP Service for webserver01 */
apply Service "http" {
import "https-service"
check_interval = 30s
retry_interval = 10s
assign where host.name == "webserver01"
}
/* SSH Service for all Linux hosts */
apply Service "ssh" {
import "ssh-service"
assign where host.vars.os == "linux"
}
/* Disk checks based on host variables */
apply Service "disk" for (disk_name => disk_config in host.vars.disks) {
import "disk-service"
display_name = "Disk " + disk_name
check_interval = 300s
vars.disk_partition = disk_config.disk_partition
vars.disk_warn = disk_config.disk_warn
vars.disk_crit = disk_config.disk_crit
assign where host.vars.disks
}
/* MySQL check for database servers */
apply Service "mysql" {
import "generic-service"
check_command = "mysql"
check_interval = 60s
vars.mysql_user = host.vars.mysql_user
vars.mysql_password = host.vars.mysql_password
assign where host.vars.mysql_port
}
/* URL checks */
apply Service "url" for (url_name => url_config in host.vars.urls) {
import "generic-service"
check_command = "http"
display_name = "URL " + url_name
vars.http_uri = url_config.http_uri
vars.http_expect = url_config.http_expect
vars.http_ssl = url_config.http_ssl
assign where host.vars.urls
}
/*
* /etc/icinga2/conf.d/contacts.conf
* Contact and Contact Group Definitions
*/
object User "admin" {
email = "admin@example.com"
pager = "+1234567890"
groups = [ "admins" ]
}
object User "ops-user" {
email = "ops@example.com"
groups = [ "ops" ]
}
object User "dba-user" {
email = "dba@example.com"
groups = [ "dba" ]
}
object User "web-user" {
email = "web@example.com"
groups = [ "web" ]
}
/* Contact Groups */
object UserGroup "admins" {
members = [ "admin" ]
}
object UserGroup "ops" {
members = [ "ops-user" ]
}
object UserGroup "dba" {
members = [ "dba-user" ]
}
object UserGroup "web" {
members = [ "web-user" ]
}
object UserGroup "oncall" {
members = [ "admin", "ops-user" ]
}
/*
* /etc/icinga2/conf.d/notifications.conf
* Notification Commands and Templates
*/
/* Email Notification Command */
object NotificationCommand "mail-service-notification" {
command = [ "/usr/bin/printf" ]
arguments = {
"%b" = "Icinga Service Notification"
"%r" = "$host.name$"
"%s" = "$service.state$"
"%i" = "$service.last_check_result$.output"
"%d" = "$service.last_check$"
"%e" = "$service.check_command$"
"%n" = "$service.name$"
}
}
object NotificationCommand "mail-host-notification" {
command = [ "/usr/bin/printf" ]
arguments = {
"%b" = "Icinga Host Notification"
"%r" = "$host.name$"
"%s" = "$host.state$"
"%i" = "$host.last_check_result$.output"
"%d" = "$host.last_check$"
}
}
/* Slack Notification Command */
object NotificationCommand "slack-service-notification" {
command = [ "/usr/lib/nagios/plugins/notify_slack.py" ]
arguments = {
"-w" = "$slack_webhook$"
"-c" = "$slack_channel$"
"-s" = "$service.state$"
"-h" = "$host.name$"
"-n" = "$service.name$"
"-o" = "$service.last_check_result$.output"
}
vars.slack_webhook = "$SlackWebhook$"
}
/* Notification Templates */
template Notification "default-service-notification" {
command = "mail-service-notification"
user_groups = [ "oncall" ]
states = [ Warning, Critical, Unknown ]
types = [ Problem, Recovery ]
period = "24x7"
}
template Notification "default-host-notification" {
command = "mail-host-notification"
user_groups = [ "oncall" ]
states = [ Down, Unreachable ]
types = [ Problem, Recovery ]
period = "24x7"
}
template Notification "slack-service-notification" {
command = "slack-service-notification"
user_groups = [ "ops" ]
states = [ Critical ]
types = [ Problem ]
period = "24x7"
}
/* Apply Notifications */
apply Notification "service-email" to Service {
import "default-service-notification"
assign where host.name != "icinga-master"
}
apply Notification "host-email" to Host {
import "default-host-notification"
assign where host.name != "icinga-master"
}
apply Notification "service-slack" to Service {
import "slack-service-notification"
assign where service.state == Critical
}
/*
* /etc/icinga2/conf.d/timeperiods.conf
* Time Period Definitions
*/
object TimePeriod "24x7" {
display_name = "24 Hours A Day, 7 Days A Week"
ranges = {
monday = "00:00-24:00"
tuesday = "00:00-24:00"
wednesday = "00:00-24:00"
thursday = "00:00-24:00"
friday = "00:00-24:00"
saturday = "00:00-24:00"
sunday = "00:00-24:00"
}
}
object TimePeriod "workhours" {
display_name = "Work Hours (8AM-6PM)"
ranges = {
monday = "08:00-18:00"
tuesday = "08:00-18:00"
wednesday = "08:00-18:00"
thursday = "08:00-18:00"
friday = "08:00-18:00"
}
}
object TimePeriod "night" {
display_name = "Night Hours"
ranges = {
monday = "18:00-24:00"
tuesday = "18:00-24:00"
wednesday = "18:00-24:00"
thursday = "18:00-24:00"
friday = "18:00-24:00"
saturday = "00:00-24:00"
sunday = "00:00-24:00"
}
}
object TimePeriod "never" {
display_name = "Never"
}
# Validate Icinga 2 configuration
sudo icinga2 daemon -C
# Validate with verbose output
sudo icinga2 daemon -C -v
# Check object configuration
sudo icinga2 object list
# List hosts
sudo icinga2 object list --type Host
# List services
sudo icinga2 object list --type Service
# Restart Icinga 2
sudo systemctl restart icinga2
# Check service status
sudo systemctl status icinga2
# View logs
sudo journalctl -u icinga2 -f
sudo tail -f /var/log/icinga2/icinga2.log
# Reload configuration without restart
sudo systemctl reload icinga2
# List available features
sudo icinga2 feature list
# Enable features
sudo icinga2 feature enable command
sudo icinga2 feature enable checker
sudo icinga2 feature enable api
sudo icinga2 feature enable ido-mysql
sudo icinga2 feature enable perfdata
sudo icinga2 feature enable syslog
# Disable features
sudo icinga2 feature disable debuglog
# Apply changes
sudo icinga2 daemon -C && sudo systemctl restart icinga2
# List all objects
sudo icinga2 object list
# List hosts
sudo icinga2 object list --type Host
# List services
sudo icinga2 object list --type Service
# List contacts
sudo icinga2 object list --type User
# List notifications
sudo icinga2 object list --type Notification
# Test API connection
curl -k -u icingaadmin:SecureApiPassword123! https://localhost:5665/v1/status
# Get host status
curl -k -u icingaadmin:SecureApiPassword123! \
-H 'Accept: application/json' \
'https://localhost:5665/v1/objects/hosts/webserver01'
# Execute check via API
curl -k -u icingaadmin:SecureApiPassword123! \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
-X POST 'https://localhost:5665/v1/actions/process-check-result' \
-d '{"type": "Service", "filter": "host.name==\"webserver01\" && service.name==\"http\"", "exit_status": 0, "plugin_output": "OK"}'
# Force check execution
sudo icingacli director schedule check --host webserver01 --service http
# Check pending checks
sudo icinga2 object list --type CheckCommand
# View check results
sudo tail -f /var/log/icinga2/icinga2.log | grep "CheckResult"
# Send test notification
sudo icingacli director notification send --host webserver01 --service http --type Problem
# View notification log
sudo tail -f /var/log/icinga2/icinga2.log | grep "Notification"
# Check notification history (via IDO)
mysql -u icinga -p -e "SELECT * FROM icinga_notifications ORDER BY notification_id DESC LIMIT 10;" icinga
Squeezing every bit of performance from your Icinga installation? Our experts help with:
Optimize your setup: office@linux-server-admin.com | Contact Us