Icinga 2 Installation Guide

Install package

sudo apt-get update
sudo apt-get -y install apt-transport-https wget gnupg lsb-core

Import icinga2 key

wget https://packages.icinga.com/icinga.key
sudo apt-key add icinga.key
rm -f icinga.key

Add repo

sudo tee /etc/apt/sources.list.d/$(lsb_release -sc)-icinga.list <<EOF
deb https://packages.icinga.com/ubuntu icinga-$(lsb_release -sc) main
deb-src https://packages.icinga.com/ubuntu icinga-$(lsb_release -sc) main
EOF

Install icinga2

sudo apt-get update
sudo apt-get install -y icinga2

Install Monitor package

sudo apt-get install -y monitoring-plugins

Vim syntax Highlinght(no need no install)

sudo apt-get install -y vim-icinga2 vim-addon-manager
sudo vim-addon-manager -w install icinga2

Install Mysql

sudo apt-get -y install mysql-server libmysqlclient-dev

DB_PASSWORD=`cat /dev/urandom | tr -dc A-Za-z0-9 | head -c 24`
echo -e "\033[31m YOUR DB PASSWORD IS $DB_PASSWORD \033[0m"
echo "DB_PASSWORD=$DB_PASSWORD" >> ~/.bashrc

mysql -u debian-sys-maint -p$(sudo cat /etc/mysql/debian.cnf|grep password|head -1|awk '{print $3}') \
-e "alter user root@'localhost' identified with mysql_native_password by '$DB_PASSWORD';"
# Create icinga db and set password
ICINGA_PASSWORD=`cat /dev/urandom | tr -dc A-Za-z0-9 | head -c 24`
echo -e "\033[31m YOUR ICINGA PASSWORD IS $ICINGA_PASSWORD \033[0m"
echo "ICINGA_PASSWORD=$ICINGA_PASSWORD" >> ~/.bashrc

mysql -uroot -p$DB_PASSWORD -e "create database icinga;"
mysql -uroot -p$DB_PASSWORD -e "grant all on icinga.* to 'icinga'@'%' identified by '$ICINGA_PASSWORD';"
mysql -uroot -p$DB_PASSWORD -e "drop user 'debian-sys-maint'@'localhost';"
mysql -uroot -p$DB_PASSWORD -e "show databases;"
mysql -uroot -p$DB_PASSWORD -e "select user,host,authentication_string from mysql.user;"
mysql -uicinga -p$ICINGA_PASSWORD -e "show databases;"

sudo systemctl enable mysql
sudo systemctl restart mysql

Install icinga2 IDO module

---choose no
sudo apt-get install -y icinga2-ido-mysql

sudo icinga2 feature enable ido-mysql

mysql -uroot -p$DB_PASSWORD icinga < /usr/share/icinga2-ido-mysql/schema/mysql.sql

# host is your ip or cn
sudo tee /etc/icinga2/features-enabled/ido-mysql.conf << EOF
/**
 * The db_ido_mysql library implements IDO functionality
 * for MySQL.
 */

library "db_ido_mysql"

object IdoMysqlConnection "ido-mysql" {
  user = "icinga",
  password = "$ICINGA_PASSWORD",
  host = "localhost",
  database = "icinga"
}
EOF

sudo cat /etc/icinga2/features-enabled/ido-mysql.conf
sudo systemctl restart icinga2
sudo systemctl enable icinga2

install php

sudo apt-get install -y \
php7.0 \
php7.0-curl \
libapache2-mod-php7.0 \
php7.0-gd \
php7.0-intl \
php7.0-xml \
php7.0-ldap \
php7.0-mysql \
php7.0-pgsql \
php7.0-mbstring \
php7.0-fpm \
php7.0-json \
php7.0-common \
php7.0-cli \
php7.0-zip

