Insights Core
Insights Core is a data collection and analysis framework built for extensibility and rapid development. It allows users to create components that collect and transform raw system data into typed Python objects, which are then used in rules to encapsulate knowledge. The library provides reusable components for various data gathering methods and offers a reliable object model for unstructured and semi-structured data. The project maintains an active release cadence, with weekly revisions and minor version bumps approximately every 25 revisions.
Common errors
-
Unable to fetch egg url ... 500: Internal Server Error. Defaulting to /release Machine-id found
cause The `insights-client` failed to download the `insights-core.egg` from the configured URL (often a Red Hat Satellite server) due to a server-side or network error.fixInspect the Satellite server logs for specific errors. Verify network connectivity from the client to the Satellite server. If applicable, try unregistering and re-registering the `insights-client` using `insights-client --unregister`. -
insights-client --version shows an old Core version after client execution.
cause The `insights-client` might be caching the ETag for the `insights-core.egg` file, leading it to believe the local version is still current, thus not downloading a newer available version.fixDelete the ETag cache files, typically located at `/etc/insights-client/.insights-core.etag` and `/etc/insights-client/.insights-core.gpg-sig.etag`, then re-run `insights-client`. -
ImportError: No module named 'insights.core.dr' (or similar for other core modules)
cause The `insights-core` package is either not installed, or the Python environment where the script is being run does not have access to the installed package. This can happen in isolated virtual environments.fixEnsure `insights-core` is installed in the active Python environment (`pip install insights-core`). If using a virtual environment, make sure it's activated before running the script. Verify the Python executable path.
Warnings
- deprecated Specific functions, class methods, and entire classes within `insights-core` are subject to deprecation. Refer to the 'Feature Deprecation' section in the official documentation for an 'insights-core release timeline' to see which features will be removed in upcoming minor versions.
- gotcha When using `insights-client` to update `insights-core`, the client might not download the latest core egg due to persistent ETags, leading to an outdated core version despite successful client execution.
- gotcha Users often encounter '500: Internal Server Error' when `insights-client` attempts to fetch the `insights-core.egg` from a Red Hat Satellite server, particularly after Satellite upgrades. This can prevent the core from updating.
Install
-
pip install insights-core
Imports
- load_default_plugins
from insights import load_default_plugins, run
- run
from insights import load_default_plugins, run
- installed_rpms
from insights.parsers import installed_rpms as rpm
- dr
from insights.core import dr
Quickstart
from insights import load_default_plugins, run
from insights.parsers import installed_rpms as rpm
# Load all default insights components (parsers, combiners, rules)
load_default_plugins()
# Simulate running insights on a system and collect installed RPMs
# In a real scenario, `run()` would process collected data from a host or archive.
# For this example, we'll access the parser directly, typically data comes via contexts.
# To get actual data, you would normally specify a context, e.g., HostContext
# Example of getting parsed data (conceptual, run() works with a Broker context)
# Normally, the run() call would fill the broker with data from all active components.
# For a local execution, you might run `insights-run` CLI or use specific contexts.
# Let's illustrate with a simple check using a known parser output.
# In a programmatic usage, `run()` is typically invoked on a Broker.
# This example is adapted from the PyPI description.
# The 'run' function typically takes a list of components or a Broker instance.
# For a simple local check without a full host context setup:
# If you were running against a system, 'run()' would implicitly collect data.
# For a quick local check on a parser, you'd feed it content.
# The example from PyPI is more illustrative of using the *results* from a run.
# This is a conceptual example based on docs, actual `run()` requires a context or data feed.
# A direct `run()` call will gather data based on active contexts (e.g., HostContext by default).
results = run(rpm.Installed)
# Accessing the parsed RPM data from the results
if rpm.Installed in results:
installed_rpms_data = results[rpm.Installed]
print(f"Newest bash version: {installed_rpms_data.newest('bash')}")
else:
print("Installed RPMs data not found in results.")
# Note: To run this against actual system data, `insights-core` typically
# works with data collected by `insights-client` or processed via specific contexts.
# A simple `run()` without explicit context uses the default HostContext if available.