elastalert icon indicating copy to clipboard operation
elastalert copied to clipboard

elastalert-test-rule error

Open anragen opened this issue 7 years ago • 17 comments

/opt/elastalert$ sudo elastalert-create-index Elastic Version: 7.3.0 Reading Elastic 6 index mappings: Reading index mapping 'es_mappings/6/silence.json' Reading index mapping 'es_mappings/6/elastalert_status.json' Reading index mapping 'es_mappings/6/elastalert.json' Reading index mapping 'es_mappings/6/past_elastalert.json' Reading index mapping 'es_mappings/6/elastalert_error.json' New index elastalert_status created Done! /opt/elastalert$ sudo vim example_rules/example_frequency.yaml /opt/elastalert$ sudo elastalert-test-rule example_rules/example_frequency.yaml Traceback (most recent call last): File "/usr/local/bin/elastalert-test-rule", line 11, in load_entry_point('elastalert==0.2.1', 'console_scripts', 'elastalert-test-rule')() File "/usr/lib/python2.7/dist-packages/pkg_resources/init.py", line 480, in load_entry_point return get_distribution(dist).load_entry_point(group, name) File "/usr/lib/python2.7/dist-packages/pkg_resources/init.py", line 2693, in load_entry_point return ep.load() File "/usr/lib/python2.7/dist-packages/pkg_resources/init.py", line 2324, in load return self.resolve() File "/usr/lib/python2.7/dist-packages/pkg_resources/init.py", line 2330, in resolve module = import(self.module_name, fromlist=['name'], level=0) File "/usr/local/lib/python2.7/dist-packages/elastalert-0.2.1-py2.7.egg/elastalert/test_rule.py", line 61 print('Invalid filter provided:', str(ea), file=sys.stderr) ^ SyntaxError: invalid syntax

anragen avatar Aug 12 '19 11:08 anragen

@anragen try to install setup by python3 (it worked for me).

Same issue : https://github.com/Yelp/elastalert/issues/2390

prabhuverse avatar Aug 12 '19 18:08 prabhuverse

@anragen try to install setup by python3 (it worked for me).

Same issue : #2390

tanx but i did sudo apt-get install python3-minimal sudo apt-get install python3-pip python3-dev libffi-dev libssl-dev sudo python3 setup.py install and get

$ sudo elastalert-test-rule example_rules/example_frequency.yaml
Traceback (most recent call last):
  File "/usr/local/bin/elastalert-test-rule", line 11, in <module>
    load_entry_point('elastalert==0.2.1', 'console_scripts', 'elastalert-test-rule')()
  File "/usr/local/lib/python3.6/dist-packages/elastalert-0.2.1-py3.6.egg/elastalert/test_rule.py", line 445, in main
    test_instance.run_rule_test()
  File "/usr/local/lib/python3.6/dist-packages/elastalert-0.2.1-py3.6.egg/elastalert/test_rule.py", line 412, in run_rule_test
    conf = load_conf(args, defaults, overwrites)
  File "/usr/local/lib/python3.6/dist-packages/elastalert-0.2.1-py3.6.egg/elastalert/config.py", line 44, in load_conf
    conf = yaml_loader(filename)
  File "/usr/local/lib/python3.6/dist-packages/PyStaticConfiguration-0.10.4-py3.6.egg/staticconf/loader.py", line 167, in yaml_loader
    with open(filename) as fh:
TypeError: expected str, bytes or os.PathLike object, not NoneType

anragen avatar Aug 13 '19 06:08 anragen

me too python3 /usr/bin/elastalert-test-rule /data/elk/elastalert-master/example_rules/example_frequency.yaml

Traceback (most recent call last):
  File "/usr/bin/elastalert-test-rule", line 8, in <module>
    load_entry_point('elastalert==0.2.1', 'console_scripts', 'elastalert-test-rule')()
  File "/usr/local/lib/python3.6/site-packages/elastalert/test_rule.py", line 445, in main
    test_instance.run_rule_test()
  File "/usr/local/lib/python3.6/site-packages/elastalert/test_rule.py", line 412, in run_rule_test
    conf = load_conf(args, defaults, overwrites)
  File "/usr/local/lib/python3.6/site-packages/elastalert/config.py", line 44, in load_conf
    conf = yaml_loader(filename)
  File "/usr/local/lib/python3.6/site-packages/staticconf/loader.py", line 167, in yaml_loader
    with open(filename) as fh:
TypeError: expected str, bytes or os.PathLike object, not NoneType

zhanghan12 avatar Aug 13 '19 09:08 zhanghan12

I'm sorry, there was a regression here. I clearly wasn't very carful when merging https://github.com/Yelp/elastalert/pull/2030/files. You need to pass --config too, where it used to default to checking for "config.yaml". I'll fix this asap.