# set your timezone
sudo sed -i '/;date.timezone =/s#.*#date.timezone = Asia/Shanghai#g' /etc/php/7.0/apache2/php.ini
sudo sed -i '/;date.timezone =/s#.*#date.timezone = Asia/Shanghai#g'  /etc/php/7.0/fpm/php.ini

# restart php
sudo systemctl restart php7.0-fpm
sudo systemctl enable php7.0-fpm

Install icingaweb2 icingacli apache2

sudo apt-get install -y icingaweb2 icingacli
sudo apt-get install -y apache2
sudo systemctl restart apache2
sudo systemctl enable apache2

sudo groupadd -r icingaweb2
sudo usermod -a -G icingaweb2 www-data
sudo icingacli setup config directory --group icingaweb2
sudo systemctl restart icinga2 mysql apache2 php7.0-fpm

Install web2

1. create token
sudo icingacli setup token create

2. open web
http://10.0.0.100/icingaweb2/setup

paster token and next

3. choose all and next

4. next

5. Database next

6.
mysql -uroot -p$DB_PASSWORD -e "CREATE DATABASE icinga2web;"
mysql -uroot -p$DB_PASSWORD -e "GRANT all ON icinga2web.* TO 'icinga2web'@'%' IDENTIFIED BY 'icinga2web';"

Database Name: icinga2web
Username : icinga2web
Password :icinga2web

next

7. Backend Name
icingaweb2 
next

8. set login admin user
user: admin 
pwd:admin 
Repeat password:admin

9. next

10.next

11.next

12. next
13.
Database Name  icinga
Username  icinga
Password    $ICINGA_PASSWORD
cat ~/.bashrc | grep ICINGA

# install Icinga 2 API
sudo vim /etc/hosts
10.0.0.100 test.icinga.com

sudo icinga2 api setup --cn test.icinga.com
sudo systemctl restart icinga2

sudo cat /etc/icinga2/conf.d/api-users.conf

