Getting "'__name__' not in globals" when updating custom plugins for 2.0

163 views Asked by At

I have updated my check_mk from 1.6.x to 2.0.x

My custom omd-plugins got messed up and so I started to refactor them for the new 2.0 API with the help of this article.

However, when the time for testing came, I got this:

OMD[my_omd]:~$ cmk --detect-plugins=my_plugin -vI my_host.my_company.de
Error in plugin file /omd/sites/my_omd/local/share/check_mk/checks/my_plugin: "'__name__' not in globals"
1

There are 1 answers

1
Chris On BEST ANSWER

I was using sym-links.

For source-control, I have a git-repo. I had put sym-links pointing from the old checks-directory back to the plugin-file in that repo. Starting through the above mentioned guide, I created a new sym-link from the new local/lib/check_mk/base/plugins/agent_based/. Adding the required .py suffix in the process. So now I have 2 sym-links pointing to one piece of code, which I had modified in-place.

Turns out: If you do not delete the plugin from the old location, you will always test the old plugin. With sym-links, you will test the new code in the old environment, giving you that error.

Notice the path in the error-message!

As for the __name__ error itself: It seems to come from doing relative imports import .something. Notice the leading dot. It means "in the same directory as this file". Somehow the old environment was not able to cope with that.