You are reading the documentation for Statusengine 3.x - Switch to Version 2.x for old stable

Setup a Naemon Development environment with Eclipse

This document describes how to setup Naemon in a development environment with attached Debugger using Eclipse on Ubuntu 18.04

If you are looking for an production setup please follow one of these guides:

I'm not a professional C developer. Want to improve this document? Please send a Pull Request to https://github.com/statusengine/docs

This tutorial contains a lot of screenshots. Hopefully this helps developers that are not familiar with eclipse (like myself) to follow this guide.

Prepare your system

Please run all commands as your user. It is not recommended to use root user.

Install Eclipse IDE

Download the latest version of Eclipse IDE for C/C++ Developers using your favorite web browser.

Install OpenJDK

sudo apt-get update
sudo apt-get install default-jre

Open a terminal and navigate to your downloads folder. Extract Eclipse to your home directory:

tar xfv eclipse-cpp-2019-03-R-linux-gtk-x86_64.tar.gz -C ~/

Start Eclipse

Execute:

~/eclipse/eclipse

Use the default path as Workspace and continue.

Set Eclipse Workspace

If you see the welcome message just minimize Eclipse for now.

Eclipse welcome message

Install dependencies for Naemon Core

sudo apt-get update
sudo apt-get install build-essential automake gperf help2man libtool libglib2.0-dev gdb monitoring-plugins git valgrind

Build a Basic Naemon configuration

To run Naemon a few configuration files are required like naemon.cfg and a host and service definition. I'm used to use the default configuration examples that are shipped with Naemon.

I'm also pretty sure that there is an easier way to generate this configuration files, which I didn't discovered yet. ¯\_(ツ)_/¯

cd /tmp/
wget https://github.com/naemon/naemon-core/archive/v1.0.10.tar.gz
tar xfv v1.0.10.tar.gz
cd naemon-core-1.0.10/

mkdir ~/naemon-dev
./autogen.sh --prefix=$(echo ~/naemon-dev) --with-naemon-user=$(whoami) --with-naemon-group=users --with-pluginsdir=/usr/lib/nagios/plugins
make all
make install

mkdir -p ~/naemon-dev/var/
mkdir -p ~/naemon-dev/var/cache/naemon
mkdir -p ~/naemon-dev/var/spool/checkresults
mkdir ~/naemon-dev/etc/naemon/module-conf.d

rm -rf ~/naemon-dev/bin
rm -rf ~/naemon-dev/include
rm -rf ~/naemon-dev/lib
rm -rf ~/naemon-dev/share

Clone Naemon source code

mkdir -p ~/git
cd ~/git

git clone https://github.com/naemon/naemon-core.git

Configure Eclipse

Switch back to Eclipse IDE.

First of all, close the welcome message.

Now import the Naemon code to Eclipse by navigate to File Import

Import code to Eclipse

Select C/C++ Existing code as Autotools project and continue.

Import code to Eclipse

Set the path where the Naemon source code is located (~/git/naemon-core) and continue.

Import code to Eclipse

Finish import.

Import code to Eclipse

Setup Autotools

Now its time to enable Eclipse to compile and run Naemon.

Go to Project Properties Autotools Configuration Settings

Set the --prefix option to the path, where your naemon configuration is stored: /home/$USERNAME$/naemon-dev.

Replace $USERNAME$ with your user name.

Import code to Eclipse

Make sure to enable the Debug option

Import code to Eclipse

And set the following additional command line options:

--with-naemon-user=$(echo ~/naemon-dev) --with-naemon-group=users --with-pluginsdir=/usr/lib/nagios/plugins

Import code to Eclipse

Make sure that all Builders are checked and click on Apply and Close

Import code to Eclipse

Now build Naemon Core through Project Build All

Import code to Eclipse

Check that the build was successful.

Import code to Eclipse

Setup Run environment

After Naemon was built successfully through the IDE you can set up the "Run environment" for Naemon.

This allows you to run Naemon Core inside the IDE.

Navigate to Project Properties Run/Debug Settings New C/C++ Application and click on Search Project and select the naemon binary.

Import code to Eclipse

Switch to the Arguments Tab and set /home/$USERNAME$/naemon-dev/etc/naemon/naemon.cfg as argument.

Replace $USERNAME$ with your user name.

Import code to Eclipse

Switch to the Environment Tab and create a new environment variable:

Name: LD_LIBRARY_PATH

Value: /home/$USERNAME$/git/naemon-core/.libs:$LD_LIBRARY_PATH

Replace $USERNAME$ with your user name.

Import code to Eclipse

Press Apply and close the window.

Run Naemon-Core in the IDE

Run Naemon through the IDE and check the Console for the following line:

Successfully launched command file worker with pid <PID>

Import code to Eclipse

Import code to Eclipse

Press Stop to kill the Naemon process.

Setup Debugger environment

Now you are able to configure, compile and run Naemon inside the IDE. In the last step you need to configure the IDE to be able to attach a Debugger.

Open the Debug Configurations

Import code to Eclipse

Select C/C++ Application Naemon-Core Build Debugger Tab Disable Stop on startup at: main Apply and close the window.

Import code to Eclipse

Run Naemon-Core with attached Debugger

Open a C-File, for Example src/naemon/checks_service.c and add a Breakpoint by double clicking on a line number (line 127 in my case). Than start Naemon with the Debugger.

Import code to Eclipse

If Eclipse ask you if you want to switch into the Debug perspective select switch.

Import code to Eclipse

As soon as the code reaches your Breakpoint you can debug as you are used to.

Import code to Eclipse

Setup Valgrind

Valgrind is a powerful profiling tool which can also be integrated to Eclipse. It can be used to find memory leaks.

Navigate to Project Properties Run/Debug Settings New Profile With Valgrind and click on Search Project and select the naemon binary.

Import code to Eclipse

Switch to the Arguments Tab and set /home/$USERNAME$/naemon-dev/etc/naemon/naemon.cfg as argument.

Replace $USERNAME$ with your user name.

Import code to Eclipse

Switch to the Valgrind Options Tab. Valgrind provides different profiling tools. I chosed Massif in my case.

Import code to Eclipse

Switch to the Environment Tab and create a new environment variable:

Name: LD_LIBRARY_PATH

Value: /home/$USERNAME$/git/naemon-core/.libs:$LD_LIBRARY_PATH

Replace $USERNAME$ with your user name.

Import code to Eclipse

Run Naemon-Core through Valgrind

Switch you Launch Configuration to Naemon Valgrind and click on Launch in Profile mode

Import code to Eclipse

Import code to Eclipse

Let Naemon run in profiling mode for a few minutes. As soon as you stop Naemon you will get a heap allocation chart.

Import code to Eclipse

Happy hacking!