object ApiUser "root" {
  password = "7c0b49534daa460b"

API Username: root
API Password : 7c0b49534daa460b

host:  localhost
or
host:   test.icinga.com

next

14. next
15. finish
16. login to icinga web2  user: admin pass: admin
1 Like

Hello there!
First of all, thank you for the nice step-by-step the installation of an Icinga setup :slight_smile:

I was wondering whether you have any questions surrounding it, or if not, then I would move this topic to the how-to category - and merge your other topics on the master setup and module installation into this one.

Cheers,
Feu

thank you very much , i no problem

set master

sudo icinga2 feature enable command
sudo systemctl restart icinga2
sudo ls -l /var/run/icinga2/cmd/icinga2.cmd
sudo icinga2 node setup --cn test.icinga.com --master
sudo systemctl restart icinga2
sudo cat /etc/icinga2/constants.conf | egrep -i "ZoneName|TicketSalt"
1 Like

install ipl module

git clone https://github.com/Icinga/icingaweb2-module-ipl.git ipl
cd ipl
git checkout stable/0.5.0
cd && sudo mv ipl /usr/share/icingaweb2/modules/
sudo icingacli module enable ipl

install incubator

git clone https://github.com/Icinga/icingaweb2-module-incubator.git incubator
cd incubator
git checkout stable/0.5.0
cd && sudo mv incubator /usr/share/icingaweb2/modules/
sudo icingacli module enable incubator

install reactbundle

git clone https://github.com/Icinga/icingaweb2-module-reactbundle.git reactbundle
cd reactbundle
git checkout stable/0.7.0
cd && sudo mv reactbundle /usr/share/icingaweb2/modules/
sudo icingacli module enable reactbundle

restart icinga2

sudo systemctl restart icinga2

install director

mysql -uroot -p$DB_PASSWORD -e "create database director character set 'utf8';"
mysql -uroot -p$DB_PASSWORD -e "create user 'director'@'%' identified by 'director';"
mysql -uroot -p$DB_PASSWORD -e "grant all on director.* to 'director'@'%';"

sudo tee -a /etc/icingaweb2/resources.ini <<'EOF'

[icinga_director]
type = "db"
db = "mysql"
host = "localhost"
port = ""
dbname = "director"
username = "director"
password = "director"
charset = "utf8"
use_ssl = "0"
EOF

sudo mkdir -p /etc/icingaweb2/modules/director
sudo chmod -R 770 /etc/icingaweb2/modules/director

sudo tee /etc/icingaweb2/modules/director/config.ini <<'EOF'
[db]
resource = "icinga_director"
EOF

sudo chown -R www-data:icingaweb2 /etc/icingaweb2
sudo chmod 660 /etc/icingaweb2/modules/director/config.ini

sudo cat /etc/icinga2/conf.d/api-users.conf

sudo tee /etc/icingaweb2/modules/director/kickstart.ini <<'EOF'
[config]
endpoint = test.icinga.com
; host = 127.0.0.1
username = root
password = 508ff832850b1de3
EOF

sudo chown -R www-data:icingaweb2 /etc/icingaweb2
sudo chmod 660 /etc/icingaweb2/modules/director/kickstart.ini
sudo systemctl restart icinga2

wget https://github.com/Icinga/icingaweb2-module-director/archive/v1.7.2.tar.gz -O director.tar.gz
tar xf director.tar.gz
sudo mv icingaweb2-module-director-1.7.2 /usr/share/icingaweb2/modules/director
sudo icingacli module enable director
sudo icingacli module list
sudo systemctl restart icinga2

# http://10.0.0.100/icingaweb2/setup
# choose you database (icinga_director)


sudo icingacli director migration pending --verbose
sudo icingacli director migration run
sudo icingacli director kickstart required --verbose
sudo icingacli director kickstart run
sudo icingacli director config deploy
sudo systemctl restart icinga2

sudo useradd -r -g icingaweb2 -d /var/lib/icingadirector -s /bin/false icingadirector
sudo install -d -o icingadirector -g icingaweb2 -m 0750 /var/lib/icingadirector
sudo cp /usr/share/icingaweb2/modules/director/contrib/systemd/icinga-director.service /etc/systemd/system
sudo systemctl daemon-reload
sudo systemctl enable icinga-director.service
sudo systemctl start icinga-director.service
sudo systemctl status icinga-director.service

Hello again @jqrun :slight_smile:
I merged the topics together earlier today.

I would like to ask why you wrote that guide :slight_smile:
Did you feel like anything was missing in the official Installation Documentation?
Did you need any help at some point?

I also noticed, that you installed an EOL version of PHP in your guide, was there any reason for this? As it is not exactly best practice :slight_smile:

:grinning:icinga2 use nice, help more use

Create SSL

sudo mkdir -p /data/cert
sudo chown -R $USER.$USER /data/cert
mv create_self-signed-cert.sh /data/cert
pushd /data/cert/ >/dev/null

domain_name=test.icinga.com
domain_ip="10.0.0.100"

bash create_self-signed-cert.sh --ssl-domain=${domain_name} \
--ssl-trusted-ip=${domain_ip} --ssl-size=4096 --ssl-date=3650

popd >/dev/null

apache2 enable ssl

sudo ln -snf /etc/apache2/sites-available/default-ssl.conf /etc/apache2/sites-enabled/000-default-ssl.conf

ssl conf

sudo tee /etc/apache2/sites-available/default-ssl.conf <<'EOF'
<IfModule mod_ssl.c>
  <VirtualHost _default_:443>
    ServerAdmin test@foxmail.com
    DocumentRoot /var/www/html
    ServerName test.icinga.com
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
    SSLEngine on
    SSLCertificateFile /data/cert/test.icinga.com.crt
    SSLCertificateKeyFile /data/cert/test.icinga.com.key
    #SSLCertificateChainFile /etc/ssl/certs/ca.crt
    <FilesMatch "\.(cgi|shtml|phtml|php)$">
        SSLOptions +StdEnvVars
    </FilesMatch>
    <Directory /usr/lib/cgi-bin>
        SSLOptions +StdEnvVars
    </Directory>
    </VirtualHost>
</IfModule>
EOF

load ssl module

sudo a2enmod ssl
sudo service apache2 restart

Rewrite

sudo tee /etc/apache2/sites-available/000-default.conf <<'EOF'
<VirtualHost *:80>
    RewriteEngine on
    RewriteCond %{HTTPS} !=on
    RewriteRule ^(.*) https://%{SERVER_NAME}$1 [L,R]
    ServerAdmin test@foxmail.com
    DocumentRoot /var/www/html
    ServerName test.icinga.com
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
EOF

# Restart apache2
sudo a2enmod rewrite
sudo service apache2 restart

5. Rewrite url

Rewrite Url icingaweb2

# old test.icinga.com/icingaweb2
# new test.icinga.com

sudo tee /etc/apache2/sites-available/default-ssl.conf <<'EOF'
<IfModule mod_ssl.c>
  <VirtualHost _default_:443>
    ServerAdmin test@foxmail.com
    DocumentRoot /var/www/html
    RedirectMatch ^/$ /icingaweb2/
    ServerName test.icinga.com
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
    SSLEngine on
    SSLCertificateFile /data/cert/test.icinga.com.crt
    SSLCertificateKeyFile /data/cert/test.icinga.com.key
    #SSLCertificateChainFile /etc/ssl/certs/ca.crt
    <FilesMatch "\.(cgi|shtml|phtml|php)$">
        SSLOptions +StdEnvVars
    </FilesMatch>
    <Directory /usr/lib/cgi-bin>
        SSLOptions +StdEnvVars
    </Directory>
    </VirtualHost>
</IfModule>
EOF

sudo tee /etc/apache2/sites-available/000-default.conf <<'EOF'
<VirtualHost *:80>
    RewriteEngine on
    RewriteCond   %{HTTPS} !=on
    RewriteRule   ^(.*)  https://%{SERVER_NAME}$1 [L,R]
    ServerAdmin test@foxmail.com
    DocumentRoot /var/www/html
    RedirectMatch ^/$ /icingaweb2/
    ServerName test.icinga.com
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
EOF

sudo service apache2 restart

6. install s-nail

sudo apt-get install -y s-nail

# configure email
# for 465 port
sudo tee -a /etc/s-nail.rc <<EOF
# email
set smtp="smtps://smtp.xxx.com:465"
set from="xxx@xxx.com"
set smtp-auth=login
set smtp-auth-user="xxx@xxx.com"
set smtp-auth-password="xxx"
set ssl-verify=ignore
EOF

# test
echo -e "$HOSTNAME xxx" | /usr/bin/s-nail -s "[PROBLEM] $HOSTNAME xxx [PROBLEM]" xxx@qq.com

# modify email user
sudo cat /etc/icinga2/conf.d/users.conf
sudo sed -i '/email/s#.*#  email = "xxx@xxx.com"#g' /etc/icinga2/conf.d/users.conf

sudo systemctl restart icinga2

7. add TimePeriods

sudo icingacli director timeperiod create 7x24 \
    --json '{ "display_name": "7x24","ranges": { "friday": "00:00-24:00","monday": "00:00-24:00", "saturday": "00:00-24:00","sunday": "00:00-24:00","thursday": "00:00-24:00","tuesday": "00:00-24:00","wednesday": "00:00-24:00" } }'

sudo icingacli director config deploy

add User Templates

sudo icingacli director user --object_type template create email_template \
    --period 7x24 \
    --states Down \
    --states Up \
    --states Critical \
    --types Acknowledgement \
    --types Custom \
    --types Problem \
    --types Recovery \
    --enable_notifications y

sudo icingacli director config deploy

Add Users

sudo icingacli director user create xxx \
    --imports email_template \
    --email xxx@xxx.com

sudo icingacli director config deploy

add Notification Templates

sudo icingacli director notification --object_type template create email_service \
    --command mail-service-notification \
    --notification_interval 86400

sudo icingacli director notification --object_type template create email_host \
    --command mail-host-notification \
    --notification_interval 86400

sudo icingacli director config deploy

Add new Icinga ServiceSet

sudo icingacli director serviceset --object_type template create general_service \
    --description general_service

sudo icingacli director config deploy

Add your Host Templates

sudo icingacli director host --object_type template create add_hosts \
    --check_command hostalive \
    --has_agent y \
    --master_should_connect y \
    --accept_config y

sudo icingacli director config deploy

8. mail-host-notification.sh

#!/bin/sh
# Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+
# Except of function urlencode which is Copyright (C) by Brian White (brian@aljex.com) used under MIT license

PROG="`basename $0`"
ICINGA2HOST="`hostname`"
MAILBIN="/usr/bin/s-nail"

if [ -z "`which $MAILBIN`" ] ; then
  echo "$MAILBIN not found in \$PATH. Consider installing it."
  exit 1
fi

## Function helpers
Usage() {
cat << EOF

Required parameters:
  -d LONGDATETIME (\$icinga.long_date_time\$)
  -l HOSTNAME (\$host.name\$)
  -n HOSTDISPLAYNAME (\$host.display_name\$)
  -o HOSTOUTPUT (\$host.output\$)
  -r USEREMAIL (\$user.email\$)
  -s HOSTSTATE (\$host.state\$)
  -t NOTIFICATIONTYPE (\$notification.type\$)

Optional parameters:
  -4 HOSTADDRESS (\$address\$)
  -6 HOSTADDRESS6 (\$address6\$)
  -b NOTIFICATIONAUTHORNAME (\$notification.author\$)
  -c NOTIFICATIONCOMMENT (\$notification.comment\$)
  -i ICINGAWEB2URL (\$notification_icingaweb2url\$, Default: unset)
  -f MAILFROM (\$notification_mailfrom\$, requires GNU mailutils (Debian/Ubuntu) or mailx (RHEL/SUSE))
  -v (\$notification_sendtosyslog\$, Default: false)

EOF
}

Help() {
  Usage;
  exit 0;
}

Error() {
  if [ "$1" ]; then
    echo $1
  fi
  Usage;
  exit 1;
}

urlencode() {
  local LANG=C i=0 c e s="$1"

  while [ $i -lt ${#1} ]; do
    [ "$i" -eq 0 ] || s="${s#?}"
    c=${s%"${s#?}"}
    [ -z "${c#[[:alnum:].~_-]}" ] || c=$(printf '%%%02X' "'$c")
    e="${e}${c}"
    i=$((i + 1))
  done
  echo "$e"
}

## Main
while getopts 4:6::b:c:d:f:hi:l:n:o:r:s:t:v: opt
do
  case "$opt" in
    4) HOSTADDRESS=$OPTARG ;;
    6) HOSTADDRESS6=$OPTARG ;;
    b) NOTIFICATIONAUTHORNAME=$OPTARG ;;
    c) NOTIFICATIONCOMMENT=$OPTARG ;;
    d) LONGDATETIME=$OPTARG ;; # required
    f) MAILFROM=$OPTARG ;;
    h) Help ;;
    i) ICINGAWEB2URL=$OPTARG ;;
    l) HOSTNAME=$OPTARG ;; # required
    n) HOSTDISPLAYNAME=$OPTARG ;; # required
    o) HOSTOUTPUT=$OPTARG ;; # required
    r) USEREMAIL=$OPTARG ;; # required
    s) HOSTSTATE=$OPTARG ;; # required
    t) NOTIFICATIONTYPE=$OPTARG ;; # required
    v) VERBOSE=$OPTARG ;;
   \?) echo "ERROR: Invalid option -$OPTARG" >&2
       Error ;;
    :) echo "Missing option argument for -$OPTARG" >&2
       Error ;;
    *) echo "Unimplemented option: -$OPTARG" >&2
       Error ;;
  esac
