• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

The Urban Penguin

The Urban Penguin - Linux Training

  • Home
  • About
  • Live Online Courses
  • Shop
  • Programming
    • Master Editing Text Files Using VIM
    • Learn Shell Scripting with BASH
    • PERL Scripting in Linux
    • Ruby Scripting in Linux
    • Scripting with PowerShell
    • Learn C Programming using Linux and the Raspberry Pi
    • General Java Tutorials
    • Java 7 OCA Exam 1ZO-803
  • OS Tutorials
    • Red Hat and CentOS Training
      • Red Hat Enterprise Linux System Administration 1 – RH124
      • RHCSA – System Admin 2 – RH134
      • RHCE – EX294 – Automation With Ansible
    • Learning Ubuntu
    • LPI Training
      • LPI Linux Essentials
      • LPIC-1 Linux Administrator
      • LPIC-2 Certified Linux Engineer
      • LPIC-3 Senior Level Certification
        • LPIC-3 Exam 300 : Mixed Environments
        • LPIC-3 Exam 303 : Security
        • LPIC-3 Exam 304 : Virtualization and High Availability
    • Linux Technologies
      • Apache HTTPD Server
      • Learning PHP
      • Learning PUPPET
      • Learning SAMBA
      • Linux File-Systems
      • Monitoring with Nagios Core
      • MYSQL
      • openLDAP Directories on Linux
You are here: Home / Linux / nagios / Nagios Core – Enabling external commands

Nagios Core – Enabling external commands

October 23, 2013 by The Urban Penguin


It is possible to send commands to Nagios core from other systems or processes, this is known as external commands; however they do need to be enabled if you want to make use of them. These commands can be initiated through shell scripts on your host, through the browser or other APIS that you use. Commands are sent through to the nagios.cmd file which is named pipe and enabled the inter process communication. The location for this file is /var/lib/nagios3/rw and we have to ensure that the Apache process has permissions to the directory and file if we want to use these commands from the browser.

  1. Enable external commands in nagios. edit the nagios.cfg so that the check_external_commands options reads: check_external-commands = 1
  2. Add the Apache user account to the nagios group. In the case of Ubuntu this is www-data and we edit the /etc/group file to add the user to the group.
  3. Set the file system permissions. To access the nagios.cmd file which is writable by the group nagios we need to give group permissions to directories in its path:
    chmod g=rx /var/lib/nagios3 /var/lib/nagios3/rw
  4. Now we need to restart the apache and nagios servers
    sudo /etc/init.d/apache2 restart
    sudo /etc/init.d/nagios3 restart

External commands are written to /var/lib/nagios3/rw/nagios.cmd . This file is a named pipe and takes the input from the browser or script and pipes it through to nagios.

In the video we look at using the browser but we can use command line script if we like

#!/bin/sh
# This is a sample shell script showing how you can submit the #ACKNOWLEDGE_SVC_PROBLEM command
# to Nagios.  Adjust variables to fit your environment as necessary.

now=`date +%s`
commandfile='/var/lib/nagios3/rw/nagios.cmd'

/bin/printf "[%lu] ACKNOWLEDGE_SVC_PROBLEM;host1;service1;2;1;1;Some One;Some Acknowledgement Commentn" $now > $commandfile

As you can see from the script the text is just echoes through to the commandfile variable. See Nagios documentation for more commands that can be sent.

Share this:

  • Click to share on Twitter (Opens in new window)
  • Click to share on Facebook (Opens in new window)
  • Click to share on LinkedIn (Opens in new window)
  • Click to share on Reddit (Opens in new window)
  • Click to share on Pinterest (Opens in new window)
  • Click to share on Tumblr (Opens in new window)
  • Click to print (Opens in new window)

Filed Under: nagios, Ubuntu

Primary Sidebar

Newest Video

The Urban Penguin On Youtube

Categories

Pages

  • About The Urban Penguin
  • Contact Us
  • Shop
    • Basket
    • Checkout
    • My Account
  • LPI Training from The Urban Penguin
    • Live and Pluralsight hosted courses
    • Complete Linux Essentials
    • LPIC-3 Senior Level Certification
      • LPIC-3 Exam 300 : Mixed Environments
      • LPIC-3 Exam 303 : Security
      • LPIC-3 Exam 304 : Virtualization and High Availability
    • LPIC-2 Certified Linux Engineer
    • LPIC-1 Linux Administrator
    • LPI Linux Essentials for Raspberry Pi
    • LPI Linux Essentials
  • Operating System Tutorials
    • Linux Foundation Training
    • Solaris 11 OCA 1ZO-821
    • Learning Ubuntu
    • Learning SUSE
    • Red Hat and CentOS Training
      • RHCE – EX294 – Automation With Ansible
      • RHCSA – System Admin 1 – RH124
      • RHCSA – System Admin 2 – RH134
  • Scripting – the power of repetition!
    • Java 7 OCA Exam 1ZO-803
    • General Java Tutorials
    • Learn C Programming using Linux and the Raspberry Pi
    • Ruby Scripting in Linux
    • Scripting with PowerShell
    • PERL Scripting in Linux
    • Learn Shell Scripting with BASH
    • Master Editing Text Files Using VIM
  • Linux Technologies
    • Learning PUPPET
    • openLDAP Directories on Linux
    • Monitoring with Nagios Core
    • Linux File-Systems
    • Learning SAMBA
    • Apache HTTPD Server
    • Learning PHP
    • MYSQL
  • OpenStack
    • Pluralsight
    • Udemy
    • Raspberry Pi Tutorials
    • Citrix Videos
  • Online Instructor-led Courses
    • Red Hat Enterprise Linux System Administration 1 – RH124
    • SELinux Masterclass
    • Bash Scripting Masterclass
    • Nftables Masterclass

© 2021 The Urban Penguin · All Rights Reserved