Quantcast
Channel: THWACK: All Content - Orion SDK
Viewing all articles
Browse latest Browse all 2677

Inconsistent time zone handling with Unmanage, SuppressAlerts verbs

$
0
0

While working on a C# application to mute/unmute/unmanage/remanage Solarwinds objects, I came across a couple of odd inconsistencies in the REST API:

 

  • For Orion.AlertSuppression/SuppressAlerts (i.e. muting), the verb expects two date values, SuppressFrom and SuppressUntil. SuppressFrom has to be the local time, but SuppressUntil has to be UTC.
  • The Unmanage verb expects its start and end times to be local time or UTC, depending on what kind of object is being invoked. Orion.Nodes and Orion.NPM.Interfaces objects expect UTC time, but everything else (as far as I can tell) expects local time.

 

Here's a snippet of the C# code I created to handle alert suppression/muting:

        public void Mute(ISwisClient swisClient, int minutes)        {            JToken invokeResult = swisClient.InvokeAsync("Orion.AlertSuppression", "SuppressAlerts", new object[]            {                new object[]                {                    this.Uri                },                DateTime.Now.ToString(),                (DateTime.Now.AddMinutes(minutes)).ToUniversalTime().ToString()            }).Result;            if (invokeResult.ToString() != "")            {                throw new Exception(String.Format("Mute {0} {1} failed. Error: {2}", this.Type, this.Name, invokeResult.ToString()));            }        }

 

Similarly, here's a snippet of the C# code I created for unmanaging alerts based on object type:

        public void Unmanage(ISwisClient swisClient, int minutes)        {            string startTime = "";            string endTime = "";            switch (Type)            {                case "Orion.Nodes":                    startTime = DateTime.Now.ToUniversalTime().ToString();                    endTime = DateTime.Now.ToUniversalTime().AddMinutes(minutes).ToString();                    break;                case "Orion.NPM.Interfaces":                    startTime = DateTime.Now.ToUniversalTime().ToString();                    endTime = DateTime.Now.ToUniversalTime().AddMinutes(minutes).ToString();                    break;                case "Orion.APM.GenericApplication":                    startTime = DateTime.Now.ToString();                    endTime = DateTime.Now.AddMinutes(minutes).ToString();                    break;                default:                    startTime = DateTime.Now.ToString();                    endTime = DateTime.Now.AddMinutes(minutes).ToString();                    break;            }            JToken invokeResult = swisClient.InvokeAsync(this.Type, "Unmanage", new object[]            {                this.Prefix + ":" + this.ID,                startTime,                endTime,                "false"            }).Result;            if (invokeResult.ToString() != "")            {                throw new Exception(String.Format("Unmanage {0} {1} failed. Error: {2}", this.Type, this.Name, invokeResult.ToString()));            }        }

 

The entire source code and installer is here: Unmanage/remanage/mute/unmute a node or group - Windows program in C#


Viewing all articles
Browse latest Browse all 2677

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>