done

shift $((OPTIND - 1))

## Keep formatting in sync with mail-service-notification.sh
for P in LONGDATETIME HOSTNAME HOSTDISPLAYNAME HOSTOUTPUT HOSTSTATE USEREMAIL NOTIFICATIONTYPE ; do
	eval "PAR=\$${P}"

	if [ ! "$PAR" ] ; then
		Error "Required parameter '$P' is missing."
	fi
done

## Build the message's subject
SUBJECT="[$NOTIFICATIONTYPE] Host $HOSTDISPLAYNAME is $HOSTSTATE!"

## Build the notification message
NOTIFICATION_MESSAGE=`cat << EOF
***** Host Monitoring on $ICINGA2HOST *****

$HOSTDISPLAYNAME is $HOSTSTATE!

Info:    $HOSTOUTPUT

When:    $LONGDATETIME
Host:    $HOSTNAME
EOF
`

## Check whether IPv4 was specified.
if [ -n "$HOSTADDRESS" ] ; then
  NOTIFICATION_MESSAGE="$NOTIFICATION_MESSAGE
IPv4:	 $HOSTADDRESS"
fi

## Check whether IPv6 was specified.
if [ -n "$HOSTADDRESS6" ] ; then
  NOTIFICATION_MESSAGE="$NOTIFICATION_MESSAGE
