mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-02-16 21:24:54 +00:00
Resolves #368
Changed parsing routine to no longer use absolute indicies for 'ParseUptime'
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using Crestron.SimplSharp;
|
using Crestron.SimplSharp;
|
||||||
using Crestron.SimplSharpPro.DeviceSupport;
|
using Crestron.SimplSharpPro.DeviceSupport;
|
||||||
using Crestron.SimplSharpPro.Diagnostics;
|
using Crestron.SimplSharpPro.Diagnostics;
|
||||||
@@ -103,28 +104,24 @@ namespace PepperDash.Essentials.Core.Monitoring
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void ParseUptime(string response)
|
private void ParseUptime(string response)
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
var splitString = response.Trim().Split('\r', '\n');
|
var splitString = response.Trim().Split('\r', '\n');
|
||||||
|
|
||||||
var lastStartRaw = splitString[2];
|
var lastStartRaw = splitString.FirstOrDefault(o => o.Contains("started"));
|
||||||
|
var uptimeRaw = splitString.FirstOrDefault(o => o.Contains("running"));
|
||||||
|
|
||||||
|
if (!String.IsNullOrEmpty(lastStartRaw))
|
||||||
|
{
|
||||||
var lastStartIndex = lastStartRaw.IndexOf(':');
|
var lastStartIndex = lastStartRaw.IndexOf(':');
|
||||||
|
|
||||||
_lastStart = lastStartRaw.Substring(lastStartIndex + 1).Trim();
|
_lastStart = lastStartRaw.Substring(lastStartIndex + 1).Trim();
|
||||||
|
}
|
||||||
|
|
||||||
var uptimeRaw = splitString[0];
|
if (String.IsNullOrEmpty(uptimeRaw)) return;
|
||||||
|
|
||||||
var forIndex = uptimeRaw.IndexOf("for", StringComparison.Ordinal);
|
var forIndex = uptimeRaw.IndexOf("for", StringComparison.Ordinal);
|
||||||
|
|
||||||
//4 => "for " to get what's on the right
|
//4 => "for " to get what's on the right
|
||||||
_uptime = uptimeRaw.Substring(forIndex + 4);
|
_uptime = uptimeRaw.Substring(forIndex + 4);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
ErrorLog.Exception(String.Format("Exception unable to parse string '{1}'", response), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void CrestronEnvironmentOnEthernetEventHandler(EthernetEventArgs ethernetEventArgs)
|
private void CrestronEnvironmentOnEthernetEventHandler(EthernetEventArgs ethernetEventArgs)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user