Thanks Jef, for the reply.
Maybe I can reword my issue:
I have two raspberry PI. 4B. One PI run sensu-backend and sensuctl, another one run sensu-agent.
I created a very simple check with following config
{
"type": "CheckConfig",
"api_version": "core/v2",
"metadata": {
"name": "y_system_info_checker"
},
"spec": {
"command": "python /home/pi/checkers/bin/y_system_info.py",
"subscriptions": [
"system"
],
"handlers": [
"y_system_info"
],
"interval": 60,
"publish": true
}
}
y_system_info.py only has two line of code: import platform;print(platform.machine())
And here is handler
{
"type": "Handler",
"api_version": "core/v2",
"metadata": {
"name": "y_system_info",
"namespace": "default"
},
"spec": {
"command": "sh /home/pi/handlers/bin/y_system_info.sh",
"type": "pipe"
}
}
y_system_info.py only has two line of code: import platform;print(platform.machine())
Then I got following issue from sensu-backend log
{"check_name":"y_system_info_checker","check_namespace":"default","component":"pipeline/legacy","entity_name":"192.168.199.247","entity_namespace":"default","event_id":"bea8f6f6-e037-4564-b9c0-50bcf3da5291","handler":"y_system_info","level":"info","msg":"event pipe handler executed","**output":"sh: can't open '/home/pi/handlers/bin/y_system_info.sh': No such file or directory\n"**,"pipeline":"legacy-pipeline","pipeline_workflow":"legacy-pipeline-workflow-y_system_info","status":2,"time":"2022-07-06T23:23:16Z"}
I am 100% y_system_info.py exist in /home/pi/handlers/bin
Then I updated handler’s command just run a simple command whoami
{"check_name":"y_system_info_checker","check_namespace":"default","component":"pipeline/legacy","entity_name":"192.168.199.247","entity_namespace":"default","event_id":"33a9f148-a295-430e-b24a-0b84993acd75","handler":"y_system_info","level":"info","msg":"event pipe handler executed","**output":"root\n",**"pipeline":"legacy-pipeline","pipeline_workflow":"legacy-pipeline-workflow-y_system_info","status":0,"time":"2022-07-06T23:25:16Z"}
so I know sensu-agent host run handler command as root.
Next step I run mkdir test_create_folder && ls in handler’s command
{"check_name":"y_system_info_checker","check_namespace":"default","component":"pipeline/legacy","entity_name":"192.168.199.247","entity_namespace":"default","event_id":"04a3f0cb-7f95-4df7-927f-09e54b8092af","handler":"y_system_info","level":"info","msg":"event pipe handler executed","output":"bin\ndev\netc\nhome\nlib\nmedia\nmnt\nopt\nproc\nroot\nrun\nsbin\nsrv\nsys\ntest.sh\n**test_create_folder**\ntest_folder\ntmp\ntmp.txt\nusr\nvar\ny_system_info\n","pipeline":"legacy-pipeline","pipeline_workflow":"legacy-pipeline-workflow-y_system_info","status":0,"time":"2022-07-06T23:31:46Z"}
clearly test_create_folder has been create. however when I tried to run command in sensu-agent host
sudo su
cd /
ls
bin boot dev etc home lib lost+found media mnt opt proc root run sbin srv sys tmp usr
var
there is no test_create_folder
So I don’t know why handler command execute as root user, but it has different folder accessibility when I directly run command in sensu-agent host.