Bit of a predicament with commands on Linux clients

Hey guys!

I have a problem with using commands on a linux client. It’s very simple, I have a service set for linux called basic linux checks or something, it has all the basic stuff like disk space, cpu load, memory, etc. Everything works except I memory.

For disk and cpu load I use the external commands called “load” and “disk”. These work just fine. But when using “mem” from the external commands I get the error: missing check_mem.pl. So I downloaded that file and it runs, but it says it needs arguments. Ok, no problem, I create a new command Called “Memory Check Command - Linux” and add the parameters. It looks like this:

zones.d/global-templates/commands.conf

object CheckCommand “Memory Check Command - Linux” {
import “plugin-check-command”
command = [ PluginDir + “/check_mem.pl” ]
arguments += {
“-c” = “95”
“-u” = {}
“-w” = “85”
}
}

Then I add this to my service, like it did on all my windows hosts and it says that command “Memory Check Command - Linux does not exist”.
Am I doing something wrong here? This approach worked on windows clients where I had to add arguments to the check commands.

Thanks in advance!

Couple of things are off here, you’re using the command object like a service object should ideally be used. Check this for the values already specified by the included command object:

https://icinga.com/docs/icinga2/latest/doc/10-icinga-template-library/#mem

check_mem.pl is one of a number of not-included checks that they already have command templates for. So instead, consider this example for a service object once check_mem.pl is available:

apply Service "memory" {
  import "generic-service"

  check_command = "mem"
  command_endpoint = host.name
  // consider this if your host template includes the command_endpoint value
  // from the default template:
  // command_endpoint = host.vars.client_endpoint

  vars.mem_used = true
  vars.mem_cache = true
  vars.mem_warning = 85 // percent
  vars.mem_critical = 90

  assign where host.vars.os = "Linux"
}

I’m not sure I understand what you’re getting at… The check_mem.pl is working, but it needs arguments passed (-c and -w) to work. How does one pass those arguments if not by creating a command object?

the command object receives them from the service object. this way they can be tuned per service object created, or per host type, etc. Command objects typically inherit from a Service object’s variables first and a Host object’s variables secondarily.

You can actually view the pre defined command objects in /usr/share/icinga2/include/. For mem is it such:

object CheckCommand "mem" {
	command = [ PluginContribDir + "/check_mem.pl" ]

	arguments = {
		"-u" = {
			set_if = "$mem_used$"
			description = "Check USED memory"
		}
		"-f" = {
			set_if = "$mem_free$"
			description = "Check FREE memory"
		}
		"-C" = {
			set_if = "$mem_cache$"
			description = "Count OS caches as FREE memory"
		}
		"-w" = {
			value = "$mem_warning$"
			description = "Percent free/used when to warn"
		}
		"-c" = {
			value = "$mem_critical$"
			description = "Percent free/used when critical"
		}
	}

	vars.mem_used = false
	vars.mem_free = false
	vars.mem_cache = false
}

So in this case, in the Service object I wrote as an example, -u and -c were set by marking those true, and -w and -c were set by providing a value.

Where can I do this on the service object in the director? The argument tab only shows on the command objects, nowhere else.

On Director? I’ll let someone else chime in. I do everything by hand. If there’s a thing for putting the aforementioned variables in, you’ll want to use that as the arguments are inherited.

Navigate into Commands > External and search for mem. Then in the fields tab, select the command arguments you want to use in your services. This is a required step.

Once done, navigate into the services, create apply rules or sets, put mem as check_command and select the previously created data fields from command arguments.

Cheers,
Michael

My man!

That clears up a lot of things. Now I only need to pass ‘-u’ to make it monitor USED memory, however I can only add the ‘mem_critical’ and ‘mem_warning’ fields and don’t see a way to add a custom one. Any ideas?

Hmmm it could be the case that the Director doesn’t understand the commands imported from Icinga 2’s ITL with set_if and no value, I am not sure about this.

Still, if you don’t get them via the command fields, you can always define data fields “free form” for being used in your service definitions. Therefore, navigate to the main dashboard and pick the data fields section.

Next up, define a new data field with the Boolean type, named mem_used.

Now, in your service, add this field and select true.

Once Icinga executes the check then, it will evaluate mem_used and if set to true, automatically add the required command line parameter -u. You can verify this via the Inspect option in the service’s detail view in Icinga Web 2.

Cheers,
Michael

2 Likes

It works, fantastic! Thank you very much!

You’re welcome :slight_smile: Especially since I am still learning with the Director, I am glad I could have helped you in there.

Please pick a reply which fits best as solution, and mark it like this. This helps others to immediately see that this topic has a solution too :kissing_heart: More: Mark a topic as solved