From 624f0589b4cdd8cbec3bc93e4185dc251a9fd315 Mon Sep 17 00:00:00 2001 From: Harald Wolff Date: Fri, 12 Apr 2019 00:52:55 +0200 Subject: [PATCH] WIP --- SkyEntities.cs | 25 +++--- checks/APC.cs | 102 +++++++++++++++++++++++ checks/CheckJob.cs | 2 +- checks/Hostalive.cs | 11 +-- checks/PerformanceValue.cs | 69 +++++++++++++++ checks/SkyCheck.cs | 16 +--- checks/SkyCheckState.cs | 60 +++++++++---- checks/SkyChecker.cs | 35 ++------ checks/Ubiquity.cs | 12 +-- crawl/service/ICMP.cs | 2 +- crawl/service/Ubiquity.cs | 13 ++- entities/GlobalNetwork.cs | 11 ++- entities/Node.cs | 2 +- http/CheckerApi.cs | 13 +++ ln.skyscanner.csproj | 2 + templates/static/checks/checkstates.html | 1 + templates/static/checks/index.html | 25 ++++-- 17 files changed, 306 insertions(+), 95 deletions(-) create mode 100644 checks/APC.cs create mode 100644 checks/PerformanceValue.cs diff --git a/SkyEntities.cs b/SkyEntities.cs index fdb01a8..2cb3e6f 100644 --- a/SkyEntities.cs +++ b/SkyEntities.cs @@ -52,28 +52,33 @@ namespace ln.skyscanner NodeCollection = ODB.GetCollection(); NodeCollection.EnableStrongCache(true); - NodeCollection.EnsureIndex("PrimaryIP"); - NodeCollection.EnsureIndex("Interfaces[].ConfiguredIPs[].IP"); - NodeCollection.EnsureIndex("Interfaces[].ConfiguredIPs[].Network"); - NodeCollection.EnsureIndex("uniqueIdentity"); + NodeCollection.EnsureIndeces( + "PrimaryIP", + "Interfaces[].ConfiguredIPs[].IP", + "Interfaces[].ConfiguredIPs[].Network", + "uniqueIdentity" + ); + + /* Preload all nodes to increase load speed*/ + foreach (Node node in NodeCollection) + { + } SubnetCollection = ODB.GetCollection(); - SubnetCollection.EnsureIndex("Network"); + SubnetCollection.EnsureIndeces("Network"); PointOfPresenceCollection = ODB.GetCollection(); - PointOfPresenceCollection.EnsureIndex("ForeignName"); + PointOfPresenceCollection.EnsureIndeces("ForeignName"); CrawledHosts = ODB.GetCollection(); - CrawledHosts.EnsureIndex("PrimaryIP"); - CrawledHosts.EnsureIndex("IPAddresses[]"); + CrawledHosts.EnsureIndeces("PrimaryIP","IPAddresses[]"); CrawledSubnets = ODB.GetCollection(); BlockedNetworks = ODB.GetCollection("blockedNetworks"); SkyCheckStates = ODB.GetCollection(); SkyCheckStates.EnableStrongCache(true); - SkyCheckStates.EnsureIndex("CheckName"); - SkyCheckStates.EnsureIndex("Node.ID"); + SkyCheckStates.EnsureIndeces("CheckName","Node"); Logging.Log(LogLevel.INFO, "SkyEntities: initialized"); diff --git a/checks/APC.cs b/checks/APC.cs new file mode 100644 index 0000000..ce09344 --- /dev/null +++ b/checks/APC.cs @@ -0,0 +1,102 @@ +using System; +using ln.skyscanner.entities; +using ln.types; +using ln.snmp; +using System.Collections.Generic; +using ln.snmp.types; +using ln.logging; +using Microsoft.Win32.SafeHandles; +using Renci.SshNet.Messages.Connection; + +namespace ln.skyscanner.checks +{ + public class APC : SkyCheck + { + public APC() + :base("apc") + { + } + + + public override void Check(SkyChecker skyChecker,ref SkyCheckState checkState,Node node) + { + if ((checkState == null)) + { + checkState = new SkyCheckState(this, node); + } + + foreach (URI snmpUri in node.FindURIs("snmp")) + { + using (SnmpInterface snmp = SnmpInterface.FromURI(snmpUri,skyChecker.SNMPEngine)) + { + try + { + Sequence[][] inputs = snmp.snmpWalk(new string[]{ + "1.3.6.1.2.1.33.1.3.3.1.2", + "1.3.6.1.2.1.33.1.3.3.1.3", + "1.3.6.1.2.1.33.1.3.3.1.4" + }); + Sequence[][] outputs = snmp.snmpWalk(new string[]{ + "1.3.6.1.2.1.33.1.4.4.1.2", + "1.3.6.1.2.1.33.1.4.4.1.3", + "1.3.6.1.2.1.33.1.4.4.1.5" + }); + Sequence[][] batteries = snmp.snmpWalk(new string[] { + "1.3.6.1.2.1.33.1.2.1", + "1.3.6.1.2.1.33.1.2.3", + "1.3.6.1.2.1.33.1.2.4", + "1.3.6.1.2.1.33.1.2.5", + "1.3.6.1.2.1.33.1.2.7" + }); + + CheckState myCheckState = CheckState.OK; + + int n = 0; + foreach (Sequence[] input in inputs) + { + double frequency = (double)((Integer)(input[0].Items[1])).LongValue / 10.0; + double voltage = (double)((Integer)(input[1].Items[1])).LongValue; + double current = (double)((Integer)(input[2].Items[1])).LongValue; + + checkState.WritePerformanceValue(String.Format("ups_input_{0}_frequency", n), frequency, wLower: 48, wUpper: 52, cLower: 45, cUpper: 55); + checkState.WritePerformanceValue(String.Format("ups_input_{0}_voltage", n), voltage, wLower: 218.5, wUpper: 238, cLower: 212, cUpper: 245); + checkState.WritePerformanceValue(String.Format("ups_input_{0}_current", n), current); + n++; + } + + n = 0; + foreach (Sequence[] output in outputs) + { + checkState.WritePerformanceValue(String.Format("ups_output_{0}_voltage", n), (double)((Integer)(output[0].Items[1])).LongValue, wLower: 218.5, wUpper: 238, cLower: 212, cUpper: 245); + checkState.WritePerformanceValue(String.Format("ups_output_{0}_current", n), (double)((Integer)(output[1].Items[1])).LongValue / 10.0); + checkState.WritePerformanceValue(String.Format("ups_output_{0}_load", n), (double)((Integer)(output[2].Items[1])).LongValue, wUpper: 50, cUpper: 75); + n++; + } + + n = 0; + foreach (Sequence[] battery in batteries) + { + checkState.WritePerformanceValue(String.Format("ups_battery_{0}_status", n), (double)((Integer)(battery[0].Items[1])).LongValue); + checkState.WritePerformanceValue(String.Format("ups_battery_{0}_minutes_remain", n), (double)((Integer)(battery[1].Items[1])).LongValue, wLower: 20, cLower: 10 ); + checkState.WritePerformanceValue(String.Format("ups_battery_{0}_capacity", n), (double)((Integer)(battery[2].Items[1])).LongValue, wLower: 75, cLower: 50); + checkState.WritePerformanceValue(String.Format("ups_battery_{0}_voltage", n), (double)((Integer)(battery[3].Items[1])).LongValue / 10.0); + checkState.WritePerformanceValue(String.Format("ups_battery_{0}_temperature", n), (double)((Integer)(battery[4].Items[1])).LongValue, wUpper: 40, cUpper: 60); + n++; + } + + checkState.CheckState = CheckState.OK; + return; + } catch (SnmpError) + { + } + } + } + checkState.CheckState = CheckState.FAIL; + } + + public override bool IsValid(Node node) + { + return (node.Vendor != null) && node.Vendor.Equals("APC"); + } + } +} diff --git a/checks/CheckJob.cs b/checks/CheckJob.cs index 88892b2..f54d4e0 100644 --- a/checks/CheckJob.cs +++ b/checks/CheckJob.cs @@ -29,7 +29,7 @@ namespace ln.skyscanner.checks Name = String.Format("Interval check: {0} [{1}]",node.UniqueIdentity,node.PrimaryIP.ToString()); Node = node; - Query stateQuery = Query.Equals("Node.ID", Node.ID); + Query stateQuery = Query.Equals("Node", Node.ID); SkyCheckState[] skyCheckStates = SkyScanner.Instance.Entities.SkyCheckStates.Query(stateQuery).ToArray(); foreach (SkyCheckState checkState in skyCheckStates) { diff --git a/checks/Hostalive.cs b/checks/Hostalive.cs index 4d222f0..fe73846 100644 --- a/checks/Hostalive.cs +++ b/checks/Hostalive.cs @@ -32,11 +32,7 @@ namespace ln.skyscanner.checks public override void Check(SkyChecker skyChecker,ref SkyCheckState checkState,Node node) { if (checkState == null) - { checkState = new SkyCheckState(this, node); - checkState.WarnLower = 0.6; - checkState.CritLower = 0.3; - } long roundTripTime = 0; int success = 0; @@ -54,13 +50,14 @@ namespace ln.skyscanner.checks float fSuccess = (float)success / (float)n; - skyChecker.WritePerfValue(this,checkState,"replies",node,fSuccess); + checkState.WritePerformanceValue("replies", fSuccess, 0.8, 1.0, 0.6, 1.0); if (success > 0) { roundTripTime /= success; - skyChecker.WritePerfValue(this, checkState, "rta", node, roundTripTime); + checkState.WritePerformanceValue("rta", roundTripTime, 0, 10, 0, 50); } - SetState(checkState, fSuccess); + + checkState.BaseCheckState = CheckState.OK; } } } diff --git a/checks/PerformanceValue.cs b/checks/PerformanceValue.cs new file mode 100644 index 0000000..d303b04 --- /dev/null +++ b/checks/PerformanceValue.cs @@ -0,0 +1,69 @@ +// /** +// * File: PerformanceValue.cs +// * Author: haraldwolff +// * +// * This file and it's content is copyrighted by the Author and / or copyright holder. +// * Any use wihtout proper permission is illegal and may lead to legal actions. +// * +// * +// **/ +using System; +using ln.perfdb.storage; +namespace ln.skyscanner.checks +{ + public class PerformanceValue + { + public string[] PerfPath { get; private set; } + public string PerfName => string.Join("/", PerfPath); + + public double LastValue { get; set; } + + public double WarnLower { get; set; } = Double.MinValue; + public double WarnUpper { get; set; } = Double.MaxValue; + public double CritLower { get; set; } = Double.MinValue; + public double CritUpper { get; set; } = Double.MaxValue; + + + private PerformanceValue() + { + } + public PerformanceValue(string[] perfPath,double wLower = Double.MinValue,double wUpper = Double.MaxValue, double cLower = Double.MinValue, double cUpper = Double.MaxValue) + { + PerfPath = perfPath; + LastValue = 0; + + WarnLower = wLower; + WarnUpper = wUpper; + CritLower = cLower; + CritUpper = cUpper; + } + + public void WritePerfValue(double value) + { + LastValue = value; + + PerfFile perfFile = SkyScanner.Instance.Checker.GetPerfFile(PerfPath); + lock (perfFile) + { + perfFile.EnsureOpen(); + perfFile.Write(DateTimeOffset.Now.ToUnixTimeSeconds(), value); + perfFile.Close(); + } + } + + public CheckState CheckState + { + get + { + if ((LastValue < CritLower) || (LastValue > CritUpper)) + return CheckState.CRITICAL; + if ((LastValue < WarnLower) || (LastValue > WarnUpper)) + return CheckState.WARN; + + return CheckState.OK; + } + } + + + } +} diff --git a/checks/SkyCheck.cs b/checks/SkyCheck.cs index 9fee775..9188c5d 100644 --- a/checks/SkyCheck.cs +++ b/checks/SkyCheck.cs @@ -34,25 +34,11 @@ namespace ln.skyscanner.checks public abstract bool IsValid(Node node); public abstract void Check(SkyChecker skyChecker,ref SkyCheckState checkState,Node node); - public virtual void SetState(SkyCheckState checkState,double value) - { - if ((value < checkState.CritLower) || (value > checkState.CritUpper)) - { - checkState.CheckState = CheckState.CRITICAL; - } else if ((value < checkState.WarnLower) || (value > checkState.WarnUpper)) - { - checkState.CheckState = CheckState.WARN; - } - else - { - checkState.CheckState = CheckState.OK; - } - } - static SkyCheck() { AddSkyCheck(new Hostalive()); AddSkyCheck(new Ubiquity()); + AddSkyCheck(new APC()); } } } diff --git a/checks/SkyCheckState.cs b/checks/SkyCheckState.cs index 7a6c445..daa85fe 100644 --- a/checks/SkyCheckState.cs +++ b/checks/SkyCheckState.cs @@ -35,24 +35,34 @@ namespace ln.skyscanner.checks public class SkyCheckState { [DocumentID] - public Guid ID = Guid.NewGuid(); + public Guid ID; public readonly String CheckName; [ByReference] public readonly Node Node; - public String[] PerformanceValues => performanceValues.ToArray(); - List performanceValues = new List(); + public PerformanceValue[] PerformanceValues => performanceValues.ToArray(); + List performanceValues = new List(); public DateTime LastCheckTime { get; set; } + public TimeSpan UnchangedTime => history.Count > 0 ? DateTime.Now - history[history.Count - 1].Timestamp : TimeSpan.FromSeconds(0); - public double WarnLower { get; set; } = Double.MinValue; - public double WarnUpper { get; set; } = Double.MaxValue; - public double CritLower { get; set; } = Double.MinValue; - public double CritUpper { get; set; } = Double.MaxValue; + public CheckState BaseCheckState { get; set; } = CheckState.OK; + public CheckState CheckState { + get + { + CheckState checkState = BaseCheckState; + foreach (PerformanceValue performanceValue in performanceValues) + if (performanceValue.CheckState > checkState) + checkState = performanceValue.CheckState; - public CheckState CheckState { get => currentCheckState; set { if (currentCheckState != value) history.Add(new CheckStateChange(value)); currentCheckState = value; } } - CheckState currentCheckState; + return checkState; + } + set + { + BaseCheckState = value; + } + } public CheckStateChange[] History => history.ToArray(); List history = new List(); @@ -62,24 +72,42 @@ namespace ln.skyscanner.checks } public SkyCheckState(SkyCheck skyCheck,Node node) { + ID = Guid.NewGuid(); CheckName = skyCheck.Name; Node = node; } - public void EnsurePerformanceValue(String perfName) + public void WritePerformanceValue(String perfName,double value, double wLower = Double.MinValue, double wUpper = Double.MaxValue, double cLower = Double.MinValue, double cUpper = Double.MaxValue) { if (performanceValues == null) - performanceValues = new List(); + performanceValues = new List(); - if (!performanceValues.Contains(perfName)) - performanceValues.Add(perfName); + string[] perfPath = new string[] { Node.UniqueIdentity, CheckName, perfName }; + perfName = string.Join("/", perfPath); + + foreach (PerformanceValue performanceValue in performanceValues) + { + if (performanceValue.PerfName.Equals(perfName)) + { + performanceValue.WritePerfValue(value); + return; + } + } + + PerformanceValue newPerformanceValue = new PerformanceValue(perfPath, wLower, wUpper, cLower, cUpper); + performanceValues.Add(newPerformanceValue); + newPerformanceValue.WritePerfValue(value); } - - public class PerformanceValue + public void CheckHistory() { - + if ((history.Count == 0) || (history[history.Count - 1].NewState != CheckState)) + { + history.Add(new CheckStateChange(CheckState)); + } } + + } } diff --git a/checks/SkyChecker.cs b/checks/SkyChecker.cs index 3d7f550..66252ae 100644 --- a/checks/SkyChecker.cs +++ b/checks/SkyChecker.cs @@ -21,6 +21,7 @@ using ln.http.resources; using ln.types.odb; using System.Collections.Generic; using ln.types.odb.mapped; +using System.Runtime.CompilerServices; namespace ln.skyscanner.checks { public class SkyChecker @@ -102,42 +103,18 @@ namespace ln.skyscanner.checks perfFiles.Clear(); } - public void WritePerfValue(SkyCheck skyCheck,SkyCheckState checkState,String vName,Node node,double value) + public PerfFile GetPerfFile(params string[] perfPath) { - PerfFile perfFile = GetPerfFile(skyCheck, checkState, vName, node); - lock (perfFile) - { - perfFile.EnsureOpen(); - perfFile.Write(DateTimeOffset.Now.ToUnixTimeSeconds(), value); - perfFile.Close(); - } - } - - public PerfFile GetPerfFile(string perfName) - { - return perfFiles[perfName]; - } - - private PerfFile GetPerfFile(SkyCheck skyCheck,SkyCheckState checkState,String vName, Node node) - { - String checkPath = String.Format("{0}_{1}", node.UniqueIdentity, skyCheck.Name); - String perfName = String.Format("{0}_{1}",checkPath,vName); - - if (node.AddCheck(perfName)) - { - SkyScanner.Instance.Entities.NodeCollection.Upsert(node); - } - checkState.EnsurePerformanceValue(perfName); - lock (this) { + string perfName = string.Join("/", perfPath); if (!perfFiles.ContainsKey(perfName)) { - String perfDirectory = Path.Combine(BasePath, node.UniqueIdentity, skyCheck.Name); + String perfDirectory = Path.Combine(BasePath, Path.Combine(perfPath.Take(perfPath.Length - 1).ToArray())); if (!Directory.Exists(perfDirectory)) Directory.CreateDirectory(perfDirectory); - String perfFileName = Path.Combine(BasePath, node.UniqueIdentity, skyCheck.Name, String.Format("{0}.perf", vName)); + String perfFileName = Path.Combine(perfDirectory, String.Format("{0}.perf", perfPath[perfPath.Length-1])); PerfFile perfFile = new PerfFile(perfFileName); perfFile.Open(); @@ -151,13 +128,13 @@ namespace ln.skyscanner.checks PerfFile.PerfFileSection s5 = new PerfFile.PerfFileSection(perfFile, s4, TimeSpan.FromDays(750), 3600, AggregationMethod.AVERAGE); } perfFile.Close(); - perfFiles.Add(perfName, perfFile); } return perfFiles[perfName]; } } + private void scheduler() { long nextMinute = DateTimeOffset.Now.ToUnixTimeMilliseconds(); diff --git a/checks/Ubiquity.cs b/checks/Ubiquity.cs index 92460c1..23633c4 100644 --- a/checks/Ubiquity.cs +++ b/checks/Ubiquity.cs @@ -39,10 +39,10 @@ namespace ln.skyscanner.checks foreach (Sequence[] row in ptp) { - skyChecker.WritePerfValue(this, checkState, "ptp_rx_capa", node, (double)((Integer)(row[0].Items[1])).LongValue); - skyChecker.WritePerfValue(this, checkState, "ptp_tx_capa", node, (double)((Integer)(row[1].Items[1])).LongValue); - skyChecker.WritePerfValue(this, checkState, "ptp_rx_pwr", node, (double)((Integer)(row[2].Items[1])).LongValue); - skyChecker.WritePerfValue(this, checkState, "ptp_tx_pwr", node, (double)((Integer)(row[3].Items[1])).LongValue); + ubiquityCheckState.WritePerformanceValue("ptp_rx_capa", (double)((Integer)(row[0].Items[1])).LongValue); + ubiquityCheckState.WritePerformanceValue("ptp_tx_capa", (double)((Integer)(row[1].Items[1])).LongValue); + ubiquityCheckState.WritePerformanceValue("ptp_rx_pwr", (double)((Integer)(row[2].Items[1])).LongValue, -65.0,0,-75.0,0); + ubiquityCheckState.WritePerformanceValue("ptp_tx_pwr", (double)((Integer)(row[3].Items[1])).LongValue); long rxBytes = ((Integer)(row[4].Items[1])).LongValue; long txBytes = ((Integer)(row[5].Items[1])).LongValue; @@ -50,8 +50,8 @@ namespace ln.skyscanner.checks ubiquityCheckState.RXRate.Update(rxBytes * 8); ubiquityCheckState.TXRate.Update(txBytes * 8); - skyChecker.WritePerfValue(this, checkState, "ptp_rx_rate", node, ubiquityCheckState.RXRate.Current); - skyChecker.WritePerfValue(this, checkState, "ptp_tx_rate", node, ubiquityCheckState.TXRate.Current); + ubiquityCheckState.WritePerformanceValue("ptp_rx_rate", ubiquityCheckState.RXRate.Current); + ubiquityCheckState.WritePerformanceValue("ptp_tx_rate", ubiquityCheckState.TXRate.Current); } } diff --git a/crawl/service/ICMP.cs b/crawl/service/ICMP.cs index e71e810..ddd0538 100644 --- a/crawl/service/ICMP.cs +++ b/crawl/service/ICMP.cs @@ -14,7 +14,7 @@ namespace ln.skyscanner.crawl.tests { public class ICMP : CrawlService { - public Ping Ping { get; private set; } + public Ping Ping { get; private set; } = new Ping(); public ICMP() :base("ping") diff --git a/crawl/service/Ubiquity.cs b/crawl/service/Ubiquity.cs index 002741e..8b2cc6c 100644 --- a/crawl/service/Ubiquity.cs +++ b/crawl/service/Ubiquity.cs @@ -32,10 +32,19 @@ namespace ln.skyscanner.crawl.service if (crawl.Host.GetHint("snmp.orids", new string[0]).Contains("1.3.6.1.4.1.41112")) { List test = snmp.snmpWalk("1.3.6.1.4.1.41112.1.3.2.1.11"); - List test2 = snmp.snmpWalk("1.3.6.1.4.1.41112.1.3.3.1.66"); + //List test2 = snmp.snmpWalk("1.3.6.1.4.1.41112.1.3.3.1.66"); + if (test.Count > 0) + crawl.Host.SetHint("ubiquity.ptp", true); + else + crawl.Host.SetHint("ubiquity.ptp", false); - crawl.Host.SetHint("ubiquity.ptp", true); + test = snmp.snmpWalk("1.3.6.1.4.1.41112.1.4.7.1.1"); + + if (test.Count > 0) + crawl.Host.SetHint("ubiquity.ptmp", true); + else + crawl.Host.SetHint("ubiquity.ptmp", false); } } } diff --git a/entities/GlobalNetwork.cs b/entities/GlobalNetwork.cs index 92ea984..ac5d08d 100644 --- a/entities/GlobalNetwork.cs +++ b/entities/GlobalNetwork.cs @@ -275,14 +275,21 @@ namespace ln.skyscanner.entities if (crawledHost.GetHint("http.server", "").Equals("Viprinet")) node.Vendor = "Viprinet"; - if (crawledHost.GetHint("snmp.orids",new string[0]).Contains("1.3.6.1.4.1.41112")) + if (crawledHost.GetHint("snmp.sysObjectID", "").Equals("1.3.6.1.4.1.318.1.3.27")) + { + node.Vendor = "APC"; + node.DeviceType = DeviceType.UPS; + } else if (crawledHost.GetHint("snmp.orids", new string[0]).Contains("1.3.6.1.4.1.41112")) { node.Vendor = "Ubiquity"; } - if (crawledHost.GetHint("ubiquity.ptp",false)) + if (crawledHost.GetHint("ubiquity.ptp", false)) { node.DeviceType = DeviceType.PTP; + } else if (crawledHost.GetHint("ubiquity.ptmp", false)) + { + node.DeviceType = DeviceType.PTMP; } diff --git a/entities/Node.cs b/entities/Node.cs index 2ff205e..16ab90e 100644 --- a/entities/Node.cs +++ b/entities/Node.cs @@ -108,7 +108,7 @@ namespace ln.skyscanner.entities public IEnumerable FindURIs(string scheme) { - return uris.Where((u) => scheme.Equals(u.Scheme)); + return uris.Where((u) => scheme.Equals(u.Scheme)).ToArray(); } public NetworkInterface GetInterface(String intfName) diff --git a/http/CheckerApi.cs b/http/CheckerApi.cs index 117494e..0268fbf 100644 --- a/http/CheckerApi.cs +++ b/http/CheckerApi.cs @@ -14,6 +14,7 @@ using ln.http.resources; using ln.types.threads; using ln.perfdb.storage; using Newtonsoft.Json; +using System.Net; namespace ln.skyscanner.http { public class CheckerApi : JsonCallResource @@ -40,6 +41,8 @@ namespace ln.skyscanner.http :base(container,"checks") { } + public override bool HandlesDispatching => true; + public override bool Contains(string name) { return base.Contains(name) || SkyScanner.Instance.Checker.ContainsPerfFile(name); @@ -56,6 +59,16 @@ namespace ln.skyscanner.http throw new KeyNotFoundException(); } + public override HttpResponse GetResponse(HttpRequest httpRequest, Queue pathStack) + { + if (pathStack.Count == 0) + return GetResponse(httpRequest); + + string perfName = WebUtility.UrlDecode(String.Join("/", pathStack)); + + Resource perfResource = GetResource(perfName); + return perfResource.GetResponse(httpRequest); + } public override HttpResponse GetResponse(HttpRequest httpRequest) { diff --git a/ln.skyscanner.csproj b/ln.skyscanner.csproj index 2ffa880..fe00310 100644 --- a/ln.skyscanner.csproj +++ b/ln.skyscanner.csproj @@ -81,6 +81,8 @@ + + diff --git a/templates/static/checks/checkstates.html b/templates/static/checks/checkstates.html index 5fb1c1d..e544705 100644 --- a/templates/static/checks/checkstates.html +++ b/templates/static/checks/checkstates.html @@ -20,6 +20,7 @@ { title: "Node", data: "Node.Name" }, { title: "LastCheckTime", data: "LastCheckTime" }, { title: "CheckState", data: "CheckState" }, + { title: "Zeitspanne", data: "UnchangedTime" }, { title: "Check Schwere", data: "Node.Severity" }, ], ajax: { diff --git a/templates/static/checks/index.html b/templates/static/checks/index.html index aad08f2..97a7b6c 100644 --- a/templates/static/checks/index.html +++ b/templates/static/checks/index.html @@ -12,6 +12,8 @@

