Hi, I have found one ruby plugin for checking freenas FreeNAS plugin
, and it was all set and tested, so the script works as it is expected if I run it manually.
I have placed my plugin to default path of all plugins /usr/lib64/nagios/plugins/check_freenas_ruby
and I made super simple shell script to call that ruby script (it was not needed but I did it anyway)
My next step was to set this as a service to run in icinga2 itself, so I have created under zones.d/master/server.example.com.conf
and inside (since I am not an expert in icinga2 field) I have probably messy script:
// Endpoints & Zones
object Endpoint "server.example.com" {
}
object Zone "server.example.com" {
endpoints = [ "server.example.com" ]
parent = "master"
}
apply Service "check_freenas" {
check_command = "check_freenas"
assign where host.name == "server.example.com"
}
object CheckCommand "check_freenas" {
import "plugin-check-command"
command = [ "/usr/lib64/nagios/plugins/check_freenas" ]
}
// Host Objects
object Host "server.example.com" {
check_command = "hostalive"
address = "192.168.1.2"
vars.client_endpoint = name //follows the convention that host name == endpoint name
// Custom Optional Check - END
}
Now this service is shown in the icingaweb2 without issues and default plugins are working such as āpingā, but that custom ruby script is giving the error:
[2020-05-29 08:41:18 +0200] warning/PluginCheckTask: Check command for object āserver.example.com!check_freenasā (PID: 27951, arguments: ā/usr/lib64/nagios/plugins/check_freenasā) terminated with exit code 126, output: /usr/lib64/nagios/plugins/check_freenas: line 4: /root/.rbenv/shims/ruby: Permission denied
If all other plugins are āroot:rootā, I even tried to set this plugin to have apache:icingaweb2 permissions, along with ruby binary (just for a test)⦠The output was the same.
Which permissions should this have to be able to execute and get info from my freenas server?
You probably run your script manually as user root but icinga is executing the plugin as icinga/nagios (depending on your distribution). This may produce different results as you may have different environments and/or access rights. Therefore, it is always recommended to run manually tests as the icinga user.
Iām sorry but in my opinion is this the wrong way because this will weakening security. In most case sudo is not necessary. In your case Iād assume you simply you should not use rbenv from user root but from your icinga user (if it is necessary at all - which I cannot comment on as Iām not familiar wich ruby).
I got some progress in terms of getting this script to work. SELinux was causing problem, now I will try to revoke sudo and see what happens⦠I will report progress here, so if someone needs solution that it is here in the community
Unfortunately no, when I revoke sudo it does not work. I can set any permissions, it makes no difference, so what I did is, set sudo only to that script and set chattr +i to make check_freenas script immutable, that content cannot be changed and system abosed, unless it is first attribute modified by root, and then changed⦠It is not great security, but it will do