result = Hash.from_xml(File.read(sortname[-1])).to_json
puts result
return result
``
However, when executed by Sensu through checks it returns an error:
/opt/sensu/embedded/bin/event-queues.rb:6:in `initialize': no implicit conversion of nil into String (TypeError) from /opt/sensu/embedded/bin/event-queues.rb:6:in `<main>'
Before iterating over something you should always check that its empty. I was able to replicate by creating an empty dir and doing what you did. From my quick tests of using Dir it will always return an empty array when using a blob even if the parent dir does not exist, this is probably your issue if I had to guess.
result = Hash.from_xml(File.read(sortname[-1])).to_json
puts result
return result
``
However, when executed by Sensu through checks it returns an error:
/opt/sensu/embedded/bin/event- queues.rb:6:in initialize': no implicit conversion of nil into String (TypeError) from /opt/sensu/embedded/bin/event-queues.rb:6:in ’
The thing is the dir I am referring to is not empty. When I execute your script in the command line using the following I get the exact results I want. But when sensu client picks it up, it is seeing an empty DIR.
./ruby xmltojson.rb
``
Any ideas on this? thanks!
Regards,
Peter
···
On Monday, July 10, 2017 at 2:35:56 AM UTC+8, Ben Abrams wrote:
Peter,
Before iterating over something you should always check that its empty. I was able to replicate by creating an empty dir and doing what you did. From my quick tests of using Dir it will always return an empty array when using a blob even if the parent dir does not exist, this is probably your issue if I had to guess.
result = Hash.from_xml(File.read(sortname[-1])).to_json
puts result
return result
``
However, when executed by Sensu through checks it returns an error:
/opt/sensu/embedded/bin/event- queues.rb:6:in initialize': no implicit conversion of nil into String (TypeError) from /opt/sensu/embedded/bin/event-queues.rb:6:in ’
Also, the dir and the files has all the permissions needed. So I don’t understand why Sensu sees this as empty.
/home/oracle/test
drwxrwxrwx. 2 oracle oinstall 36864 Jul 4 05:23 test
``
/home/oracle/test/*
-rwxrwxrwx. 1 oracle oinstall 60056 Jun 28 01:55 performance.20170628015548.xml
``
···
On Wednesday, July 12, 2017 at 9:43:22 AM UTC+8, Peter wrote:
Hi Ben,
Thank you for responding to this thread.
The thing is the dir I am referring to is not empty. When I execute your script in the command line using the following I get the exact results I want. But when sensu client picks it up, it is seeing an empty DIR.
./ruby xmltojson.rb
``
Any ideas on this? thanks!
Regards,
Peter
On Monday, July 10, 2017 at 2:35:56 AM UTC+8, Ben Abrams wrote:
Peter,
Before iterating over something you should always check that its empty. I was able to replicate by creating an empty dir and doing what you did. From my quick tests of using Dir it will always return an empty array when using a blob even if the parent dir does not exist, this is probably your issue if I had to guess.
result = Hash.from_xml(File.read(sortname[-1])).to_json
puts result
return result
``
However, when executed by Sensu through checks it returns an error:
/opt/sensu/embedded/bin/event- queues.rb:6:in initialize': no implicit conversion of nil into String (TypeError) from /opt/sensu/embedded/bin/event-queues.rb:6:in ’
What version of sensu are you running? Wondering if its maybe something different caused by different ruby versions. When I have some time I will see if I can replicate this locally outside of the context of sensu and if not then I will try reproducing it in a sensu context.
···
On Tuesday, July 11, 2017 at 7:17:24 PM UTC-7, Peter wrote:
Also, the dir and the files has all the permissions needed. So I don’t understand why Sensu sees this as empty.
/home/oracle/test
drwxrwxrwx. 2 oracle oinstall 36864 Jul 4 05:23 test
``
/home/oracle/test/*
-rwxrwxrwx. 1 oracle oinstall 60056 Jun 28 01:55 performance.20170628015548.xml
``
On Wednesday, July 12, 2017 at 9:43:22 AM UTC+8, Peter wrote:
Hi Ben,
Thank you for responding to this thread.
The thing is the dir I am referring to is not empty. When I execute your script in the command line using the following I get the exact results I want. But when sensu client picks it up, it is seeing an empty DIR.
./ruby xmltojson.rb
``
Any ideas on this? thanks!
Regards,
Peter
On Monday, July 10, 2017 at 2:35:56 AM UTC+8, Ben Abrams wrote:
Peter,
Before iterating over something you should always check that its empty. I was able to replicate by creating an empty dir and doing what you did. From my quick tests of using Dir it will always return an empty array when using a blob even if the parent dir does not exist, this is probably your issue if I had to guess.
result = Hash.from_xml(File.read(sortname[-1])).to_json
puts result
return result
``
However, when executed by Sensu through checks it returns an error:
/opt/sensu/embedded/bin/event- queues.rb:6:in initialize': no implicit conversion of nil into String (TypeError) from /opt/sensu/embedded/bin/event-queues.rb:6:in ’
Can you verify the same script on the server has the same results when you run /opt/sensu/embedded/bin/ruby $PATH_TO_SCRIPT and calling $PATH_TO_SCRIPT directly?
···
On Tuesday, July 11, 2017 at 9:15:15 PM UTC-7, Ben Abrams wrote:
What version of sensu are you running? Wondering if its maybe something different caused by different ruby versions. When I have some time I will see if I can replicate this locally outside of the context of sensu and if not then I will try reproducing it in a sensu context.
On Tuesday, July 11, 2017 at 7:17:24 PM UTC-7, Peter wrote:
Also, the dir and the files has all the permissions needed. So I don’t understand why Sensu sees this as empty.
/home/oracle/test
drwxrwxrwx. 2 oracle oinstall 36864 Jul 4 05:23 test
``
/home/oracle/test/*
-rwxrwxrwx. 1 oracle oinstall 60056 Jun 28 01:55 performance.20170628015548.xml
``
On Wednesday, July 12, 2017 at 9:43:22 AM UTC+8, Peter wrote:
Hi Ben,
Thank you for responding to this thread.
The thing is the dir I am referring to is not empty. When I execute your script in the command line using the following I get the exact results I want. But when sensu client picks it up, it is seeing an empty DIR.
./ruby xmltojson.rb
``
Any ideas on this? thanks!
Regards,
Peter
On Monday, July 10, 2017 at 2:35:56 AM UTC+8, Ben Abrams wrote:
Peter,
Before iterating over something you should always check that its empty. I was able to replicate by creating an empty dir and doing what you did. From my quick tests of using Dir it will always return an empty array when using a blob even if the parent dir does not exist, this is probably your issue if I had to guess.
result = Hash.from_xml(File.read(sortname[-1])).to_json
puts result
return result
``
However, when executed by Sensu through checks it returns an error:
/opt/sensu/embedded/bin/event- queues.rb:6:in initialize': no implicit conversion of nil into String (TypeError) from /opt/sensu/embedded/bin/event-queues.rb:6:in ’
For some environment reasons I can only execute the script with the correct results when I go to the directory ‘/opt/sensu/embedded/bin’ and then execute the following
#/opt/sensu/embedded/bin> ./ruby event-queues.rb
``
When I execute it outside the directory by using the following the result is “No such file or directory”
On Wednesday, July 12, 2017 at 12:23:34 PM UTC+8, Ben Abrams wrote:
Can you verify the same script on the server has the same results when you run /opt/sensu/embedded/bin/ruby $PATH_TO_SCRIPT and calling $PATH_TO_SCRIPT directly?
On Tuesday, July 11, 2017 at 9:15:15 PM UTC-7, Ben Abrams wrote:
What version of sensu are you running? Wondering if its maybe something different caused by different ruby versions. When I have some time I will see if I can replicate this locally outside of the context of sensu and if not then I will try reproducing it in a sensu context.
On Tuesday, July 11, 2017 at 7:17:24 PM UTC-7, Peter wrote:
Also, the dir and the files has all the permissions needed. So I don’t understand why Sensu sees this as empty.
/home/oracle/test
drwxrwxrwx. 2 oracle oinstall 36864 Jul 4 05:23 test
``
/home/oracle/test/*
-rwxrwxrwx. 1 oracle oinstall 60056 Jun 28 01:55 performance.20170628015548.xml
``
On Wednesday, July 12, 2017 at 9:43:22 AM UTC+8, Peter wrote:
Hi Ben,
Thank you for responding to this thread.
The thing is the dir I am referring to is not empty. When I execute your script in the command line using the following I get the exact results I want. But when sensu client picks it up, it is seeing an empty DIR.
./ruby xmltojson.rb
``
Any ideas on this? thanks!
Regards,
Peter
On Monday, July 10, 2017 at 2:35:56 AM UTC+8, Ben Abrams wrote:
Peter,
Before iterating over something you should always check that its empty. I was able to replicate by creating an empty dir and doing what you did. From my quick tests of using Dir it will always return an empty array when using a blob even if the parent dir does not exist, this is probably your issue if I had to guess.
result = Hash.from_xml(File.read(sortname[-1])).to_json
puts result
return result
``
However, when executed by Sensu through checks it returns an error:
/opt/sensu/embedded/bin/event- queues.rb:6:in initialize': no implicit conversion of nil into String (TypeError) from /opt/sensu/embedded/bin/event-queues.rb:6:in ’
The reason you do not need the full path when, say, writing your JSON files is that during normal operation sensu-client assumes it is already in /opt/sensu/embedded/bin when executing scripts.
···
On Thursday, July 13, 2017 at 9:28:34 AM UTC+2, Peter wrote:
Hi Ben,
For some environment reasons I can only execute the script with the correct results when I go to the directory ‘/opt/sensu/embedded/bin’ and then execute the following
#/opt/sensu/embedded/bin> ./ruby event-queues.rb
``
When I execute it outside the directory by using the following the result is “No such file or directory”
Thank you for this and apologies for the late response. Been quite busy these past few days
However, this still doesn’t explain why sensu client reads the directory as empty?
Also, the sensu client version is Version: 0.29.0. Any ideas on this?
Regards,
Peter
···
On Thursday, July 13, 2017 at 5:49:25 PM UTC+8, Alexander Skiba wrote:
On Thursday, July 13, 2017 at 9:28:34 AM UTC+2, Peter wrote:
Hi Ben,
For some environment reasons I can only execute the script with the correct results when I go to the directory ‘/opt/sensu/embedded/bin’ and then execute the following
#/opt/sensu/embedded/bin> ./ruby event-queues.rb
``
When I execute it outside the directory by using the following the result is “No such file or directory”
The reason you do not need the full path when, say, writing your JSON files is that during normal operation sensu-client assumes it is already in /opt/sensu/embedded/bin when executing scripts.
This is solved. I think there’s a permission issue in the directory that I am using. I just moved my files under /opt/sensu/embedded/bin directory which solved my problem.
Thanks for your assistance!
Regards,
Peter
···
On Tuesday, July 18, 2017 at 11:42:43 AM UTC+8, Peter wrote:
Hi Alexander,
Thank you for this and apologies for the late response. Been quite busy these past few days
However, this still doesn’t explain why sensu client reads the directory as empty?
Also, the sensu client version is Version: 0.29.0. Any ideas on this?
Regards,
Peter
On Thursday, July 13, 2017 at 5:49:25 PM UTC+8, Alexander Skiba wrote:
On Thursday, July 13, 2017 at 9:28:34 AM UTC+2, Peter wrote:
Hi Ben,
For some environment reasons I can only execute the script with the correct results when I go to the directory ‘/opt/sensu/embedded/bin’ and then execute the following
#/opt/sensu/embedded/bin> ./ruby event-queues.rb
``
When I execute it outside the directory by using the following the result is “No such file or directory”
The reason you do not need the full path when, say, writing your JSON files is that during normal operation sensu-client assumes it is already in /opt/sensu/embedded/bin when executing scripts.