Qmando avatar Aug 13 '19 17:08 Qmando

I've just fixed this in master: https://github.com/Yelp/elastalert/commit/3affdd7ebf2b6d82c5cfcad0092df97dc27cd8b1

Qmando avatar Aug 13 '19 17:08 Qmando

@Qmando thank you so much! it worked.

@zhanghan12 example : elastalert-test-rule --config config.yaml example_rules/example_frequency.yaml which worked for me.

prabhuverse avatar Aug 13 '19 18:08 prabhuverse

I've just fixed this in master: 3affdd7

git pull sudo elastalert-test-rule --config config.yaml example_rules/example_frequency.yaml the same error

anragen avatar Aug 14 '19 06:08 anragen

I'm also getting the same error while running the command : sudo elastalert-test-rule --config config.yaml example_rules/example_frequency.yaml

Installed python version 3.6 root@XXX:/tmp/elastalert/example_rules# python --version Python 3.6.8

root@XXX:/tmp/elastalert/example_rules# sudo elastalert-test-rule --config config.yaml example_frequency.yaml Traceback (most recent call last): File "/usr/local/bin/elastalert-test-rule", line 11, in load_entry_point('elastalert==0.2.1', 'console_scripts', 'elastalert-test-rule')() File "/usr/local/lib/python3.6/dist-packages/elastalert-0.2.1-py3.6.egg/elastalert/test_rule.py", line 445, in main test_instance.run_rule_test() File "/usr/local/lib/python3.6/dist-packages/elastalert-0.2.1-py3.6.egg/elastalert/test_rule.py", line 412, in run_rule_test conf = load_conf(args, defaults, overwrites) File "/usr/local/lib/python3.6/dist-packages/elastalert-0.2.1-py3.6.egg/elastalert/config.py", line 44, in load_conf conf = yaml_loader(filename) File "/usr/local/lib/python3.6/dist-packages/PyStaticConfiguration-0.10.4-py3.6.egg/staticconf/loader.py", line 167, in yaml_loader with open(filename) as fh: FileNotFoundError: [Errno 2] No such file or directory: 'config.yaml'

jpsampat avatar Aug 19 '19 13:08 jpsampat

@jpsampat : seems like you are not mentioning example_frequency.yaml path It should be like $elastalert-test-rule --config config.yaml example_rules/example_frequency.yaml and Make sure in elastalert directory : config.yaml exists

prabhuverse avatar Aug 19 '19 16:08 prabhuverse

@prabhur24 : I'm getting the same error after mentioning the proper path even I have checked the config.yaml file also and it's present at the location. Plz check the below outputs.

Path of the config.yaml location ubuntu@XXX:/opt/elastalert$ ls Dockerfile-test Makefile build config.yaml dist docs elastalert.egg-info pytest.ini requirements.txt setup.py tests LICENSE README.md changelog.md config.yaml.example docker-compose.yml elastalert example_rules requirements-dev.txt setup.cfg supervisord.conf.example tox.ini ubuntu@XXX::/opt/elastalert$

Command ran with the proper path.

ubuntu@XXX::/opt/elastalert$ elastalert-test-rule --config config.yaml example_rules/example_frequency.yaml INFO:elastalert:Note: In debug mode, alerts will be logged to console but NOT actually sent. To send them but remain verbose, use --verbose instead. Traceback (most recent call last): File "/usr/local/bin/elastalert-test-rule", line 11, in load_entry_point('elastalert==0.2.1', 'console_scripts', 'elastalert-test-rule')() File "/usr/local/lib/python3.6/dist-packages/elastalert-0.2.1-py3.6.egg/elastalert/test_rule.py", line 445, in main test_instance.run_rule_test() File "/usr/local/lib/python3.6/dist-packages/elastalert-0.2.1-py3.6.egg/elastalert/test_rule.py", line 412, in run_rule_test conf = load_conf(args, defaults, overwrites) File "/usr/local/lib/python3.6/dist-packages/elastalert-0.2.1-py3.6.egg/elastalert/config.py", line 96, in load_conf rules_loader = rules_loader_class(conf) File "/usr/local/lib/python3.6/dist-packages/elastalert-0.2.1-py3.6.egg/elastalert/loaders.py", line 94, in init yaml.load(open(os.path.join(os.path.dirname(file), 'schema.yaml')), Loader=yaml.FullLoader)) AttributeError: module 'yaml' has no attribute 'FullLoader'

Please check and revert, any further help would be grateful. Thanks.

jpsampat avatar Aug 20 '19 07:08 jpsampat

Issue got resolved buy upgrading PyYAML from 3 to 5.1.2

jpsampat avatar Aug 20 '19 10:08 jpsampat

