question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Problems with "command" alert

See original GitHub issue

Hi there, I’m encountering all sorts of strange issues trying to set up a command alert. Essentially all I want to do is hit an http endpoint with any matching documents. This is the structure I’ve got set up for my command alert:

    alert:
     - command:
         command: "curl -XPOST -H \"Content-Type: application/json\" \"https://my.endpoint\" -d@-"
    pipe_match_json: true

The -d@- option causes curl commands to read from stdin, which as I understand, pipe_match_json should provide.

When I do I get this strange error though: elastalert_error - {'message': 'Error while running alert command: Error while running command c u r l - X P O S T - H " C o n t e n t - T y p e : a p p l i c a t i o n / j s o n " " h t t p s : / / m y . e n d p o i n t" - d @ -: [Errno 2] No such file or directory', 'traceback': ['Traceback (most recent call last):', ' File "/usr/local/lib/python2.7/dist-packages/elastalert-0.0.84-py2.7.egg/elastalert/elastalert.py", line 976, in send_alert', ' alert.alert(matches)', ' File "/usr/local/lib/python2.7/dist-packages/elastalert-0.0.84-py2.7.egg/elastalert/alerts.py", line 660, in alert', ' raise EAException("Error while running command %s: %s" % (\' \'.join(command), e))', 'EAException: Error while running command c u r l - X P O S T - H " C o n t e n t - T y p e : a p p l i c a t i o n / j s o n " " h t t p s : / / m y . e n d p o i n t " - d @ -: [Errno 2] No such file or directory'], 'data': {'rule': 'Google Microservice Error Alert'}}

In which it seems to be putting spaces in between every letter of my argument. Any thought on what is going on here??

Thanks!

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:14 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
Qmandocommented, May 11, 2018

@reswob10

  • Don’t use [ ] if you aren’t going to split up the command. Just keep it as a string, and it will then be interpreted as a shell command.

  • What you posted is not valid YAML, you must have run elastalert with something else. You need to escape your DOUBLE quotes

  • You don’t need to escape single quotes, elastalert doesn’t escape them, and I’ve just verified that using

command: "curl -v -k 'http://localhost:14901/foo' -d '{\"event\": \"blah\"}'"

works perfectly

1reaction
Qmandocommented, Jun 21, 2016

Ah, yeah the one string method is not correct unless shell=True is also passed, which it isnt. You should be using a list to run commands as arguments.

alert:
- command:
    command: ["curl", "-XPOST", "-H" "\"Content-Type: application/json\"", "\"https://my.endpoint\"", "-d@-"]
pipe_match_json: true 
Read more comments on GitHub >

github_iconTop Results From Across the Web

Using the Work with Alerts command - IBM
Type WRKALR on any command line and press the Enter key. Press F11 (Display user/group) to show the problem IDs associated with the...
Read more >
Advanced Alert Issues - THWACK Community Discussions
When I edit an existing advanced alert, I get the following error. pastedImage_1.png. I am adding the Group Name line, and I get...
Read more >
Managing Faults, Defects, and Alerts in Oracle® Solaris 11.4
Use the fmadm list-alert command to list all alerts that have not been cleared. See Displaying Information About Alerts for example output from...
Read more >
Cloudbot Common Problems & Solutions - Streamlabs
Cloudbot Common Problems & Solutions ... Ensure you have an Alert Box in every scene of your collection (or launch ... Commands Not...
Read more >
Alert handlers - Responding to problems automatically
Alert handlers really become useful when they execute a command on the target host. Checkmk offers a ready solution for Linux that will...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found