IPv6:	 $HOSTADDRESS6"
fi

## Check whether author and comment was specified.
if [ -n "$NOTIFICATIONCOMMENT" ] ; then
  NOTIFICATION_MESSAGE="$NOTIFICATION_MESSAGE

Comment by $NOTIFICATIONAUTHORNAME:
  $NOTIFICATIONCOMMENT"
fi

## Check whether Icinga Web 2 URL was specified.
if [ -n "$ICINGAWEB2URL" ] ; then
  NOTIFICATION_MESSAGE="$NOTIFICATION_MESSAGE

$ICINGAWEB2URL/monitoring/host/show?host=$(urlencode "$HOSTNAME")"
fi

## Check whether verbose mode was enabled and log to syslog.
if [ "$VERBOSE" == "true" ] ; then
  logger "$PROG sends $SUBJECT => $USEREMAIL"
fi

## Modify this for your own needs!
/usr/bin/printf "%b" "$NOTIFICATION_MESSAGE" | tr -d '\015' | $MAILBIN -s "From: $MAILFROM" -s "$SUBJECT" $USEREMAIL

9. mail-service-notification.sh

#!/bin/sh
# Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+
# Except of function urlencode which is Copyright (C) by Brian White (brian@aljex.com) used under MIT license

PROG="`basename $0`"
ICINGA2HOST="`hostname`"
MAILBIN="/usr/bin/s-nail"

