Is it possible to execute system commands from check-definition

Hello All,

I’m attempting to dynamically set the critical value for check-procs.rb by defining the subscriber check with the following definition json:

{

“checks”: {

“check-process-test”: {

“command”: "check-procs.rb -p test_process -C cat /var/test_process_count",

“subscribers”: [

“testing”

],

“handlers”: [

“pagerduty”

],

“interval”: 30

}

}

}

When I run cat /var/test_process_count on the client the return is ‘4’, but when sensu-client executes the full check command the check-procs.rb defaults to the config default of 1.

Is there any way to dynamically change the critical value based on contents of a file on the client’s disk?

Thanks,

-jake | jherbst

Hey Jake,

You can drop data in your client.json config[1] and read that from your check definitions (with an optional default) [2].

Hope that helps.

[1] See Custom Key-Values in http://sensuapp.org/docs/0.11/clients

[2] See Check command token substitution in http://sensuapp.org/docs/0.11/checks

···

On Monday, February 3, 2014 10:35:24 AM UTC-8, Jacob Herbst wrote:

Hello All,

I’m attempting to dynamically set the critical value for check-procs.rb by defining the subscriber check with the following definition json:

{

“checks”: {

“check-process-test”: {

“command”: "check-procs.rb -p test_process -C cat /var/test_process_count",

“subscribers”: [

“testing”

],

“handlers”: [

“pagerduty”

],

“interval”: 30

}

}

}

When I run cat /var/test_process_count on the client the return is ‘4’, but when sensu-client executes the full check command the check-procs.rb defaults to the config default of 1.

Is there any way to dynamically change the critical value based on contents of a file on the client’s disk?

Thanks,

-jake | jherbst

Thanks for the info Nick, but sadly I’m not sure this is going to accomplish what I need it to.

The process_count is dynamic and changes fairly often, so I need to be able to get real-time information from the system (by viewing contents of ‘/var/test_process_count’), then set the critical value of the check based on the contents of that file.

···

On Tuesday, February 4, 2014 11:51:44 AM UTC-5, Nick Stielau wrote:

Hey Jake,

You can drop data in your client.json config[1] and read that from your check definitions (with an optional default) [2].

Hope that helps.

[1] See Custom Key-Values in http://sensuapp.org/docs/0.11/clients

[2] See Check command token substitution in http://sensuapp.org/docs/0.11/checks

On Monday, February 3, 2014 10:35:24 AM UTC-8, Jacob Herbst wrote:

Hello All,

I’m attempting to dynamically set the critical value for check-procs.rb by defining the subscriber check with the following definition json:

{

“checks”: {

“check-process-test”: {

“command”: "check-procs.rb -p test_process -C cat /var/test_process_count",

“subscribers”: [

“testing”

],

“handlers”: [

“pagerduty”

],

“interval”: 30

}

}

}

When I run cat /var/test_process_count on the client the return is ‘4’, but when sensu-client executes the full check command the check-procs.rb defaults to the config default of 1.

Is there any way to dynamically change the critical value based on contents of a file on the client’s disk?

Thanks,

-jake | jherbst

Maybe the best option is to modify check-procs.rb to read the Critical threshold from that file and have a check definition like:

{

“checks”: {

“check-process-test”: {

“command”: “my-check-procs.rb -p test_process --C-file /var/test_process_count”,

“subscribers”: [

“testing”

],

“handlers”: [

“pagerduty”

],

“interval”: 30

}

}

}

Regards,

J

···

On Tue, Feb 4, 2014 at 5:57 PM, Jacob Herbst jmherbst@gmail.com wrote:

Thanks for the info Nick, but sadly I’m not sure this is going to accomplish what I need it to.

The process_count is dynamic and changes fairly often, so I need to be able to get real-time information from the system (by viewing contents of ‘/var/test_process_count’), then set the critical value of the check based on the contents of that file.

On Tuesday, February 4, 2014 11:51:44 AM UTC-5, Nick Stielau wrote:

Hey Jake,

You can drop data in your client.json config[1] and read that from your check definitions (with an optional default) [2].

Hope that helps.

[1] See Custom Key-Values in http://sensuapp.org/docs/0.11/clients

[2] See Check command token substitution in http://sensuapp.org/docs/0.11/checks

On Monday, February 3, 2014 10:35:24 AM UTC-8, Jacob Herbst wrote:

Hello All,

I’m attempting to dynamically set the critical value for check-procs.rb by defining the subscriber check with the following definition json:

{

“checks”: {

“check-process-test”: {

“command”: "check-procs.rb -p test_process -C cat /var/test_process_count",

“subscribers”: [

“testing”

],

“handlers”: [

“pagerduty”

],

“interval”: 30

}

}

}

When I run cat /var/test_process_count on the client the return is ‘4’, but when sensu-client executes the full check command the check-procs.rb defaults to the config default of 1.

Is there any way to dynamically change the critical value based on contents of a file on the client’s disk?

