elastalert icon indicating copy to clipboard operation
elastalert copied to clipboard

Problem to execute enhancement

Open leandrob04 opened this issue 9 years ago • 25 comments

Hello, I am trying to perform an enhancement to fix the timestamp, as suggested in issue #1047, but I am not able to run the enhancement. error

leandrob04 avatar Jun 25 '17 23:06 leandrob04

Try touch modules/__init__.py

Qmando avatar Jun 26 '17 20:06 Qmando

This file already exists, and I have reviewed the mach_enhancements parameter of the rules several times. Any suggestions to solve this problem?

Thanks.

leandrob04 avatar Jun 27 '17 02:06 leandrob04

I think syntax errors can cause this. Try running the file manually: python modules/Time.py

Qmando avatar Jun 27 '17 18:06 Qmando

I ran this command but didn't get any debugging. Do you have other suggestions to solve this problem?

leandrob04 avatar Jun 27 '17 18:06 leandrob04

Could it be anything related to the version?

I tested the same enhancement on a machine that had version 0.1.8 and worked.

leandrob04 avatar Jun 29 '17 17:06 leandrob04

You need to be in the directory where the modules folder is. It looks from your prompt like you are in the rules folder.

Qmando avatar Jun 29 '17 17:06 Qmando

I am not able to perform any enhancements all are giving this problem of not finding the file.

Any suggestion?

leandrob04 avatar Jun 30 '17 18:06 leandrob04

Are you running elastalert from the same directory that modules folder is in?

You should be able to run python -c "from modules import Test"

Qmando avatar Jun 30 '17 18:06 Qmando

There was no problem with the command.

teste1

leandrob04 avatar Jun 30 '17 19:06 leandrob04

Have you got modules.Time.TimeEnhancement or modules.time_real.TimeEnhancement ?

I'm not sure what issues would cause "No module named ..." error other than:

  1. Not in the current directory
  2. No __init__.py
  3. Wrong name of folder
  4. Wrong name of .py file

Qmando avatar Jun 30 '17 20:06 Qmando

In case, I modified the enhancement name only Time.py -> time_real.py, but all its points about the possible problem is really strange what is happening. It really is weird. I've been doing a few more tests and when I had a machine with version 0.1.8 it worked perfectly, when I upgraded to the latest one then it started this problem again.

Is there another way to call an enhancement?

Thanks for help!

leandrob04 avatar Jun 30 '17 23:06 leandrob04

There is actually. I had completely forgotten about this, but if you just put "TimeEnhancement" into elastalert's enhacnements.py, it should load. Then you set the match_enhancements: ["TimeEnhancement"]

You can find the location of that file with python -c "from elastalert import enhancements; print enhancements.__file__"

Qmando avatar Jun 30 '17 23:06 Qmando

You can also test this out manually using the simple code from https://github.com/Yelp/elastalert/blob/master/elastalert/config.py#L87

Maybe it will yield some clues as to what is happening

$ python
>>> module_name = "modules.time_real.TimeEnhancement"
>>> module_path, module_class = module_name.rsplit('.', 1)
>>> base_module = __import__(module_path, globals(), locals(), [module_class])
>>> module = getattr(base_module, module_class)

Qmando avatar Jun 30 '17 23:06 Qmando

Very strange the result.

teste2

leandrob04 avatar Jun 30 '17 23:06 leandrob04

I edited the comment, sorry about that! module_name = "modules...." not name =

Qmando avatar Jun 30 '17 23:06 Qmando

There was no mistake

teste2

leandrob04 avatar Jun 30 '17 23:06 leandrob04

What the heck... I'm out of ideas. Check for typos?

Try putting the code into elastalert's enhancements.py like I suggested. Hopefully that works!

Qmando avatar Jun 30 '17 23:06 Qmando

Man, now it worked. I don't know what its happen, but I execute the rules and it's worked Thanks

leandrob04 avatar Jun 30 '17 23:06 leandrob04

😌

Qmando avatar Jun 30 '17 23:06 Qmando

Hello I added the enhancement code to /usr/local/elastalert/lib/python2.7/site-packages/elastalert/enhancements.py

from elastalert.util import pretty_ts
from elastalert.enhancements import BaseEnhancement

class TimeEnhancement(BaseEnhancement):
    def process(self, match):
        match['@timestamp'] = pretty_ts(match['@timestamp'])

However my alert timestamps still come through as UTC, an hour behind local time.

kernelpanicfbsd avatar Aug 03 '17 09:08 kernelpanicfbsd