if [ -z "`which $MAILBIN`" ] ; then
  echo "$MAILBIN not found in \$PATH. Consider installing it."
  exit 1
fi

## Function helpers
Usage() {
cat << EOF

Required parameters:
  -d LONGDATETIME (\$icinga.long_date_time\$)
  -e SERVICENAME (\$service.name\$)
  -l HOSTNAME (\$host.name\$)
  -n HOSTDISPLAYNAME (\$host.display_name\$)
  -o SERVICEOUTPUT (\$service.output\$)
  -r USEREMAIL (\$user.email\$)
  -s SERVICESTATE (\$service.state\$)
  -t NOTIFICATIONTYPE (\$notification.type\$)
  -u SERVICEDISPLAYNAME (\$service.display_name\$)

Optional parameters:
  -4 HOSTADDRESS (\$address\$)
  -6 HOSTADDRESS6 (\$address6\$)
  -b NOTIFICATIONAUTHORNAME (\$notification.author\$)
  -c NOTIFICATIONCOMMENT (\$notification.comment\$)
  -i ICINGAWEB2URL (\$notification_icingaweb2url\$, Default: unset)
  -f MAILFROM (\$notification_mailfrom\$, requires GNU mailutils (Debian/Ubuntu) or mailx (RHEL/SUSE))
  -v (\$notification_sendtosyslog\$, Default: false)

EOF
}

