108 lines
3.1 KiB
C#
108 lines
3.1 KiB
C#
// /**
|
|
// * File: SkyCheckState.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.skyscanner.entities;
|
|
using System.Collections.Generic;
|
|
using ln.skyscanner.perfvalue;
|
|
using ln.skyscanner.services;
|
|
using ln.json.attributes;
|
|
namespace ln.skyscanner.checks
|
|
{
|
|
public enum CheckState { OK, WARN, CRITICAL, FAIL, ERROR }
|
|
|
|
public struct CheckStateChange
|
|
{
|
|
public CheckState NewState;
|
|
public DateTime Timestamp;
|
|
|
|
public CheckStateChange(CheckState checkState)
|
|
{
|
|
NewState = checkState;
|
|
Timestamp = DateTime.Now;
|
|
}
|
|
}
|
|
|
|
public class SkyCheckState
|
|
{
|
|
public Guid ID;
|
|
|
|
public readonly String CheckName;
|
|
|
|
public PerformanceValue[] PerformanceValues => performanceValues.ToArray();
|
|
List<PerformanceValue> performanceValues = new List<PerformanceValue>();
|
|
|
|
public DateTime LastCheckTime { get; set; }
|
|
public TimeSpan UnchangedTime => history.Count > 0 ? DateTime.Now - history[history.Count - 1].Timestamp : TimeSpan.FromSeconds(0);
|
|
|
|
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;
|
|
|
|
return checkState;
|
|
}
|
|
set
|
|
{
|
|
BaseCheckState = value;
|
|
}
|
|
}
|
|
|
|
public CheckStateChange[] History => history.ToArray();
|
|
List<CheckStateChange> history = new List<CheckStateChange>();
|
|
|
|
protected SkyCheckState()
|
|
{
|
|
}
|
|
public SkyCheckState(SkyCheck skyCheck,Node node)
|
|
{
|
|
ID = Guid.NewGuid();
|
|
CheckName = skyCheck.Name;
|
|
}
|
|
|
|
public void CheckHistory()
|
|
{
|
|
if ((history.Count == 0) || (history[history.Count - 1].NewState != CheckState))
|
|
{
|
|
history.Add(new CheckStateChange(CheckState));
|
|
}
|
|
}
|
|
|
|
public void AddPerformanceValue(PerformanceValue performanceValue)
|
|
{
|
|
performanceValues.Add(performanceValue);
|
|
}
|
|
public PerformanceValue GetPerformanceValue(string perfName)
|
|
{
|
|
foreach (PerformanceValue performanceValue in performanceValues)
|
|
{
|
|
if (performanceValue.PerfName.Equals(perfName))
|
|
return performanceValue;
|
|
}
|
|
return null;
|
|
}
|
|
public bool ContainsPerformanceValue(string perfName)
|
|
{
|
|
foreach (PerformanceValue performanceValue in performanceValues)
|
|
{
|
|
if (performanceValue.PerfName.Equals(perfName))
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|