# openbmc/phosphor-sel-logger architecture

> Architecture diagram of the GitHub repository openbmc/phosphor-sel-logger, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/openbmc/phosphor-sel-logger
- Repository: https://github.com/openbmc/phosphor-sel-logger

## Overview

##### Project type and purpose
- This is a Linux system daemon (“phosphor-sel-logger”) written in C++ with Meson build files.
- It exposes a D-Bus API for adding IPMI SEL records and embeds a collection of “event monitor” plugins that watch for D-Bus signals (e.g., sensor threshold changes) to auto-log SEL entries into the systemd journal.

##### File structure
- Top-level meson.build & meson.options: build definition for the daemon and its vendored dependencies.
- /: headers for the core SEL logger and each EventMonitor subclass (threshold, pulse, watchdog, host-error, threshold-alarm).
- src/sel_logger.cpp: the main daemon logic (initialization, D-Bus interface, plugin registration, journal calls).
- service_files/xyz.openbmc_project.Logging.IPMI.service: systemd unit that starts the daemon.
- subprojects/: vendored wraps for Boost, sdbusplus (D-Bus bindings), and phosphor-logging (journal client).

##### Extract README insights
- The daemon registers a D-Bus interface to accept System-type and OEM-type SEL records (adding metadata fields, automatically generating MESSAGE_ID and RECORD_ID).
- It also instantiates EventMonitor objects that subscribe to D-Bus signals (e.g. PropertiesChanged on xyz.openbmc_project.Sensor.Threshold) and call the logging API when triggered.

a. External invokers & systems:
- systemd (launcher)
- D-Bus clients (IPMI management modules or CLI tools)
- Sensors & services on other D-Bus buses (xyz.openbmc_project.Sensor.* interfaces)
- systemd-journald (journal)
b. Internal SEL Logger Daemon:
- D-Bus server interface (“AddSystemSEL”, “AddOEMSEL” methods)
- EventMonitor Manager (factory/registry)
– ThresholdEventMonitor
– PulseEventMonitor
– WatchdogEventMonitor
– HostErrorEventMonitor
– ThresholdAlarmEventMonitor
- phosphor-logging client (wrap around sd_journal_send with MESSAGE_ID + metadata)
c. Vendored Libraries (build-time):
- sdbusplus – D-Bus C++ bindings
- phosphor-logging – Journal client helpers
- Boost – utilities

##### Relationships and data flows
2. SEL Logger registers its D-Bus interface (sdbusplus) on the bus.
6. On sensor events, monitors invoke SEL Logger’s internal logging routines → journald.

##### Architectural patterns & design principles
- Modular “plugin” monitors, each implementing a common interface (Observer pattern for D-Bus signals).
- Single-process daemon with separation of concerns: D-Bus API, event subscription, metadata construction, journald writing.
- Build-time vendoring isolates external dependencies (Boost, sdbusplus, phosphor-logging).

