Insights Core

3.7.5 · active · verified Thu Apr 16

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

Warnings

Install

Imports

Quickstart

Initializes insights-core by loading default plugins (parsers, combiners, rules) and then demonstrates how to execute components to gather and analyze data, such as finding the newest version of a package. In a full system, `run()` would operate within a specific context (e.g., a live host or an archive) to collect and process data.

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.

view raw JSON →