Help() {
  Usage;
  exit 0;
}

Error() {
  if [ "$1" ]; then
    echo $1
  fi
  Usage;
  exit 1;
}

urlencode() {
  local LANG=C i=0 c e s="$1"

  while [ $i -lt ${#1} ]; do
    [ "$i" -eq 0 ] || s="${s#?}"
    c=${s%"${s#?}"}
    [ -z "${c#[[:alnum:].~_-]}" ] || c=$(printf '%%%02X' "'$c")
    e="${e}${c}"
    i=$((i + 1))
  done
  echo "$e"
}

## Main
while getopts 4:6:b:c:d:e:f:hi:l:n:o:r:s:t:u:v: opt
do
  case "$opt" in
    4) HOSTADDRESS=$OPTARG ;;
    6) HOSTADDRESS6=$OPTARG ;;
    b) NOTIFICATIONAUTHORNAME=$OPTARG ;;
    c) NOTIFICATIONCOMMENT=$OPTARG ;;
    d) LONGDATETIME=$OPTARG ;; # required
    e) SERVICENAME=$OPTARG ;; # required
    f) MAILFROM=$OPTARG ;;
    h) Usage ;;
    i) ICINGAWEB2URL=$OPTARG ;;
    l) HOSTNAME=$OPTARG ;; # required
    n) HOSTDISPLAYNAME=$OPTARG ;; # required
    o) SERVICEOUTPUT=$OPTARG ;; # required
    r) USEREMAIL=$OPTARG ;; # required
    s) SERVICESTATE=$OPTARG ;; # required
    t) NOTIFICATIONTYPE=$OPTARG ;; # required
    u) SERVICEDISPLAYNAME=$OPTARG ;; # required
    v) VERBOSE=$OPTARG ;;
   \?) echo "ERROR: Invalid option -$OPTARG" >&2
       Usage ;;
    :) echo "Missing option argument for -$OPTARG" >&2
       Usage ;;
    *) echo "Unimplemented option: -$OPTARG" >&2
       Usage ;;
  esac
done

shift $((OPTIND - 1))

## Keep formatting in sync with mail-host-notification.sh
for P in LONGDATETIME HOSTNAME HOSTDISPLAYNAME SERVICENAME SERVICEDISPLAYNAME SERVICEOUTPUT SERVICESTATE USEREMAIL NOTIFICATIONTYPE ; do
        eval "PAR=\$${P}"

        if [ ! "$PAR" ] ; then
                Error "Required parameter '$P' is missing."
        fi
done

## Build the message's subject
SUBJECT="[$NOTIFICATIONTYPE] $SERVICEDISPLAYNAME on $HOSTDISPLAYNAME is $SERVICESTATE!"

## Build the notification message
NOTIFICATION_MESSAGE=`cat << EOF
***** Service Monitoring on $ICINGA2HOST *****

$SERVICEDISPLAYNAME on $HOSTDISPLAYNAME is $SERVICESTATE!

Info:    $SERVICEOUTPUT

When:    $LONGDATETIME
Service: $SERVICENAME
Host:    $HOSTNAME
EOF
`

## Check whether IPv4 was specified.
if [ -n "$HOSTADDRESS" ] ; then
  NOTIFICATION_MESSAGE="$NOTIFICATION_MESSAGE
IPv4:    $HOSTADDRESS"
fi

## Check whether IPv6 was specified.
if [ -n "$HOSTADDRESS6" ] ; then
  NOTIFICATION_MESSAGE="$NOTIFICATION_MESSAGE
IPv6:    $HOSTADDRESS6"
fi

## Check whether author and comment was specified.
if [ -n "$NOTIFICATIONCOMMENT" ] ; then
  NOTIFICATION_MESSAGE="$NOTIFICATION_MESSAGE

