sensu-plugins / sensu-plugins-java

Sensu Java Plugins
http://sensu-plugins.io
MIT License
5 stars 25 forks source link

Syntax Error in java-heap-pcnt.sh #1

Closed ExocTBlid closed 8 years ago

ExocTBlid commented 9 years ago

I'm getting the following error when running java-heap-pcnt.sh:

./java-heap-pcnt.sh:23:in `load': /usr/local/share/ruby/gems/2.0/gems/sensu-plugins-java-0.0.2/bin/java-heap-pcnt.sh:15: syntax error, unexpected tCONSTANT, expecting keyword_do_cond or ';' or '\n' (SyntaxError)
while getopts "w:c:n:hp" OPT; do
                            ^
/usr/local/share/ruby/gems/2.0/gems/sensu-plugins-java-0.0.2/bin/java-heap-pcnt.sh:15: syntax error, unexpected keyword_do_cond, expecting end-of-input
    from ./java-heap-pcnt.sh:23:in `<main>'

This is running on an Amazon AMI with Ruby 2.0 and I assume there's an conflict with Ruby loading the gem that runs the Bash script.

eheydrick commented 8 years ago

Which version of bash? And what is the full command line you are using to run it? I'm not able to repro with bash 4.3.11.

eheydrick commented 8 years ago

We need to provide ruby wrappers for the non-ruby files.

ExocTBlid commented 8 years ago

Sorry, it's been a while since I tried this. I used a different script in the mean time. Thanks for your work on this!

Akshaykapoor commented 8 years ago

@eheydrick i'm getting this when running from sensu, screen shot 2016-04-07 at 12 43 56 pm

Is there anything needed to run as is ?

eheydrick commented 8 years ago

@Akshaykapoor which platform is this on? Sounds like your sudoers has Defaults requiretty which requires sudo to run from a login session. You'd to remove that to get sudo working in non-interactive shells.

btw #sensu IRC is a better way to get support for plugins. There are lots of sensu users around to help out.

Akshaykapoor commented 8 years ago

@eheydrick My bad i read the script and it mentions there to include to allow sensu user sudo access without passwords. And i could resolve that. But came across another issue which is, when i install the gem and specify the check-name to run, it's failing with the following.,

/opt/sensu/embedded/bin/java-heap-pcnt.sh:23:in `load': /opt/sensu/embedded/lib/ruby/gems/2.0.0/gems/sensu-plugins-java-0.0.3/bin/java-heap-pcnt.sh:15: syntax error, unexpected tCONSTANT, expecting keyword_do_cond or ';' or '\n' (SyntaxError) while getopts 'w:c:n:hp' OPT; do ^ /opt/sensu/embedded/lib/ruby/gems/2.0.0/gems/sensu-plugins-java-0.0.3/bin/java-heap-pcnt.sh:15: syntax error, unexpected keyword_do_cond, expecting end-of-input from /opt/sensu/embedded/bin/java-heap-pcnt.sh:23:in `<main>'

Note: if i run the script from the terminal it just works fine. Any idea why like this ? Thanks!

eheydrick commented 8 years ago

@Akshaykapoor The problem is with binstubs - it's trying to execute the shell script as ruby which obviously doesn't work. To get around this we've been adding ruby binstub wrappers. We need to add them for these plugins. I'll do that ASAP.

eheydrick commented 8 years ago

0.0.4 has been released with ruby binstubs for the non-ruby scripts. Use check-java-heap-pcnt.rb in your check. See the README for more details.