I want to take the rules that I am analyzing with a sensor

Hi, I’m making a sensor to detect rules with certain tags. I don’t want to use the API, because I would have to change the authentication parameters every time someone tries this plugin.

I am doing it this way:

As you can see what I do is take all the active rules with the sensor context.
And I use the RuleFinder so that it searches for the rule by the key and can assign it to a rule. With that I could already take his name, his tags etc.

But the problem is in the RuleFinder, which says that it is null.

I have tried without the Autowired annotation, with the annotation, putting @Component in this class. And it doesn’t work for me either.

When i do a scan it fails:

On line 39, where is the rf.

Please help!!!

Thanks in advance.


What language are you trying to write this for?

Also, have you considered that context.activeRules().findAll() may be returning an empty collection? I don’t see any length or nullness checks in there…


For Java.

The collection comes to me with information. Because I have tried to print the rules in this way
rule.ruleKey().rule() and it prints all the rules in this way: S6295,S6294…
I have also seen that the ruleFinder is deprecated.
How could I then get the tags from the rules? Without making API calls.

Hi @danisok,

Can you please explain what you are trying to achieve?

One possible solution could be to create Sensor with RuleFinder as a constructor parameter, in other words, to inject it.

I hope this helps.

All the best,