hi, have error on sudo elastalert-create-index root@hq-elk-k:/opt/elastalert# sudo elastalert-create-index Enter Elasticsearch host: hq-elk-es01 Traceback (most recent call last): File "/usr/local/bin/elastalert-create-index", line 11, in <module> load_entry_point('elastalert==0.2.1', 'console_scripts', 'elastalert-create-index')() File "/usr/local/lib/python2.7/dist-packages/elastalert-0.2.1-py2.7.egg/elastalert/create_index.py", line 215, in main host = args.host if args.host else input('Enter Elasticsearch host: ') File "<string>", line 1, in <module> NameError: name 'hq' is not defined also tried with --config and actual config path with localhost with 127.0.0.1 etc no luck

P.S have upgraded PyYAML

can somebody help?

creatoni4 avatar Sep 09 '19 15:09 creatoni4

ok found this #1077 and think setuptools related somehow.

i setup.py again and now error:

Installed /usr/local/lib/python3.5/dist-packages/elastalert-0.2.1-py3.5.egg
Processing dependencies for elastalert==0.2.1
Searching for setuptools>=20.10.1
Reading https://pypi.python.org/simple/setuptools/
Best match: setuptools 41.2.0
Downloading https://files.pythonhosted.org/packages/d9/ca/7279974e489e8b65003fe618a1a741d6350227fa2bf48d16be76c7422423/setuptools-41.2.0.zip#sha256=66b86bbae7cc7ac2e867f52dc08a6bd064d938bac59dfec71b9b565dd36d6012
Processing setuptools-41.2.0.zip
Writing /tmp/easy_install-_a1lpnma/setuptools-41.2.0/setup.cfg
Running setuptools-41.2.0/setup.py -q bdist_egg --dist-dir /tmp/easy_install-_a1lpnma/setuptools-41.2.0/egg-dist-tmp-z_bed_2e
warning: no previously-included files found matching 'pyproject.toml'
warning: install_lib: 'build/lib' does not exist -- no Python modules to install

zip_safe flag not set; analyzing archive contents...
Removing /usr/local/lib/python3.5/dist-packages/UNKNOWN-0.0.0-py3.5.egg
Moving UNKNOWN-0.0.0-py3.5.egg to /usr/local/lib/python3.5/dist-packages
UNKNOWN 0.0.0 is already the active version in easy-install.pth
Installing easy_install-3.5 script to /usr/local/bin
Installing easy_install script to /usr/local/bin

Installed /usr/local/lib/python3.5/dist-packages/UNKNOWN-0.0.0-py3.5.egg
error: The 'setuptools>=20.10.1' distribution was not found and is required by jira

but its installed

root@hq-elk-k:/opt/elastalert# sudo pip install setuptools Requirement already satisfied: setuptools in /usr/lib/python3/dist-packages (20.7.0)

creatoni4 avatar Sep 09 '19 16:09 creatoni4

ok found the problem...

need to upgrade setuptools: python3 -m pip install --upgrade pip setuptools wheel

creatoni4 avatar Sep 09 '19 16:09 creatoni4

I'm getting the same error as OP. Was there any solution found?

elastalert-test-rule --config config.yaml example_rules/example_frequency.yaml Traceback (most recent call last): File "/usr/local/bin/elastalert-test-rule", line 11, in <module> load_entry_point('elastalert==0.2.1', 'console_scripts', 'elastalert-test-rule')() File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 489, in load_entry_point return get_distribution(dist).load_entry_point(group, name) File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 2793, in load_entry_point return ep.load() File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 2411, in load return self.resolve() File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 2417, in resolve module = __import__(self.module_name, fromlist=['__name__'], level=0) File "/usr/local/lib/python2.7/dist-packages/elastalert-0.2.1-py2.7.egg/elastalert/test_rule.py", line 61 print('Invalid filter provided:', str(ea), file=sys.stderr) ^ SyntaxError: invalid syntax

Mfisher925 avatar Sep 19 '19 19:09 Mfisher925

@Mfisher925 have you tried to comment out jira staff in .local/lib/python3.8/site-packages/elastalert/alerts.py?

#from jira.client import JIRA
#from jira.exceptions import JIRAError
JIRAError = KeyError

This worked for me

kz159 avatar Mar 25 '20 14:03 kz159

@Mfisher925 have you tried to comment out jira staff in .local/lib/python3.8/site-packages/elastalert/alerts.py?

#from jira.client import JIRA
#from jira.exceptions import JIRAError
JIRAError = KeyError

This worked for me

I had not, I ended up using a compatible version of python 3.6 with virtualenv. I'll try this on my lab version I'm creating now. Thanks!

Mfisher925 avatar Mar 25 '20 14:03 Mfisher925