Saltstack 简明教程
SaltStack - Event system
Salt 中的事件系统是一个本地的 ZeroMQ PUB 接口,用于触发 Salt 事件。以下组件会执行事件系统:
The event system in Salt is a local ZeroMQ PUB interface, which fires salt events. It is performed by the following components.
-
Event Sockets − It is used to publish events.
-
Event library − It is used to listen to events and send the events into the salt system.
Salt Master Event
Salt Master 提供了不同的事件类型,如下详细说明:
A Salt master provides different types of events, which are explained in detail below −
-
Authentication events
-
Start events
-
Key events
-
Job events
-
Runner Events
-
Presence Events
-
Cloud Events
让我们详细了解每种事件类型。
Let us go through each of the event types in detail.
Authentication Events
当 Minion 对 Master 执行身份验证检查时,将触发这些身份验证事件。事件由 salt/auth 表示。
These authentication events fire when a minion performs an authentication check with the master. It is represented by salt/auth.
Start Events
每次 Minion 连接到 Salt Master 时,都会触发开始事件,事件由 salt/minion//start 表示。
The start events fire whenever a minion connects to the Salt master and it is represented by salt/minion//start.
Key Events
当 Salt Master 在 Salt Minion 上接受和拒绝密钥时,将触发密钥事件。可以使用 salt-key 命令访问此事件。
The Key events are fired when the salt master is accepting and rejecting keys on the Salt minion. You can access this event using the salt-key command.
Job Events
每次将开始新作业时,都会触发作业事件。它由 salt/job//new 表示。其中,JID - 作业 ID,new - 新作业。
A Job event is fired whenever a new job is going to start. It is represented by salt/job//new. Here, JID - Job id new - new job
Runner Events
当 Runner 开始执行时,会触发 Runner 事件。事件由 salt/run//new 表示。
When a runner begins execution, a runner event is fired. It is represented by salt/run//new.
Presence Events
当 Minion 已连接、新建连接或断开连接时,会定期触发此事件。由 salt/presence/present 和 salt/presence/change 表示。其中,
When minions are connected or newly connected or disconnected, this event is fired on a regular interval. It is represented by – salt/presence/present and salt/presence/change. Here,
-
Present − means the Salt master is currently connected to the minions list.
-
Change − used to detect a new minion – connected or disconnected.
Cloud Events
Salt-Cloud 事件在虚拟机上触发。它不会在 Minion 上执行,除非其他事件会执行。可以使用 salt/cloud//creating 访问此事件。当 Salt Cloud 启动虚拟机执行过程时,会触发此事件。
The salt-cloud events are fired on a virtual machine. Unless other events, it is not performed on the minion. You can access it using – salt/cloud//creating. It is fired when a Salt cloud starts the virtual machine execution process.
Event Tools
现在,让我们了解事件工具和脚本。可以使用 CLI 访问事件总线。通过以下命令进行访问。
Now, let us go through the event tools and scripts. You can access the event bus using CLI. It is accessed by the following command.
salt-run state.event pretty = True
在这里,运行程序设计为从外部工具和 shell 脚本与事件总线进行交互。可通过 REST API 远程访问 Salt 的事件总线。以 – (示例 URL) 表示。
Here, the runner is designed to interact with the event bus from external tools and shell scripts. Salt’s event bus can be accessed remotely via the REST API. It is represented by – (sample URL).
curl -SsNk https://salt-api.example.com:8000/events?token = 05A3.
同样,您还可以从 Python 脚本访问事件。
Similarly, you can access events from the Python scripts as well.