机器上线时的 WMI 事件

发布于 2024-07-08 05:48:38 字数 106 浏览 8 评论 0原文

是否有您可以订阅的 WMI 事件,该事件会在远程计算机启动并联机或脱机时触发?

我的应用程序需要能够监视机器的可用性,理想情况下,我想要一些可以通过事件而不是连续轮询工作的东西。

Is there a WMI event you can subscribe to that will fire when a remote machine boots up and comes online, or goes offline?

My application needs to be able to monitor machines for their availability, and ideally, I'd like something that can work via events instead of continuous polling.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

倥絔 2024-07-15 05:48:38

理论上可以订阅关闭事件。 您可以订阅以获取“系统”事件日志的更新。 您将从 Source =“EventLog”和 EventID = 6006 中查找事件。此事件包含以下消息:

事件日志服务已停止。

这通常是关机时写入的最后一条消息。 可是等等! 通过 WMI 接收此信息可能会出现问题。 为什么? WMI 服务本身可能会在 EventLog 之前关闭,因此它可能是第 22 条军规。您可能会查找在您监视的服务器上关闭期间早些时候出现的另一条消息,并注意该消息。

启动事件伴随着一组更麻烦的第 22 条军规。 考虑一下 WMI 事件是如何工作的。 要获取事件,您必须通过 DCOM 打开到远程 WMI 服务器的连接,并发出 WQL 查询来指示您想要的事件。 为了接收启动事件,您必须“神奇地”知道在触发事件之前打开所述连接并发出所述查询。

几年前,我编写了一项服务,从远程服务器收集事件日志条目以用于网络监控应用程序。 检测与遥控器的 DCOM 连接何时丢失并需要重建的逻辑本身就是一大难题。 碰巧这是一个大型系统中的一个组件,无论如何都会对远程主机执行 ping 操作,因此我们最终依靠该信息来了解何时重建 DCOM 连接。

Subscribing to a shutdown event is theoretically possible. You could subscribe to get updates to the "System" Event Log. You'd be looking for an event from Source = "EventLog" and EventID = 6006. This event contains the message:

The Event log service was stopped.

This is usually the last message written on shutdown. But wait! It may be problematical to receive this via WMI. Why? It may be that the WMI service itself shuts down prior to EventLog so it might be a Catch 22. You could potentially look for another message that occurs earlier during shutdown on the servers you are monitoring, and watch for that.

A boot up event carries with it an even more troublesome set of Catch 22s. Think about how WMI eventing works for a moment. To get events, you have to open a connection to the remote WMI server via DCOM, and issue a WQL query to indicate what events you want. In order to receive a boot up event, you'd have to "magically" know to open said connection and issue said query prior to the event being fired.

Years ago I wrote a service that collected Event Log entries from remote servers for a network monitoring application. Just the logic to detect when the DCOM connection to the remote had been lost and needed to be rebuilt was a major pain in the neck. As it happened this was a component in a larger system that pinged the remote hosts anyway, so we ended up relying on that information to know when to rebuild our DCOM connections.

策马西风 2024-07-15 05:48:38

这些系统使用 DHCP 吗? 监视 DHCP 续订以查看系统何时恢复在线可能会更容易。

Are these systems on DHCP? It might be easier to monitor the DHCP renewals to see when a system is back online.

南笙 2024-07-15 05:48:38

仔细浏览 Microsoft 和其他站点并不会产生有关 WMI 中“启动”事件的任何信息。 但是,此 线程 建议在您想要的服务器上的启动文件夹中安装某些内容监视器。

A perusal around Microsoft's and other sites doesn't yield any information on a "boot" event in WMI. However, this thread suggests installing something in the startup folder on the server(s) you want to monitor.

半枫 2024-07-15 05:48:38

根据我的经验,这通常最好通过活动(轮询/ping/无论你怎么称呼它)来完成。

您不喜欢轮询怎么样? (一般来说,我同意您对大多数用途的轮询的厌恶,但在这种情况下,它可能是一个很好的解决方案)

至少您可以进行一些小型的轻量级轮询过程,然后在状态更改时向一组订阅者触发事件对于一台机器。

然后,如果您找到更好的解决方案,您就已经有了一个事件接口。

Typically from my experience this is done best with active (polling/pinging/whatever you want to call it)

What about the polling don't you like? (in general I share your dislike of polling for most uses, but this is a case where it is probably a good solution)

At the very least you can make some small lightweight polling process that then fires events to a set of subscribers when status changes for a machine.

Then if you find a better solution you already have an interface for events.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文