Simplest way to test if a recorder is offline?

Hello,

Currently I figured out on my own that to test if a recorder is offline I can use this:

private static bool IsRecorderOnline(Item recorder)
  try{
    var client = new VideoOS.Platform.SDK.Proxy.Status2.RecorderStatusService2(recorder.FQID.ServerId.Uri);
    var test = client.GetVersion();
    return true;
  }
  catch(Exception ex)
  {
      return false;
  }
}

Is there a better way? If not, to get the test to work faster I’d modify the Timeout property on the client?

Kind regards,

Philippe

Hi Philippe,

In MilestonePSTools I’m using MessageCommunicationManager in the Get-ItemState cmdlet to subscribe to the “ProvideCurrentStateResponse” message, and then I use TransmitMessage to send a “ProvideCurrentStateRequest”.

The downside to this is that this gives you the current state for everything and isn’t really designed to be executed repeatedly in a live monitoring scenario due to the time it can take to get that initial response.

However, you could combine this with a subscription to “NewEventIndication” and listen for the “Server Responding” and “Server Not Responding” messages.

Thanks for the idea!

How long does the MessageCommunicationManager way take? The way I am using right now takes around 15 seconds to get the timeout. I think I can probably lower that by tweaking the Timeout property of the RecorderStatusService2 but given it’s 100 by default and I get a timeout after 15 seconds I’m not sure.

Also can you confirm that the NewEventIndication way requires the external monitoring to run permanently for the monitored XProtect?

We are monitoring XProtect through PRTG, which runs a script every 5 minutes. This script receives an IP as entry and uses it to connect to the XProtect API and run its tests. If I understood correctly, doing the NewEventIndication way would require some sort of daemon that monitors permanently all remote servers and would be quite some refactoring.

If this is running once every 5 minutes, the ProvideCurrentStateResponse would be okay, but depending on the size of the site, it may not be any faster than the 15 seconds you’re getting now. On the otherhand, if you had 10 servers it would give the status of all those servers (and attached devices) in a single response which may or may not work in the context of PRTG?

Subscribing to NewEventIndication indeed only makes sense in a service/daemon scenario. If you’re looking to run a script every 5 minutes, that would not fit the use case.

Here’s a couple more ideas:

  1. Run a PowerShell script in the background as a daemon which subscribes to NewEventIndication and provides instant access to the current server/device states for your PRTG scripts
  • The daemon could host it’s own small web api - there’s some easy-to-use PowerShell modules for building PowerShell based web api’s, and your PRTG script could make requests against that local API instead of talking directly to the VMS
    • The daemon could update a local JSON file, or even a SQLite database file, and your PRTG script could read that local file to retrieve the current device states
  • Create your own ASP.NET Web API which acts as the “daemon”. It’s built using MIP SDK and talks directly to Milestone. Your PRTG scripts query your web api so you can design that api to suit your needs.
  • Consider using a Task and a CancellationTokenSource with a timeout if you’re unable to adjust the recorder status timeout, as a workaround to break out early?

Thanks again for the nice ideas, some patterns I didn’t consider and they make sense. Alright I have everything needed to start playing :grinning_face_with_smiling_eyes: