ln.skyscanner/checks/Hostalive.cs

87 lines
2.5 KiB
C#

// /**
// * File: Hostalive.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.types;
using ln.skyscanner.entities;
using ln.perfdb;
using System.Net.NetworkInformation;
using ln.logging;
using ln.perfdb.storage;
using ln.skyscanner.services;
using ln.skyscanner.perfvalue;
namespace ln.skyscanner.checks
{
public class Hostalive : SkyCheck
{
Ping Ping { get; }
public Hostalive()
: base("hostalive")
{
Ping = new Ping();
}
public override bool IsCritical => true;
public override bool IsValid(Node node) => node.PrimaryIP != null;
public override void Check(CheckService checkService, ref SkyCheckState checkState, Node node)
{
long roundTripTime = 0;
int success = 0;
int n;
for (n = 0; n < 4; n++)
{
PingReply reply = Ping.Send(node.PrimaryIP, 250);
if (reply.Status == IPStatus.Success)
{
success++;
roundTripTime += reply.RoundtripTime;
}
}
float fSuccess = (float)success / (float)n;
node.WritePerformanceValue(
checkService.PerformanceValueService,
Name,
"replies",
fSuccess,
node.DeviceType == DeviceType.UNKNOWN ? Double.MinValue : 0.8,
double.MaxValue,
node.DeviceType == DeviceType.UNKNOWN ? Double.MinValue : 0.6,
double.MaxValue,
"%"
);
if (success > 0)
{
roundTripTime /= success;
node.WritePerformanceValue(
checkService.PerformanceValueService,
Name,
"rta",
roundTripTime,
0,
80,
0,
140,
"ms"
);
}
foreach (PerformanceValue pv in checkState.PerformanceValues)
pv.IgnoreLimits = ((node.DeviceType == DeviceType.UNKNOWN) && (node.DeviceType == DeviceType.PTMP));
checkState.BaseCheckState = CheckState.OK;
}
}
}