Thanks,

-jake | jherbst


Javier

Hey,

Yeah, I agree with Javier: just update the check you’re running, it should be just a few lines of code. I’m actually not sure why the inline backticks didn’t work, as other shell operators do (&&, ||, |), although I haven’t tried it explicitly, so you could potentially try debugging more (maybe triggering debug logging with http://sensuapp.org/docs/0.11/faq).

···

On Wednesday, February 5, 2014 2:38:02 AM UTC-8, Javier Segura wrote:

Maybe the best option is to modify check-procs.rb to read the Critical threshold from that file and have a check definition like:

{

“checks”: {

“check-process-test”: {

“command”: “my-check-procs.rb -p test_process --C-file /var/test_process_count”,

“subscribers”: [

“testing”

],

“handlers”: [

“pagerduty”

],

“interval”: 30

}

}

}

Regards,

J

On Tue, Feb 4, 2014 at 5:57 PM, Jacob Herbst jmhe...@gmail.com wrote:

Thanks for the info Nick, but sadly I’m not sure this is going to accomplish what I need it to.

The process_count is dynamic and changes fairly often, so I need to be able to get real-time information from the system (by viewing contents of ‘/var/test_process_count’), then set the critical value of the check based on the contents of that file.

On Tuesday, February 4, 2014 11:51:44 AM UTC-5, Nick Stielau wrote:

Hey Jake,

You can drop data in your client.json config[1] and read that from your check definitions (with an optional default) [2].

Hope that helps.

[1] See Custom Key-Values in http://sensuapp.org/docs/0.11/clients

[2] See Check command token substitution in http://sensuapp.org/docs/0.11/checks

On Monday, February 3, 2014 10:35:24 AM UTC-8, Jacob Herbst wrote:

Hello All,

I’m attempting to dynamically set the critical value for check-procs.rb by defining the subscriber check with the following definition json:

{

“checks”: {

“check-process-test”: {

“command”: "check-procs.rb -p test_process -C cat /var/test_process_count",

“subscribers”: [

“testing”

],

“handlers”: [

“pagerduty”

],

“interval”: 30

}

}

}

When I run cat /var/test_process_count on the client the return is ‘4’, but when sensu-client executes the full check command the check-procs.rb defaults to the config default of 1.

Is there any way to dynamically change the critical value based on contents of a file on the client’s disk?

Thanks,

-jake | jherbst


Javier

Backticks in commands should work, I’m going to add a check definition with backticks to the test suite, see if anything jumps out.

···

On Wed, Feb 5, 2014 at 8:57 AM, Nick Stielau nick.stielau@gmail.com wrote:

Hey,

Yeah, I agree with Javier: just update the check you’re running, it should be just a few lines of code. I’m actually not sure why the inline backticks didn’t work, as other shell operators do (&&, ||, |), although I haven’t tried it explicitly, so you could potentially try debugging more (maybe triggering debug logging with http://sensuapp.org/docs/0.11/faq).

On Wednesday, February 5, 2014 2:38:02 AM UTC-8, Javier Segura wrote:

Maybe the best option is to modify check-procs.rb to read the Critical threshold from that file and have a check definition like:

{

“checks”: {

“check-process-test”: {

“command”: “my-check-procs.rb -p test_process --C-file /var/test_process_count”,

“subscribers”: [

“testing”

],

“handlers”: [

“pagerduty”

],

“interval”: 30

}

}

}

Regards,

J

On Tue, Feb 4, 2014 at 5:57 PM, Jacob Herbst jmhe...@gmail.com wrote:

Thanks for the info Nick, but sadly I’m not sure this is going to accomplish what I need it to.

The process_count is dynamic and changes fairly often, so I need to be able to get real-time information from the system (by viewing contents of ‘/var/test_process_count’), then set the critical value of the check based on the contents of that file.

On Tuesday, February 4, 2014 11:51:44 AM UTC-5, Nick Stielau wrote:

Hey Jake,

You can drop data in your client.json config[1] and read that from your check definitions (with an optional default) [2].

Hope that helps.

[1] See Custom Key-Values in http://sensuapp.org/docs/0.11/clients

[2] See Check command token substitution in http://sensuapp.org/docs/0.11/checks

On Monday, February 3, 2014 10:35:24 AM UTC-8, Jacob Herbst wrote:

Hello All,

I’m attempting to dynamically set the critical value for check-procs.rb by defining the subscriber check with the following definition json:

{

“checks”: {

“check-process-test”: {

“command”: "check-procs.rb -p test_process -C cat /var/test_process_count",

“subscribers”: [

“testing”

],

“handlers”: [

“pagerduty”

],

“interval”: 30

}

}

}

When I run cat /var/test_process_count on the client the return is ‘4’, but when sensu-client executes the full check command the check-procs.rb defaults to the config default of 1.

Is there any way to dynamically change the critical value based on contents of a file on the client’s disk?

Thanks,

-jake | jherbst


Javier