+
+
@@ -60,10 +62,11 @@ } } ); - var perfList = skyapi().getJson("api/checker/checks", function(checks){ - $.each( checks, function(){ - $("#perfList").append( $( "" ) ); - }); + var perfList = []; + + skyapi().getJson("api/checker/checks", function(checks){ + perfList = checks; + applyFilter(); }); function showGraph() @@ -71,7 +74,7 @@ var perfName = $("#perfList").children("option:selected").val(); if (perfName) { - skyapi().getJson("api/checker/checks/" + perfName + "?interval=" + $("#interval").children("option:selected").val(), function(perfValues){ + skyapi().getJson("api/checker/checks/" + encodeURIComponent(perfName) + "?interval=" + $("#interval").children("option:selected").val(), function(perfValues){ chart.data.labels.length = 0; chart.data.datasets[0].data.length = 0; chart.data.datasets[0].label = perfName; @@ -87,8 +90,20 @@ } } + function applyFilter() + { + var pat = $("#filter").val(); + + $("#perfList").empty(); + $.each( perfList, function(){ + if (this.includes(pat)) + $("#perfList").append( $( "" ) ); + }); + } + $("#perfList").change( function(e){ showGraph(); } ); $("#interval").change( function(e){ showGraph(); } ); + $("#filter").on( "input", function(e){ applyFilter(); } ); skyapi().addRefresh( showGraph, 60 );