##### Final remarks
- Shared use of sdbusplus and phosphor-logging inside the daemon.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Components
    systemd["systemd (launcher)"]:::external
    dbus_clients["D-Bus Clients\n(IPMI modules/CLI)"]:::external
    sensor_services["Sensor Services\n(xyz.openbmc_project.Sensor.*)"]:::external
    journald["systemd-journald"]:::journal

    %% SEL Logger Daemon Subgraph
    subgraph "SEL Logger Daemon"
        core_cpp["sel_logger.cpp"]:::daemon
        core_hpp["sel_logger.hpp"]:::daemon
        dbus_iface["D-Bus Interface\n(AddSystemSEL, AddOEMSEL)"]:::daemon
        mgr["EventMonitorManager"]:::daemon
        journal_client["Journal Client\n(phosphor-logging)"]:::daemon
        subgraph "Event Monitors"
            thresh["ThresholdEventMonitor"]:::daemon
            alarm["ThresholdAlarmEventMonitor"]:::daemon
            pulse["PulseEventMonitor"]:::daemon
            watchdog["WatchdogEventMonitor"]:::daemon
            hosterr["HostErrorEventMonitor"]:::daemon
        end
    end

    %% Vendored Libraries
    subgraph "Vendored Libraries"
        boost["Boost"]:::vendored
        sdbusplus["sdbusplus"]:::vendored
        phlog["phosphor-logging"]:::vendored
    end

    %% Build Configuration
    meson_build["meson.build"]:::vendored
    meson_options["meson.options"]:::vendored
    service_file["Logging.IPMI.service"]:::external

    %% Connections - Service Launch & API Calls
    systemd -->|"starts service"| core_cpp
    core_cpp -->|"initializes"| core_hpp
    core_cpp -->|"registers"| dbus_iface
    dbus_clients -->|"AddSystemSEL()/AddOEMSEL() call"| dbus_iface
    dbus_iface -->|"invoke logging"| journal_client
    journal_client -->|"send Journal Entry"| journald

    %% Vendored Usage
    core_cpp --> boost
    core_cpp --> sdbusplus
    core_cpp --> phlog
    mgr --> sdbusplus
    dbus_iface --> sdbusplus
    journal_client --> phlog

    %% Event Monitor Creation & Subscriptions
    core_cpp --> mgr
    mgr --> thresh
    mgr --> alarm
    mgr --> pulse
    mgr --> watchdog
    mgr --> hosterr

    sensor_services -.->|"PropertiesChanged signal"| thresh
    sensor_services -.-> alarm
    sensor_services -.-> pulse
    sensor_services -.-> watchdog
    sensor_services -.-> hosterr

    thresh -->|"log SEL"| journal_client
    alarm --> journal_client
    pulse --> journal_client
    watchdog --> journal_client
    hosterr --> journal_client

    %% Service & Build Files
    systemd -->|"service file"| service_file
    service_file --> core_cpp
    meson_build --> core_cpp
    meson_options --> core_cpp

    %% Click Events
    click core_cpp "https://github.com/openbmc/phosphor-sel-logger/blob/master/src/sel_logger.cpp"
    click core_hpp "https://github.com/openbmc/phosphor-sel-logger/blob/master/include/sel_logger.hpp"
    click mgr "https://github.com/openbmc/phosphor-sel-logger/blob/master/include/sensorutils.hpp"
    click thresh "https://github.com/openbmc/phosphor-sel-logger/blob/master/include/threshold_event_monitor.hpp"
    click alarm "https://github.com/openbmc/phosphor-sel-logger/blob/master/include/threshold_alarm_event_monitor.hpp"
    click pulse "https://github.com/openbmc/phosphor-sel-logger/blob/master/include/pulse_event_monitor.hpp"
    click watchdog "https://github.com/openbmc/phosphor-sel-logger/blob/master/include/watchdog_event_monitor.hpp"
    click hosterr "https://github.com/openbmc/phosphor-sel-logger/blob/master/include/host_error_event_monitor.hpp"
    click service_file "https://github.com/openbmc/phosphor-sel-logger/blob/master/service_files/xyz.openbmc_project.Logging.IPMI.service"
    click meson_build "https://github.com/openbmc/phosphor-sel-logger/blob/master/meson.build"
    click meson_options "https://github.com/openbmc/phosphor-sel-logger/blob/master/meson.options"
    click boost "https://github.com/openbmc/phosphor-sel-logger/blob/master/subprojects/boost.wrap"
    click sdbusplus "https://github.com/openbmc/phosphor-sel-logger/blob/master/subprojects/sdbusplus.wrap"
    click phlog "https://github.com/openbmc/phosphor-sel-logger/blob/master/subprojects/phosphor-logging.wrap"

    %% Styles
    classDef external fill:#cccccc,stroke:#333,stroke-width:1px
    classDef daemon fill:#cce5ff,stroke:#004085,stroke-width:1px
    classDef vendored fill:#d4edda,stroke:#155724,stroke-width:1px
    classDef journal fill:#ffe5b4,stroke:#994d00,stroke-width:1px
```
