Description
Was hoping to use the "Diagnostic Walkthrough" instructions[1] to sample making a local insights rule, but I came a cropper.
I simply opened the Python interpreter and started entering the code. I ran the report and I got the following result
>>> results[report]
{'rule_fqdn': '__main__.report', 'reason': 'MISSING_REQUIREMENTS', 'details': "All: ['insights.parsers.installed_rpms.InstalledRpms'] Any: ", 'type': 'skip'}
As far as I can interpret this, the failure is due to some MISSING REQUIREMENTS. But, since I imported all the things that I was supposed to import, and certainly I imported InstalledRpms, it is hard for me to discover what I did wrong. I can run rpm -qa
without difficulty from the command-line, and get a bunch of results.
I see, at the bottom of the Diagnostic Walkthrough, that I am told that I should have jupyter-notebook installed. I installed that, but I still get the same problem. I am not actually running jupyter-notebook, but still using the Python interpreter.
Then I fell back on trying the example in the README[2]:
>>> from insights import run
>>> from insights.parsers import installed_rpms as rpm
>>> lower = rpm.Rpm("bash-4.4.11-1.fc26")
>>> upper = rpm.Rpm("bash-4.4.22-1.fc26")
>>> results = run(rpm.Installed)
>>> rpms = results[rpm.Installed]
>>> rpms.newest("bash")
0:bash-4.4.12-7.fc26
>>> lower <= rpms.newest("bash") < upper
True
but that didn't work out so well either:
>>> rpms = results[rpm.Installed]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.12/site-packages/insights/core/dr.py", line 949, in __getitem__
raise KeyError("Unknown component: %s" % get_name(component))
KeyError: 'Unknown component: insights.parsers.installed_rpms.InstalledRpms'
Turns out there is one item in results, just not accessible by the specified key:
>>> [x for x in results]
[<class 'insights.core.context.HostContext'>]
>>> [(x, y) for x, y in results.items()]
[(<class 'insights.core.context.HostContext'>, <HostContext('/', 30)>)]
>>> (key, value) = [(x, y) for x, y in results.items()][0]
>>> key
<class 'insights.core.context.HostContext'>
>>> value
<HostContext('/', 30)>
>>> type(key)
<class 'insights.core.context.ExecutionContextMeta'>
>>> type(value)
<class 'insights.core.context.HostContext'>
>>> value.newest
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'HostContext' object has no attribute 'newest'
At this point, I'm hoping for some help to figure out how to make the README example work for me.
I'm running this code on a Fedora 39 machine, and never tried on a Fedora 38 machine, so I can't compare.
Happy to provide additional information.
[1] https://github.com/RedHatInsights/insights-core/blob/master/docs/notebooks/Diagnostic%20Walkthrough.ipynb
[2] https://github.com/RedHatInsights/insights-core#readme