read_history_events
サーバー側がイベント履歴(HistoryRead Events)を記録している場合、クライアント側は時間範囲を指定して過去のイベントを取得することができます。
付属品
- リアルタイムイベントの購読には、以下をご利用ください イベントの購読.
- 過去の変数データについては、以下をご利用ください。 read_history (Raw) / read_history_processed.
署名
def read_history_events(self,
node_id: str,
start_utc: datetime,
end_utc: datetime,
max_events: int = 0) -> List[HistoryEventArgs]: ...
node_id 通常は i=2253 (Server ノード) またはカスタム EventNotifier ノードです。max_events=0 件数に制限がないことを示します。空 node_id の文字列は例外をスローします ValueError。
HistoryEventArgs
@dataclass
class HistoryEventArgs:
severity: int = 0
message: Optional[str] = None
source_name: Optional[str] = None
time: Optional[datetime] = None
event_type: Optional[str] = None
フィールドの意味が同じ EventArrivedEventArgs, ただし、ライフサイクルはリストへの格納期間に相当する(マネージドであるため、disposeは必要ない)。
4つの標準が組み込まれています SelectClauses: Severity / Message / SourceName / Time.
使用方法
import datetime as dt
now = dt.datetime.now(dt.timezone.utc)
events = ua.read_history_events(
"i=2253",
start_utc=now - dt.timedelta(days=1),
end_utc=now)
for e in events:
print(f"[{e.severity}] {e.source_name}: {e.message} @ {e.time}")
カスタマイズ EventFilter
read_history_events 受け付けませんカスタム SelectClauses / EventFilter パラメータ、固定で組み込みの4つのフィールドを使用します。 EventType / 深刻度でフィルタリングしたい場合は、結果を取得してから自分で絞り込む必要があります。
カスタム EventFilter のエントリポイントは です( EventSubscription.subscribe(node_id, event_filter=...) 高度な使い方については、 イベントの購読), リアルタイムのイベント購読にのみ適用され、履歴の読み取りには適用されません。
サーバー側の要件
- 必須のサポート対象:Events HistoryRead (サーバー側の ServerCapabilities フラグ)
- イベント送信元ノードでは、EventNotifier属性 (12) のビット1 (HistoryRead) がセットされている必要があります。
リアルタイムイベントの購読との関係
| API | 何を持っていくか |
|---|---|
| subscribe_events(...) | リアルタイムイベント(購読期間中に発生したもの) |
| read_history_events(...) | 履歴上のイベント(サーバーにアーカイブされたもの) |
一般的な組み合わせ:起動時に24時間分 read_history_events を引き継ぎ、その後リアルタイム subscribe_events で引き継ぐ。