Nagios on Raspberry PI (with nagiosQL)

Download the latest NOOBS Raspberry PI installer from: https://www.raspberrypi.org/downloads/

Download the ZIP file
###fdisk /dev/sdg1

Welcome to fdisk (util-linux 2.25.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): p
Disk /dev/sdg1: 14,9 GiB, 15927345152 bytes, 31108096 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x00000000

Command (m for help): d
No partition is defined yet!
Could not delete partition 1

Command (m for help): n
Partition type
p primary (0 primary, 0 extended, 4 free)
e extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1):
First sector (2048-31108095, default 2048):
Last sector, +sectors or +size{K,M,G,T,P} (2048-31108095, default 31108095):

Created a new partition 1 of type ‘Linux’ and of size 14,9 GiB.

Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): L

0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris
1 FAT12 27 Hidden NTFS Win 82 Linux swap / So c1 DRDOS/sec (FAT-
2 XENIX root 39 Plan 9 83 Linux c4 DRDOS/sec (FAT-
3 XENIX usr 3c PartitionMagic 84 OS/2 hidden C: c6 DRDOS/sec (FAT-
4 FAT16 <32M 40 Venix 80286 85 Linux extended c7 Syrinx
5 Extended 41 PPC PReP Boot 86 NTFS volume set da Non-FS data
6 FAT16 42 SFS 87 NTFS volume set db CP/M / CTOS / .
7 HPFS/NTFS/exFAT 4d QNX4.x 88 Linux plaintext de Dell Utility
8 AIX 4e QNX4.x 2nd part 8e Linux LVM df BootIt
9 AIX bootable 4f QNX4.x 3rd part 93 Amoeba e1 DOS access
a OS/2 Boot Manag 50 OnTrack DM 94 Amoeba BBT e3 DOS R/O
b W95 FAT32 51 OnTrack DM6 Aux 9f BSD/OS e4 SpeedStor
c W95 FAT32 (LBA) 52 CP/M a0 IBM Thinkpad hi eb BeOS fs
e W95 FAT16 (LBA) 53 OnTrack DM6 Aux a5 FreeBSD ee GPT
f W95 Ext’d (LBA) 54 OnTrackDM6 a6 OpenBSD ef EFI (FAT-12/16/
10 OPUS 55 EZ-Drive a7 NeXTSTEP f0 Linux/PA-RISC b
11 Hidden FAT12 56 Golden Bow a8 Darwin UFS f1 SpeedStor
12 Compaq diagnost 5c Priam Edisk a9 NetBSD f4 SpeedStor
14 Hidden FAT16 <3 61 SpeedStor ab Darwin boot f2 DOS secondary
16 Hidden FAT16 63 GNU HURD or Sys af HFS / HFS+ fb VMware VMFS
17 Hidden HPFS/NTF 64 Novell Netware b7 BSDI fs fc VMware VMKCORE
18 AST SmartSleep 65 Novell Netware b8 BSDI swap fd Linux raid auto
1b Hidden W95 FAT3 70 DiskSecure Mult bb Boot Wizard hid fe LANstep
1c Hidden W95 FAT3 75 PC/IX be Solaris boot ff BBT
1e Hidden W95 FAT1 80 Old Minix
Hex code (type L to list all codes): b
If you have created or modified any DOS 6.x partitions, please see the fdisk documentation for additional information.
Changed type of partition ‘Linux’ to ‘W95 FAT32’.

Command (m for help): p
Disk /dev/sdg1: 14,9 GiB, 15927345152 bytes, 31108096 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x00000000

Device Boot Start End Sectors Size Id Type
/dev/sdg1p1 2048 31108095 31106048 14,9G b W95 FAT32
Command (m for help): a
Selected partition 1
The bootable flag on partition 1 is enabled now.

Command (m for help): p
Disk /dev/sdg1: 14,9 GiB, 15927345152 bytes, 31108096 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x00000000

Device Boot Start End Sectors Size Id Type
/dev/sdg1p1 * 2048 31108095 31106048 14,9G b W95 FAT32
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Re-reading the partition table failed.: Invalid argument

The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8).

####mkfs.vfat /dev/sdg1
mkfs.fat 3.0.27 (2014-11-12)
mkfs.vfat: /dev/sdg1 contains a mounted filesystem.
####umount /dev/sdg1
###mkfs.vfat /dev/sdg1
mkfs.fat 3.0.27 (2014-11-12)
###mkdir /mnt/
lvm-rhg/ sdd1/ sdf1/ usb/ www/
###mkdir /mnt/sdg1
###mount /dev/sdg1 /mnt/sdg1
###cd /mnt/sdg1
###unzip /home/rob/Downloads/NOOBS_v1_5_0.zip
Archive: /home/rob/Downloads/NOOBS_v1_5_0.zip
inflating: bcm2708-rpi-b.dtb
inflating: bcm2708-rpi-b-plus.dtb
inflating: bcm2709-rpi-2-b.dtb
inflating: bootcode.bin
inflating: BUILD-DATA
creating: defaults/
creating: defaults/slides/
inflating: defaults/slides/A.png
inflating: INSTRUCTIONS-README.txt
creating: os/
creating: os/Raspbian/
inflating: os/Raspbian/partitions.json
creating: os/Raspbian/slides_vga/
inflating: os/Raspbian/slides_vga/B.png
inflating: os/Raspbian/slides_vga/F.png
inflating: os/Raspbian/slides_vga/D.png
inflating: os/Raspbian/slides_vga/E.png
inflating: os/Raspbian/slides_vga/G.png
inflating: os/Raspbian/slides_vga/C.png
inflating: os/Raspbian/slides_vga/A.png
extracting: os/Raspbian/Raspbian.png
inflating: os/Raspbian/root.tar.xz
inflating: os/Raspbian/partition_setup.sh
inflating: os/Raspbian/os.json
inflating: os/Raspbian/boot.tar.xz
creating: overlays/
inflating: overlays/hy28a-overlay.dtb
inflating: overlays/pwm-overlay.dtb
inflating: overlays/mcp2515-can1-overlay.dtb
inflating: overlays/spi-bcm2835-overlay.dtb
inflating: overlays/i2c-rtc-overlay.dtb
inflating: overlays/hifiberry-dac-overlay.dtb
inflating: overlays/iqaudio-dac-overlay.dtb
inflating: overlays/uart1-overlay.dtb
inflating: overlays/pitft28-capacitive-overlay.dtb
inflating: overlays/rpi-display-overlay.dtb
inflating: overlays/hifiberry-digi-overlay.dtb
inflating: overlays/pps-gpio-overlay.dtb
inflating: overlays/iqaudio-dacplus-overlay.dtb
inflating: overlays/spi-dma-overlay.dtb
inflating: overlays/rpi-backlight-overlay.dtb
inflating: overlays/smi-dev-overlay.dtb
inflating: overlays/pitft28-resistive-overlay.dtb
inflating: overlays/raspidac3-overlay.dtb
inflating: overlays/sdhost-overlay.dtb
inflating: overlays/rpi-dac-overlay.dtb
inflating: overlays/at86rf233-overlay.dtb
inflating: overlays/i2s-mmap-overlay.dtb
inflating: overlays/hy28b-overlay.dtb
inflating: overlays/hifiberry-dacplus-overlay.dtb
inflating: overlays/gpio-poweroff-overlay.dtb
inflating: overlays/mz61581-overlay.dtb
inflating: overlays/mcp2515-can0-overlay.dtb
inflating: overlays/spi-bcm2708-overlay.dtb
inflating: overlays/rpi-ft5406-overlay.dtb
inflating: overlays/w1-gpio-overlay.dtb
inflating: overlays/sdio-overlay.dtb
inflating: overlays/i2c-gpio-overlay.dtb
inflating: overlays/piscreen2r-overlay.dtb
inflating: overlays/rpi-sense-overlay.dtb
inflating: overlays/lirc-rpi-overlay.dtb
inflating: overlays/smi-nand-overlay.dtb
inflating: overlays/rpi-proto-overlay.dtb
inflating: overlays/dht11-overlay.dtb
inflating: overlays/hifiberry-amp-overlay.dtb
inflating: overlays/enc28j60-overlay.dtb
inflating: overlays/pwm-2chan-overlay.dtb
inflating: overlays/piscreen-overlay.dtb
inflating: overlays/bmp085_i2c-sensor-overlay.dtb
inflating: overlays/tinylcd35-overlay.dtb
inflating: overlays/vga666-overlay.dtb
inflating: overlays/mmc-overlay.dtb
inflating: overlays/ads7846-overlay.dtb
inflating: overlays/w1-gpio-pullup-overlay.dtb
inflating: overlays/smi-overlay.dtb
inflating: recovery7.img
inflating: recovery.cmdline
inflating: recovery.elf
extracting: RECOVERY_FILES_DO_NOT_EDIT
inflating: recovery.img
inflating: recovery.rfs
inflating: riscos-boot.bin
###cd ..
###umount sdg1/

Boot from the SD card and choose to install Rasbian.

Check IP address and login using ssh

###sudo passwd root
###sudo su –

###raspi-config

Change the default boot to be console based
In advanced Update tool to the latest version
Exit the tool

###reboot

Login again after the reboot.
###sudo su –
###apt-get update

###apt-get install apache2
###apt-get install php5
###apt-get install php5-cgi
###apt-get install mysql-server
###apt-get install php-pear php5-mysql
###cd /etc/apache2/mods-enabled
###ln -s ../mods-available/cgi.load cgi.load
###cd /etc/apache2/conf-enabled
###ln -s ../conf-available/nagios.conf nagios.conf
###ln -s ../conf-available/php5-cgi.conf php5-cgi.conf
###/etc/init.d/apache2 restart
###htpasswd -c -m /usr/local/nagios/etc/htpasswd.users nagiosadmin
New password:
Re-type new password:
Adding password for user nagiosadmin
###useradd -d /usr/local/nagios -M -U nagios

###cd

###mkdir nagios
###cd nagios
###wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.1.1.tar.gz
–2015-12-09 23:23:44– https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.1.1.tar.gz
Resolving assets.nagios.com (assets.nagios.com)… 72.14.181.71
Connecting to assets.nagios.com (assets.nagios.com)|72.14.181.71|:443… connected.
HTTP request sent, awaiting response… 200 OK
Length: 11206656 (11M) [application/x-gzip]
Saving to: ‘nagios-4.1.1.tar.gz’

nagios-4.1.1.tar.gz 100%[=======================================================================================================================>] 10.69M 892KB/s in 11s

2015-12-09 23:23:56 (1018 KB/s) – ‘nagios-4.1.1.tar.gz’ saved [11206656/11206656]
###tar zxvf nagios-4.1.1.tar.gz

###wget http://www.nagios-plugins.org/download/nagios-plugins-2.1.1.tar.gz
–2015-12-09 23:26:21– http://www.nagios-plugins.org/download/nagios-plugins-2.1.1.tar.gz
Resolving www.nagios-plugins.org (www.nagios-plugins.org)… 72.14.186.43
Connecting to www.nagios-plugins.org (www.nagios-plugins.org)|72.14.186.43|:80… connected.
HTTP request sent, awaiting response… 301 Moved Permanently
Location: http://nagios-plugins.org/download/nagios-plugins-2.1.1.tar.gz [following]
–2015-12-09 23:26:21– http://nagios-plugins.org/download/nagios-plugins-2.1.1.tar.gz
Resolving nagios-plugins.org (nagios-plugins.org)… 72.14.186.43
Reusing existing connection to www.nagios-plugins.org:80.
HTTP request sent, awaiting response… 200 OK
Length: 2677352 (2.6M) [application/x-gzip]
Saving to: ‘nagios-plugins-2.1.1.tar.gz’

nagios-plugins-2.1.1.tar.gz 100%[=======================================================================================================================>] 2.55M 911KB/s in 2.9s

2015-12-09 23:26:24 (911 KB/s) – ‘nagios-plugins-2.1.1.tar.gz’ saved [2677352/2677352]

###tar zxvf nagios-plugins-2.1.1.tar.gz


###cd nagios-4.1.1/
###./configure –with-httpd-conf=/etc/apache2/conf-available/ –with-command-group=nagcmd

Creating sample config files in sample-config/ …
*** Configuration summary for nagios 4.1.1 08-19-2015 ***:

General Options:
————————-
Nagios executable: nagios
Nagios user/group: nagios,nagios
Command user/group: nagios,nagios
Event Broker: yes
Install ${prefix}: /usr/local/nagios
Install ${includedir}: /usr/local/nagios/include/nagios
Lock file: ${prefix}/var/nagios.lock
Check result directory: ${prefix}/var/spool/checkresults
Init directory: /etc/init.d
Apache conf.d directory: /etc/apache2/conf-available/
Mail program: /bin/mail
Host OS: linux-gnu
IOBroker Method: epoll

Web Interface Options:
————————
HTML URL: http://localhost/nagios/
CGI URL: http://localhost/nagios/cgi-bin/
Traceroute (used by WAP): /usr/sbin/traceroute
Review the options above for accuracy. If they look okay,
type ‘make all’ to compile the main program and CGIs.

###make all

*** Compile finished ***

If the main program and CGIs compiled without any errors, you
can continue with installing Nagios as follows (type ‘make’
without any arguments for a list of all possible options):

make install
– This installs the main program, CGIs, and HTML files

make install-init
– This installs the init script in /etc/init.d

make install-commandmode
– This installs and configures permissions on the
directory for holding the external command file

make install-config
– This installs *SAMPLE* config files in /usr/local/nagios/etc
You’ll have to modify these sample files before you can
use Nagios. Read the HTML documentation for more info
on doing this. Pay particular attention to the docs on
object configuration files, as they determine what/how
things get monitored!

make install-webconf
– This installs the Apache config file for the Nagios
web interface

make install-exfoliation
– This installs the Exfoliation theme for the Nagios
web interface

make install-classicui
– This installs the classic theme for the Nagios
web interface
*** Support Notes *******************************************

If you have questions about configuring or running Nagios,
please make sure that you:

– Look at the sample config files
– Read the documentation on the Nagios Library at:
https://library.nagios.com

before you post a question to one of the mailing lists.
Also make sure to include pertinent information that could
help others help you. This might include:

– What version of Nagios you are using
– What version of the plugins you are using
– Relevant snippets from your config files
– Relevant error messages from the Nagios log file

For more information on obtaining support for Nagios, visit:

https://support.nagios.com

*************************************************************

Enjoy.

###make install
###make install-init
###make install-commandmode
###make install-config
###make install-webconf
###make install-classicui
###make install-exfoliation

###cd ../nagios-plugins
###./configure
###make all
###make install

####If the Nagios configure was done with –with-command-group=nagcmd, the next 4 lines should not be necessary####
###groupadd nagcmd
###usermod -G nagcmd nagios
###usermod -G nagcmd www-data
###chown nagios:nagcmd /usr/local/nagios/var/rw
###chown nagios:nagcmd /usr/local/nagios/var/rw/nagios.cmd

Download NagiosQL

###wget http://sourceforge.net/projects/nagiosql/files/nagiosql/NagiosQL%203.2.0/nagiosql_320.tar.gz
–2015-12-10 07:57:54– http://sourceforge.net/projects/nagiosql/files/nagiosql/NagiosQL%203.2.0/nagiosql_320.tar.gz
Resolving sourceforge.net (sourceforge.net)… 216.34.181.60
Connecting to sourceforge.net (sourceforge.net)|216.34.181.60|:80… connected.
HTTP request sent, awaiting response… 302 Found
Location: http://sourceforge.net/projects/nagiosql/files/nagiosql/NagiosQL%203.2.0/nagiosql_320.tar.gz/download [following]
–2015-12-10 07:57:54– http://sourceforge.net/projects/nagiosql/files/nagiosql/NagiosQL%203.2.0/nagiosql_320.tar.gz/download
Connecting to sourceforge.net (sourceforge.net)|216.34.181.60|:80… connected.
HTTP request sent, awaiting response… 302 Found
Location: http://downloads.sourceforge.net/project/nagiosql/nagiosql/NagiosQL%203.2.0/nagiosql_320.tar.gz?r=&ts=1449734275&use_mirror=netcologne [following]
–2015-12-10 07:57:55– http://downloads.sourceforge.net/project/nagiosql/nagiosql/NagiosQL%203.2.0/nagiosql_320.tar.gz?r=&ts=1449734275&use_mirror=netcologne
Resolving downloads.sourceforge.net (downloads.sourceforge.net)… 216.34.181.59
Connecting to downloads.sourceforge.net (downloads.sourceforge.net)|216.34.181.59|:80… connected.
HTTP request sent, awaiting response… 302 Found
Location: http://netcologne.dl.sourceforge.net/project/nagiosql/nagiosql/NagiosQL%203.2.0/nagiosql_320.tar.gz [following]
–2015-12-10 07:57:55– http://netcologne.dl.sourceforge.net/project/nagiosql/nagiosql/NagiosQL%203.2.0/nagiosql_320.tar.gz
Resolving netcologne.dl.sourceforge.net (netcologne.dl.sourceforge.net)… 78.35.24.46, 2001:4dd0:1234:6::5f
Connecting to netcologne.dl.sourceforge.net (netcologne.dl.sourceforge.net)|78.35.24.46|:80… connected.
HTTP request sent, awaiting response… 200 OK
Length: 1417124 (1.4M) [application/x-gzip]
Saving to: ‘nagiosql_320.tar.gz’

nagiosql_320.tar.gz 100%[============================================================>] 1.35M 4.34MB/s in 0.3s

2015-12-10 07:57:55 (4.34 MB/s) – ‘nagiosql_320.tar.gz’ saved [1417124/1417124]
###tar zxvf nagiosql_320.tar.gz
###mv nagiosql32/ /var/www/html/
###/etc/init.d/mysql restart
Add “Europe/Amsterdam” as timezone in /etc/php5/apache2/php.ini

###cd /var/www/html/nagiosql32
###chmod g+w config/
###chgrp www-data config/
###cd /usr/local/nagios/etc
###mkdir nagiosql
###chgrp nagcmd nagiosql
###chmod g+w nagiosql
###chown nagios nagiosql
###chgrp nagcmd nagios.cfg
###chgrp nagcmd cgi.cfg
###chgrp nagcmd resource.cfg
###chgrp nagcmd /usr/local/nagios/bin/nagios
###chgrp -R nagcmd /usr/local/nagios/var/
###chown nagios.www-data /usr/local/nagios/var/rw/nagios.cmd
###chmod u+s `which ping`

Open http://<ip address>/nagiosql32/install/ in a browser
Click INSTALL
Check if everything is OK en click NEXT
Fill in the root password for MySQL
Tick the box create NagiosQL config path
Change the NagiosQL config path to: /usr/local/nagios/etc/nagiosql/
Change the Nagios config path to: /usr/local/nagios/etc/
Click NEXT

###rm -rf /var/www/html/nagiosql/install/

In the Administration link, go to “Config targets”
Change “Nagios command file” to: /usr/local/nagios/var/rw/nagios.cmd
Change “Nagios binary file” to: /usr/local/nagios/bin/nagios
Change “Nagios proces file” to: /usr/local/nagios/var/nagios.lock
Change “Nagios config file” to: /usr/local/nagios/etc/nagios.cfg
Goto Tools => Data import and start with importing commands.cfg
than import timeperiods, then contacts, then templates, then the hosts

In /usr/local/nagios/etc/nagios.cfg change the follwoing:
cfg_file=/usr/local/nagios/etc/nagiosql/commands.cfg
cfg_file=/usr/local/nagios/etc/nagiosql/contactgroups.cfg
cfg_file=/usr/local/nagios/etc/nagiosql/contacts.cfg
cfg_file=/usr/local/nagios/etc/nagiosql/contacttemplates.cfg
cfg_file=/usr/local/nagios/etc/nagiosql/hostdependencies.cfg
cfg_file=/usr/local/nagios/etc/nagiosql/hostescalations.cfg
cfg_file=/usr/local/nagios/etc/nagiosql/hostextinfo.cfg
cfg_file=/usr/local/nagios/etc/nagiosql/hostgroups.cfg
cfg_file=/usr/local/nagios/etc/nagiosql/hosttemplates.cfg
cfg_file=/usr/local/nagios/etc/nagiosql/servicedependencies.cfg
cfg_file=/usr/local/nagios/etc/nagiosql/serviceescalations.cfg
cfg_file=/usr/local/nagios/etc/nagiosql/serviceextinfo.cfg
cfg_file=/usr/local/nagios/etc/nagiosql/servicegroups.cfg
cfg_file=/usr/local/nagios/etc/nagiosql/servicetemplates.cfg
cfg_file=/usr/local/nagios/etc/nagiosql/timeperiods.cfg

cfg_dir=/usr/local/nagios/etc/nagiosql/hosts
cfg_dir=/usr/local/nagios/etc/nagiosql/services
Edit /var/www/html/nagiosql/admin/verify.php
modify line 345 from:
$strCommandString = “[“.mktime().”] RESTART_PROGRAM;”.mktime();
to:
$strCommandString = “[“.mktime().”] RESTART_PROGRAM\n”;