Check command "linux memory" does not exist

Hello Dear Community

I’m having trouble with the nagios plugin “linux memory” for checking the ram usage on a debian server machine over the agent.

I have installed the nagios plugin on both the master and on the server with the agent running.

This is the service on the master:

// Memory Usage
apply Service "linux_memory" {
  import "generic-service"
  check_command = "linux_memory"
  vars.linux_memory_warning = "20"
  vars.linux_memory_critical = "10"
  vars.linux_memory_divider = "M"
  command_endpoint = host.vars.client_endpoint
  assign where host.vars.client_endpoint
}

Where do I have do define this check_command? I’ve already tried to enter this check_command in conf.d/commands.conf or conf.d/services.conf Or what else am I missing? Since there’s the following error showing up at validation:

critical/config: Error: Validation failed for object 'xy-server!linux_memory' of type 'Service'; Attribute 'check_command': Object 'linux_memory' of type 'CheckCommand' does not exist.

Thank you very much for your help!

Hi,

both endpoints need to be aware of the command: The master in order to resolve the given command argument parameters, and the client to really calculate the command line being executed. The client may use a different local command to ignore certain passed parameters (for security reasons, but it is not general best practice).

Therefore, it is advised to put the CheckCommand into a global zone, namely global-templates which already comes pre-defined in the node wizard setups in recent versions.

mkdir -p /etc/icinga2/zones.d/global-templates
vim /etc/icinga2/zones.d/global-templates/commands.conf

...

systemctl restart icinga2

Cheers,
Michael

1 Like

Thank you very much! Service is now showing up!
But I’m getting the following message on icingaweb2:

/usr/lib/nagios/plugins/check_linux_memory: 8: /usr/lib/nagios/plugins/check_linux_memory: Syntax error: newline unexpected

Hi,

that’s coming from the plugin’s execution itself. I don’t know which source you did use, nor how the check command itself looks like, nor the executed command line. Please share that :slight_smile:

Cheers,
Michael

I have noticed that my nagios plugins are in /usr/lib64/nagios/plugins and not in /usr/lib/nagios/plugins, probably because of CentOS…
So it’s might looking in the wrong place?

I’ve used the following source:
wget https://github.com/osklil/nagios-misc/blob/master/check_linux_memory/check_linux_memory

Thanks:blush:

The plugin is executed already, so it shouldn’t be a location problem. To me, this sounds more like a missing code, wrong indent or interpreter, or whatever else. Time is limited so please provide the requested things :slight_smile:

Cheers,
Michael

Plugin Source:

Service:
// Memory Usage
apply Service “linux_memory” {
import “generic-service”
check_command = “linux_memory”
vars.linux_memory_warning = “20”
vars.linux_memory_critical = “10”
vars.linux_memory_divider = “M”
command_endpoint = host.vars.client_endpoint
assign where host.vars.client_endpoint
}

global-template:
/* Linux Memory Command */
object CheckCommand “linux_memory” {
command = [ PluginDir + “/check_linux_memory” ]
arguments ={
“-w” = “$linux_memory_warning$”
“-c” = “$linux_memory_critical$”
“-d” = “$linux_memory_divider$”
}
}

Ok, and the executed command line on the agent? Once you’ll have it, run the following on the agent:

sudo -u icinga <insert command here>

Cheers,
Michael

I’m not sure if this is what you’re looking for, sorry…

sudo -i /usr/lib/nagios/plugins/check_linux_memory:

    /usr/lib/nagios/plugins/check_linux_memory: Zeile 7: Syntaxfehler beim unerwarteten Wort `newline'
    /usr/lib/nagios/plugins/check_linux_memory: Zeile 7: `<!DOCTYPE html>'

Ah. Seems you’ve downloaded an HTTP page instead of the actual plugin :wink:

Lemme guess, you’re using

wget https://github.com/osklil/nagios-misc/blob/master/check_linux_memory/check_linux_memory

… instead, you’ll need the raw file to download :wink:

55

wget https://raw.githubusercontent.com/osklil/nagios-misc/master/check_linux_memory/check_linux_memory

Cheers,
Michael

You are absolutely correct! I’ve downloaded the HTTP page :sweat_smile:
We are one step further now:

Can't locate Nagios/Plugin.pm in @INC (you may need to install the Nagios::Plugin module) (@INC contains: /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.24.1 /usr/local/share/perl/5.24.1 /usr/lib/x86_64-linux-gnu/perl5/5.24 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl/5.24 /usr/share/perl/5.24 /usr/local/lib/site_perl /usr/lib/x86_64-linux-gnu/perl-base) at /usr/lib/nagios/plugins/check_linux_memory line 28.

BEGIN failed--compilation aborted at /usr/lib/nagios/plugins/check_linux_memory line 28.

I suspect, “perl-Nagios-Plugin” is missing?
The equivalent for debian would be “libnagios-plugin-perl” right?

Hi,

depending on your distribution, you may either find this packaged already as Perl library, or you’ll manually install Nagios::Plugin from CPAN.

apt-get install libnagios-plugin-perl

yum install perl-Nagios-Plugin

CentOS requires the EPEL repository up front.

yum -y install epel-release
yum makecache

Cheers,
Michael

Side note for Ubuntu 18.04 (and maybe other new debian-based systems):
On Ubuntu 18.04 you can install the package called libmonitoring-plugin-perl.
Downside is you have to change Nagios::Plugin to Monitoring::Plugin in the depending scripts.
For example with vim command line and %s/Nagios::Plugin/Monitoring::Plugin/g

2 Likes

Thank you!

Unfortunately, apt-get install libnagios-plugin-perl does not seem to work on my debian 9 server:

Paketlisten werden gelesen... Fertig
Abhängigkeitsbaum wird aufgebaut.
Statusinformationen werden eingelesen.... Fertig
Paket libnagios-plugin-perl ist nicht verfügbar, wird aber von einem anderen Paket
referenziert. Das kann heißen, dass das Paket fehlt, dass es abgelöst
wurde oder nur aus einer anderen Quelle verfügbar ist.

E: Für Paket »libnagios-plugin-perl« existiert kein Installationskandidat.

I was able to install apt-get install libmonitoring-plugin-perl, but that’s not going to do the trick, right?

Open your script with vim. When the file is open enter a : to enter the command line of vim.
On the command line just paste the command %s/Nagios::Plugin/Monitoring::Plugin/g and hit enter.
Now all occurrences of Nagios::Plugin are replaced by Monitoring::Plugin
Now just enter :x!or :wq to save the file. After this you should be able to run the script.

2 Likes

I’ve edited the check_linux_memory file in /usr/lib/nagios/plugins.
Now I’m not getting an error anymore, but the check is now purple in IcingaWeb2 with the following text:

Unknown option: d

How would a manual CLI run of this plugin look like? :slight_smile:

./check_linux_memory

check_linux_memory OK - Memory used: 7.8G/15.6G (50%), Swap used: 734M/1.7G (43%) | memused=8389021696B;;;0;16784388096 memused%=50%;;;0;100 swapused=769118208B;;;0;1795153920 swapused%=43%;;;0;100

So the plugin script doesn’t accept any threshold parameters?

I commented them out for now. It’s running perfectly without any threshold values.
I’m gonna try a few things and I’ll see if I’ll get it to work with threshold parameters. But thats not too important right now. Thanks very much for your help guys!! :smile: