Icinga result diffent from local

I want to check MegaRAID status with a smiple python script:

#!/usr/bin/python3

import os,sys

CMD = "/usr/local/MegaRAID\ Storage\ Manager/StorCLI/storcli64 -AdpAllInfo -aALL | grep -A 8 'Device Present' | grep 0 | wc -l"
PRESENT = int(os.popen(CMD).read())

if PRESENT < 4:
	print('RAID is CRITICAL')
	sys.exit(1)
else:
	print('All are OK')
	sys.exit(0)

The result is OK in local shell:

# /usr/lib/nagios/plugins/check_MegaRAID.py
All are OK

But after configure in icinga2, the result is ‘RAID is CRITICAL’

object CheckCommand "MegaRAID" {
  import "ipv4-or-ipv6"

  command = [
    PluginDir + "/check_MegaRAID.py",
  ]
}

apply Service "MegaRAID" {
  display_name = "MegaRAID"
  check_command = "MegaRAID"
  command_endpoint = host.vars.client_endpoint
  vars.grafana_graph_disable = 1
  ...... 
}

Hi & welcome,

How did you test your script in bash? With root permissions or the icinga/nagios user? My guess if icinga triggers yours script it has not much permissions.
If you configured something like SELinux or AppAmor check these logs, if the system blocks the access

greets

It is OK in bash:

# /usr/lib/nagios/plugins/check_MegaRAID.py
All are OK

So, judging by your command prompt # this command is being run as root.

Please repeat as the user icinga to ensure permissions are sufficient to get the
same result.

Antony.

thanks for you reply
you are right

the result is diffent exec by nagios and roo

root@xnode002:~# su -s /bin/sh -c “/usr/lib/nagios/plugins/check_MegaRAID.py” nagios
RAID is CRITICAL
root@xnode002:~# /usr/lib/nagios/plugins/check_MegaRAID.py
All are OK
and the storcli64
root@xnode002:~# ls -l /usr/local/MegaRAID\ Storage\ Manager/StorCLI/storcli64
-rwsr-sr-x 1 nagios root 7951864 Jul 5 2019 /usr/local/MegaRAID Storage Manager/StorCLI/storcli64
root@xnode002:~# su -s /bin/sh -c “/usr/local/MegaRAID\ Storage\ Manager/StorCLI/storcli64 -AdpAllInfo -aALL” nagios

Exit Code: 0x01
root@xnode002:~# su -s /bin/sh -c "/usr/local/MegaRAID\ Storage\ Manager/StorCLI/storcli64 " nagios
Storage Command Line Tool Ver 1.23.02 Mar 28, 2017

 (c)Copyright 2017, AVAGO Corporation, All Rights Reserved.

help - lists all the commands with their usage. E.g. storcli help
help - gives details about a particular command. E.g. storcli add help

List of commands:

Commands Description

add Adds/creates a new element to controller like VD,Spare…etc
delete Deletes an element like VD,Spare
show Displays information about an element
set Set a particular value to a property
get Get a particular value to a property
compare Compares particular value to a property
start Start background operation
stop Stop background operation
pause Pause background operation
resume Resume background operation
download Downloads file to given device
expand expands size of given drive
insert inserts new drive for missing
transform downgrades the controller
/cx Controller specific commands
/ex Enclosure specific commands
/sx Slot/PD specific commands
/vx Virtual drive specific commands
/dx Disk group specific commands
/fall Foreign configuration specific commands
/px Phy specific commands
/[bbu|cv] Battery Backup Unit, Cachevault commands
/jbodx JBOD drive specific commands

Other aliases : cachecade, freespace, sysinfo

Use a combination of commands to filter the output of help further.
E.g. ‘storcli cx show help’ displays all the show operations on cx.
Use verbose for detailed description E.g. ‘storcli add verbose help’
Use ‘page=’ as the last option in all the commands to set the page break.
X=lines per page. E.g. ‘storcli help page=10’
Use J as the last option to print the command output in JSON format
Command options must be entered in the same order as displayed in the help of
the respective commands.

I don’t know how to grant the permissions of MSM to nagios