Understanding Nagios Core: Core Component Interactions€¦ · Demo Overview Nagios Core version...

19
Understanding Nagios Core: Core Component Interactions PRESENTED BY: ROBERT CAMPBELL, CHP & CSCS

Transcript of Understanding Nagios Core: Core Component Interactions€¦ · Demo Overview Nagios Core version...

Page 1: Understanding Nagios Core: Core Component Interactions€¦ · Demo Overview Nagios Core version 4.0.8 (most current version as of this presentation) Demo installed on Red Hat Amazon

Understanding Nagios Core:Core Component InteractionsPRESENTED BY:ROBERT CAMPBELL, CHP & CSCS

Page 2: Understanding Nagios Core: Core Component Interactions€¦ · Demo Overview Nagios Core version 4.0.8 (most current version as of this presentation) Demo installed on Red Hat Amazon

Nagios Core OverviewVery customizable monitoring system

Core version is free

• Configuration through CLI, monitoring through web UI

Alerting capability with ability to escalate

Response capability through web UI

Reporting Metrics

• Historical record of outages, events, notifications and alert responses

Scheduled maintenance

Planning

• Can monitor capacity trends to anticipate infrastructure upgrades

Capability can be extended through Nagios Plugins

Page 3: Understanding Nagios Core: Core Component Interactions€¦ · Demo Overview Nagios Core version 4.0.8 (most current version as of this presentation) Demo installed on Red Hat Amazon

Demo Overview

Nagios Core version 4.0.8 (most current version as of this presentation)

Demo installed on Red Hat Amazon AWS system

This demo will focus on Nagios Core components

• Nagios has a very modular design

• Important to understand how each component relates to one another

Will review built in plugins and commands

Will briefly review remote monitoring of local resources for Linux and Windows systems

Page 4: Understanding Nagios Core: Core Component Interactions€¦ · Demo Overview Nagios Core version 4.0.8 (most current version as of this presentation) Demo installed on Red Hat Amazon

Initial SetupPrerequisites

• Make sure you've installed the following packages before continuing.

• Apache

• PHP

• GCC compiler

• GD development libraries

Create Account Information

• Become the root user.

• su –l

• Create a new nagios user account and give it a password.

• /usr/sbin/useradd -m nagios

• passwd Nagios

• Create a new nagcmd group for allowing external commands to be submitted through the web interface. Add both the nagios user and the apache user to the group.

• /usr/sbin/groupadd nagcmd

• /usr/sbin/usermod -a -G nagcmd nagios

• /usr/sbin/usermod -a -G nagcmd apache

Page 5: Understanding Nagios Core: Core Component Interactions€¦ · Demo Overview Nagios Core version 4.0.8 (most current version as of this presentation) Demo installed on Red Hat Amazon

Initial Setup (Cont.)Download Nagios and the Plugins

• Create a directory for storing the downloads.

• mkdir ~/downloads

• cd ~/downloads