Comment by $NOTIFICATIONAUTHORNAME:
  $NOTIFICATIONCOMMENT"
fi

## Check whether Icinga Web 2 URL was specified.
if [ -n "$ICINGAWEB2URL" ] ; then
  NOTIFICATION_MESSAGE="$NOTIFICATION_MESSAGE

$ICINGAWEB2URL/monitoring/service/show?host=$(urlencode "$HOSTNAME")&service=$(urlencode "$SERVICENAME")"
fi

## Check whether verbose mode was enabled and log to syslog.
if [ "$VERBOSE" == "true" ] ; then
  logger "$PROG sends $SUBJECT => $USEREMAIL"
fi

## Modify this for your own needs!
/usr/bin/printf "%b" "$NOTIFICATION_MESSAGE" | tr -d '\015' | $MAILBIN -s "From: $MAILFROM" -s "$SUBJECT" $USEREMAIL

10 . Add Service Templates

sudo icingacli director service --object_type template create check_disk \
    --check_command disk \
    --use_agent y

sudo icingacli director service --object_type template create check_mem \
    --check_command mem \
    --use_agent y

sudo icingacli director service --object_type template create check_swap \
    --check_command swap \
    --use_agent y

sudo icingacli director service --object_type template create check_load \
    --check_command load \
    --use_agent y

sudo icingacli director service --object_type template create check_iostat \
    --check_command iostat \
    --use_agent y

sudo icingacli director service --object_type template create check_procs \
    --check_command procs \
    --use_agent y

sudo icingacli director service --object_type template create check_ntp_time \
    --check_command ntp_time \
    --use_agent y

sudo icingacli director service --object_type template create check_users \
    --check_command users \
    --use_agent y

sudo icingacli director config deploy
Template: general_service
Services in this set: general_service
manully Add service
![1233|689x169](upload://7zqkSTLOuOms05tXG1kNYLyupMC.png) 

sudo icingacli director config deploy

11.install icinga client

sudo apt-get update
sudo apt-get -y install apt-transport-https wget gnupg lsb-core

wget https://packages.icinga.com/icinga.key
sudo apt-key add icinga.key

sudo tee /etc/apt/sources.list.d/$(lsb_release -sc)-icinga.list <<EOF
deb https://packages.icinga.com/ubuntu icinga-$(lsb_release -sc) main
deb-src https://packages.icinga.com/ubuntu icinga-$(lsb_release -sc) main
EOF

sudo apt-get update
sudo apt-get install -y icinga2
sudo apt-get install -y monitoring-plugins

master add clinet node scripts

...

node scripts

...

I found this guide incredibly useful and this is how the documentation should be in my opinion. Let me explain.

I’m not new to the world of installing software under Linux and the documentation for Icinga is extensive and therein lays the problem. I’ve used Nagios before and built the configs by hand.

I went to the installation section and every distro is listed in the instructions, my first attempt failed as I must have missed a step as I scrolled through sections that were of no interest for the Distro I was using, I completely failed to get a working system. If I hadn’t had found this guide I would have given up at that point, with a the aid of this guide I got a working system. It was still a little difficult as I was using a different version of Ubuntu - The PHP instructions for example didn’t work on my version.

My system works but can only monitor itself, external agents are similarly difficult to follow on how to install, I shall however persevere - no errors in the agent but nothing in the dashboard :frowning:

For me it would have been simpler if the installation was sectioned into the different Distros and if there was a preferred Distro for Icinga - There may be, I couldn’t find it amongst all the docs.

2 Likes

Thank you for your feedback!

We are currently working on a “getting started” section, that aims to simplify the installation process, also focusing on a single OS with a MySQL database and generally limiting the “branches” of having a thousand things to choose from.

I’m glad this guide helped you achieve your goal and I hope we’ll be able to provide a good starting point ourselves as well in the future :slight_smile:

1 Like