• Download the source code tarballs of both Nagios and the Nagios plugins (visit https://www.nagios.org/download/ for links to the latest versions).

• wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-4.0.8.tar.gz

• wget http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-2.0.3.tar.gz

Compile and Install Nagios

• Extract the Nagios source code tarball.

• cd ~/downloads

• tar xzf nagios-4.0.tar.gz

• cd nagios-4.0

• Run the Nagios configure script, passing the name of the group you created earlier like so:

• ./configure --with-command-group=nagcmd

Page 6: Understanding Nagios Core: Core Component Interactions€¦ · Demo Overview Nagios Core version 4.0.8 (most current version as of this presentation) Demo installed on Red Hat Amazon

Initial Setup (Cont.)• Compile the Nagios source code.

• make all

• Install binaries, init script, sample config files and set permissions on the external command directory.

• make install

• make install-init

• make install-config

• make install-commandmode

Configure the Web Interface

• Install the Nagios web config file in the Apache conf.d directory.

• make install-webconf

• Create a nagiosadmin account for logging into the Nagios web interface. Remember the password you assign to this account - you'll need it later.

• htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

• Restart Apache to make the new settings take effect.

• service httpd restart

Page 7: Understanding Nagios Core: Core Component Interactions€¦ · Demo Overview Nagios Core version 4.0.8 (most current version as of this presentation) Demo installed on Red Hat Amazon

Initial Setup (Cont.)Compile and Install the Nagios Plugins

• Extract the Nagios plugins source code tarball.

• cd ~/downloads

• tar xzf nagios-plugins-1.4.11.tar.gz

• cd nagios-plugins-1.4.11

• Compile and install the plugins.

• ./configure --with-nagios-user=nagios --with-nagios-group=Nagios

• make

• make install

Start Nagios

• Verify the sample Nagios configuration files.

• /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

• If there are no errors, start Nagios.

• service nagios start

Page 8: Understanding Nagios Core: Core Component Interactions€¦ · Demo Overview Nagios Core version 4.0.8 (most current version as of this presentation) Demo installed on Red Hat Amazon

Nagios Core Components - nagios.cfg

Located at: /usr/local/nagios/etc/nagios.cfg

Main config file

Not much to change in here besides the Object Configuration file(s) section

Nagios will only process files and/or directories defined here

For medium to large sized Nagios deployments, I recommend using the cfg_dir location setting

Page 9: Understanding Nagios Core: Core Component Interactions€¦ · Demo Overview Nagios Core version 4.0.8 (most current version as of this presentation) Demo installed on Red Hat Amazon

Nagios Core Components - Hosts and Services

Can be located anywhere as long as defined in the nagios.cfg file. Default location: /usr/local/nagios/etc/objects

Hosts and Services can be defined in a number of different ways. For example all hosts can be defined in one .cfg file and all services in another.

I highly recommend creating a .cfg file for each host and defining the service checks on that host within this one file. This makes it easy to locate and configure all your systems and devices that you are monitoring.

Page 10: Understanding Nagios Core: Core Component Interactions€¦ · Demo Overview Nagios Core version 4.0.8 (most current version as of this presentation) Demo installed on Red Hat Amazon

Nagios Core Components – contacts.cfg

Located: /usr/local/nagios/etc/objects/contacts.cfg

Used to define anyone who will receive alerts via email or text

Can also use contact groups so multiple people can be contacted on a single alert

I recommend assigning host and service alerts to contact groups and managing the individuals in the contacts.cfg file

Page 11: Understanding Nagios Core: Core Component Interactions€¦ · Demo Overview Nagios Core version 4.0.8 (most current version as of this presentation) Demo installed on Red Hat Amazon

Nagios Core Components – templates.cfgLocated: /usr/local/nagios/etc/objects/templates.cfg

Used to create templates for host and service checks as well as contact notifications

Invoked using the ‘use’ command in the host, service or contact definitions

Multiple templates can be configured to manage multiple types of systems, services and contacts

Greatly reduces the time to setup new host and service checks

Commands set in the host, service or contact definition take precedence over template settings and will override the template setting

Page 12: Understanding Nagios Core: Core Component Interactions€¦ · Demo Overview Nagios Core version 4.0.8 (most current version as of this presentation) Demo installed on Red Hat Amazon

Nagios Core Components – timeperiods.cfg

Located: /usr/local/nagios/etc/objects/timeperiods.cfg

File used to define time periods that are referenced in templates, host, service and contact definitions

Like Nagios in general, very customizable

Page 13: Understanding Nagios Core: Core Component Interactions€¦ · Demo Overview Nagios Core version 4.0.8 (most current version as of this presentation) Demo installed on Red Hat Amazon

Nagios Core Components – hostgroups and servicegroups

Located: /usr/local/nagios/etc/objects/

Can create hostgroups.cfg and servicegroups.cfg files to organize hosts and services on the web UI

These .cfg files do not define any host or service and/or any host or service checks, they are just simply used to group like systems and services together

For example a common hostgroup would be “File Servers” and a common servicegroup would be “DNS Servers”

Page 14: Understanding Nagios Core: Core Component Interactions€¦ · Demo Overview Nagios Core version 4.0.8 (most current version as of this presentation) Demo installed on Red Hat Amazon

Nagios Core Components – Plugins

Located: /usr/local/nagios/libexec/

Plugins are the small programs and scripts that run the actual Nagios host and service checks

They are each independent ‘stand-alone’ programs that can be run individually

You can greatly extend the capabilities of Nagios by installing new plugins from: https://exchange.nagios.org/directory/Plugins or by creating your own

Page 15: Understanding Nagios Core: Core Component Interactions€¦ · Demo Overview Nagios Core version 4.0.8 (most current version as of this presentation) Demo installed on Red Hat Amazon

Nagios Core Components – commands.cfg

Located: /usr/local/nagios/etc/objects/commands.cfg

Commands define the host and service checks

Each command utilizes a script or program in the plugins directory

Commands are used to define the Nagios host and service checks and set the plugins options for these checks

You can write you own custom commands for existing Nagios plugins or create entirely new ones using custom wrote plugins

Page 16: Understanding Nagios Core: Core Component Interactions€¦ · Demo Overview Nagios Core version 4.0.8 (most current version as of this presentation) Demo installed on Red Hat Amazon

Nagios Core Components – Verifying configuration

Command: /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

Very useful command and should be run anytime changes are made before running ‘service nagios restart’

Will catch most syntax errors

Would suggest adding an alias to bashrc, as this command will be used a lot

alias nagios_check='/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg'

Page 17: Understanding Nagios Core: Core Component Interactions€¦ · Demo Overview Nagios Core version 4.0.8 (most current version as of this presentation) Demo installed on Red Hat Amazon

Remote monitoring of local resources - Linux

You can monitor local resources on a Linux system using NRPE (Nagios Remote Plugin Executor)

You must install the Nagios plugins, as described in the beginning of this presentation, in order to remotely monitor the system

In addition, you must also install the NRPE program on the remote system and configure it to run as a daemon

Edit the file at /usr/local/Nagios/etc/nrpe.cfg and set ‘allowed_hosts’ to your Nagios server’s IP address

The NRPE plugin will also need to be installed on the Nagios server

Page 18: Understanding Nagios Core: Core Component Interactions€¦ · Demo Overview Nagios Core version 4.0.8 (most current version as of this presentation) Demo installed on Red Hat Amazon

Remote monitoring of local resources - Windows

Can use NSClient++

Has a GUI install which installs a configuration file and sets up the ‘allowed_hosts’ setting during install

Can also set a password during install to further restrict access

Uses the same NRPE commands on the Nagios server to collect data

Page 19: Understanding Nagios Core: Core Component Interactions€¦ · Demo Overview Nagios Core version 4.0.8 (most current version as of this presentation) Demo installed on Red Hat Amazon

Q&A

Helpful Links:

Nagios Home Page - https://www.nagios.org/

Nagios Documentation - https://www.nagios.org/documentation

Nagios Plugins Exchange - https://exchange.nagios.org/directory/Plugins

NRPE Documentation - http://nagios.sourceforge.net/docs/nrpe/NRPE.pdf

NSClient++ - http://www.nsclient.org/