WIP
parent
30b9980a51
commit
96356c047c
40
Program.cs
40
Program.cs
|
@ -37,46 +37,6 @@ namespace ln.skyscanner
|
||||||
|
|
||||||
SkyScanner skyScanner = new SkyScanner(args);
|
SkyScanner skyScanner = new SkyScanner(args);
|
||||||
skyScanner.Start();
|
skyScanner.Start();
|
||||||
return;
|
|
||||||
|
|
||||||
Node coreNode = skyScanner.Entities.GlobalNetwork.FindNodeByIP(IPv4.Parse("10.10.10.2"));
|
|
||||||
Console.WriteLine("Core Node: {0}", coreNode);
|
|
||||||
|
|
||||||
Node coreNode2 = skyScanner.Entities.GlobalNetwork.FindNodeByIP(IPv4.Parse("10.255.7.129"));
|
|
||||||
Console.WriteLine("Core Node (alt): {0}", coreNode2);
|
|
||||||
|
|
||||||
Query nodeByIpQuery = Query.Equals<Node>("Interfaces[].ConfiguredIPs[].IP", IPv4.Parse("10.255.7.129"));
|
|
||||||
IEnumerable<Node> qnodes = skyScanner.Entities.nodeCollection.Query(nodeByIpQuery);
|
|
||||||
|
|
||||||
IEnumerable<Node> neighbors = skyScanner.Entities.GlobalNetwork.FindNeighbors(coreNode);
|
|
||||||
|
|
||||||
foreach (Node neigh in neighbors)
|
|
||||||
{
|
|
||||||
Console.WriteLine("Neighbor: {0}", neigh);
|
|
||||||
}
|
|
||||||
|
|
||||||
SkyScanner.Instance.Stop();
|
|
||||||
|
|
||||||
return;
|
|
||||||
|
|
||||||
IEnumerable<Node> nodes = skyScanner.Entities.nodeCollection;
|
|
||||||
foreach (Node node in nodes)
|
|
||||||
{
|
|
||||||
Console.WriteLine("Node: {0}", node);
|
|
||||||
|
|
||||||
Timing.Meassure("", () =>
|
|
||||||
{
|
|
||||||
foreach (Node neighbor in SkyScanner.Instance.Entities.GlobalNetwork.FindNeighbors(node))
|
|
||||||
{
|
|
||||||
Console.WriteLine(" Neighbor: {0}", neighbor);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
Console.WriteLine("");
|
|
||||||
Console.WriteLine("");
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new Exception();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void Initialize()
|
private static void Initialize()
|
||||||
|
|
|
@ -14,46 +14,70 @@ using System.IO;
|
||||||
using ln.http.resources;
|
using ln.http.resources;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using ln.types.odb.mapped;
|
using ln.types.odb.mapped;
|
||||||
|
using ln.types.net;
|
||||||
|
using ln.skyscanner.crawl;
|
||||||
|
using ln.skyscanner.checks;
|
||||||
|
using ln.logging;
|
||||||
|
|
||||||
namespace ln.skyscanner
|
namespace ln.skyscanner
|
||||||
{
|
{
|
||||||
public class SkyEntities
|
public class SkyEntities
|
||||||
{
|
{
|
||||||
[Callable]
|
|
||||||
public Node[] Nodes => nodeCollection.ToArray();
|
|
||||||
|
|
||||||
public SkyScanner SkyScanner { get; }
|
public SkyScanner SkyScanner { get; }
|
||||||
public string BasePath => Path.Combine(SkyScanner.BasePath, "entities");
|
public string BasePath => Path.Combine(SkyScanner.BasePath, "entities");
|
||||||
|
|
||||||
public GlobalNetwork GlobalNetwork { get; private set; }
|
public GlobalNetwork GlobalNetwork { get; private set; }
|
||||||
public ODB odDatabase { get; private set; }
|
|
||||||
public ODBCollection<Node> nodeCollection { get; private set; }
|
|
||||||
//public ODBCollection<NetworkInterface> interfaceCollection { get; private set; }
|
public ODB ODB { get; private set; }
|
||||||
//public ODBCollection<IntfIP> intfIPCollection { get; private set; }
|
|
||||||
public ODBCollection<Subnet> subnetCollection { get; private set; }
|
public ODBCollection<Node> NodeCollection { get; private set; }
|
||||||
public ODBCollection<PointOfPresence> popCollection { get; private set; }
|
public ODBCollection<Subnet> SubnetCollection { get; private set; }
|
||||||
|
public ODBCollection<PointOfPresence> PointOfPresenceCollection { get; private set; }
|
||||||
|
|
||||||
|
public ODBCollection<CrawledHost> CrawledHosts { get; private set; }
|
||||||
|
public ODBCollection<CrawledSubnet> CrawledSubnets { get; private set; }
|
||||||
|
|
||||||
|
public ODBCollection<Network4> BlockedNetworks { get; private set; }
|
||||||
|
|
||||||
|
public ODBCollection<SkyCheckState> SkyCheckStates { get; private set; }
|
||||||
|
|
||||||
public SkyEntities(SkyScanner skyScanner)
|
public SkyEntities(SkyScanner skyScanner)
|
||||||
{
|
{
|
||||||
SkyScanner = skyScanner;
|
SkyScanner = skyScanner;
|
||||||
|
|
||||||
odDatabase = new ODB(BasePath);
|
Logging.Log(LogLevel.INFO, "SkyEntities: initializing");
|
||||||
nodeCollection = odDatabase.GetCollection<Node>();
|
|
||||||
subnetCollection = odDatabase.GetCollection<Subnet>();
|
|
||||||
|
|
||||||
nodeCollection.EnableStrongCache(true);
|
ODB = new ODB(BasePath);
|
||||||
nodeCollection.EnsureIndex("PrimaryIP");
|
|
||||||
nodeCollection.EnsureIndex("Interfaces[].ConfiguredIPs[].IP");
|
|
||||||
nodeCollection.EnsureIndex("Interfaces[].ConfiguredIPs[].Network");
|
|
||||||
nodeCollection.EnsureIndex("uniqueIdentity");
|
|
||||||
|
|
||||||
subnetCollection.EnsureIndex("Network");
|
NodeCollection = ODB.GetCollection<Node>();
|
||||||
|
NodeCollection.EnableStrongCache(true);
|
||||||
|
NodeCollection.EnsureIndex("PrimaryIP");
|
||||||
|
NodeCollection.EnsureIndex("Interfaces[].ConfiguredIPs[].IP");
|
||||||
|
NodeCollection.EnsureIndex("Interfaces[].ConfiguredIPs[].Network");
|
||||||
|
NodeCollection.EnsureIndex("uniqueIdentity");
|
||||||
|
|
||||||
popCollection = odDatabase.GetCollection<PointOfPresence>();
|
SubnetCollection = ODB.GetCollection<Subnet>();
|
||||||
popCollection.EnsureIndex("ForeignName");
|
SubnetCollection.EnsureIndex("Network");
|
||||||
popCollection.EnsureIndex("nodeIDList[]");
|
|
||||||
|
|
||||||
GlobalNetwork = new GlobalNetwork(this);
|
PointOfPresenceCollection = ODB.GetCollection<PointOfPresence>();
|
||||||
|
PointOfPresenceCollection.EnsureIndex("ForeignName");
|
||||||
|
|
||||||
|
CrawledHosts = ODB.GetCollection<CrawledHost>();
|
||||||
|
CrawledHosts.EnsureIndex("PrimaryIP");
|
||||||
|
CrawledHosts.EnsureIndex("IPAddresses[]");
|
||||||
|
|
||||||
|
CrawledSubnets = ODB.GetCollection<CrawledSubnet>();
|
||||||
|
BlockedNetworks = ODB.GetCollection<Network4>("blockedNetworks");
|
||||||
|
|
||||||
|
SkyCheckStates = ODB.GetCollection<SkyCheckState>();
|
||||||
|
SkyCheckStates.EnableStrongCache(true);
|
||||||
|
SkyCheckStates.EnsureIndex("CheckName");
|
||||||
|
SkyCheckStates.EnsureIndex("Node.ID");
|
||||||
|
|
||||||
|
Logging.Log(LogLevel.INFO, "SkyEntities: initialized");
|
||||||
|
|
||||||
|
GlobalNetwork = new GlobalNetwork();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -61,7 +61,6 @@ namespace ln.skyscanner
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Entities = new SkyEntities(this);
|
Entities = new SkyEntities(this);
|
||||||
Checker = new SkyChecker();
|
Checker = new SkyChecker();
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,12 +29,10 @@ namespace ln.skyscanner.checks
|
||||||
Name = String.Format("Interval check: {0} [{1}]",node.UniqueIdentity,node.PrimaryIP.ToString());
|
Name = String.Format("Interval check: {0} [{1}]",node.UniqueIdentity,node.PrimaryIP.ToString());
|
||||||
Node = node;
|
Node = node;
|
||||||
|
|
||||||
Query stateQuery = Query.Equals<SkyCheckState>("UniqueNodeIdentifier", Node.UniqueIdentity);
|
Query stateQuery = Query.Equals<SkyCheckState>("Node.ID", Node.ID);
|
||||||
SkyCheckState[] skyCheckStates = SkyScanner.Instance.Checker.checkStates.Query(stateQuery).ToArray();
|
SkyCheckState[] skyCheckStates = SkyScanner.Instance.Entities.SkyCheckStates.Query(stateQuery).ToArray();
|
||||||
foreach (SkyCheckState checkState in skyCheckStates)
|
foreach (SkyCheckState checkState in skyCheckStates)
|
||||||
{
|
{
|
||||||
//if (checkState.Node == null)
|
|
||||||
//checkState.Node = node;
|
|
||||||
checkStates.Add(checkState.CheckName, checkState);
|
checkStates.Add(checkState.CheckName, checkState);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,8 @@ namespace ln.skyscanner.checks
|
||||||
public Guid ID = Guid.NewGuid();
|
public Guid ID = Guid.NewGuid();
|
||||||
|
|
||||||
public readonly String CheckName;
|
public readonly String CheckName;
|
||||||
public readonly String UniqueNodeIdentifier;
|
[ByReference]
|
||||||
|
public readonly Node Node;
|
||||||
|
|
||||||
public String[] PerformanceValues => performanceValues.ToArray();
|
public String[] PerformanceValues => performanceValues.ToArray();
|
||||||
List<String> performanceValues = new List<String>();
|
List<String> performanceValues = new List<String>();
|
||||||
|
@ -62,7 +63,7 @@ namespace ln.skyscanner.checks
|
||||||
public SkyCheckState(SkyCheck skyCheck,Node node)
|
public SkyCheckState(SkyCheck skyCheck,Node node)
|
||||||
{
|
{
|
||||||
CheckName = skyCheck.Name;
|
CheckName = skyCheck.Name;
|
||||||
UniqueNodeIdentifier = node.UniqueIdentity;
|
Node = node;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void EnsurePerformanceValue(String perfName)
|
public void EnsurePerformanceValue(String perfName)
|
||||||
|
|
|
@ -31,8 +31,6 @@ namespace ln.skyscanner.checks
|
||||||
public PoolJob[] CurrentJobs => checkPool.CurrentPoolJobs;
|
public PoolJob[] CurrentJobs => checkPool.CurrentPoolJobs;
|
||||||
[Callable]
|
[Callable]
|
||||||
public PoolJob[] QueuedJobs => checkPool.QueuedJobs;
|
public PoolJob[] QueuedJobs => checkPool.QueuedJobs;
|
||||||
[Callable]
|
|
||||||
public SkyCheckState[] CheckStates => checkStates.ToArray();
|
|
||||||
|
|
||||||
|
|
||||||
[Callable]
|
[Callable]
|
||||||
|
@ -40,8 +38,7 @@ namespace ln.skyscanner.checks
|
||||||
public bool ContainsPerfFile(String perfName) => perfFiles.ContainsKey(perfName);
|
public bool ContainsPerfFile(String perfName) => perfFiles.ContainsKey(perfName);
|
||||||
|
|
||||||
[Callable]
|
[Callable]
|
||||||
public SkyCheckState[] Issues => checkStates.Query(
|
public SkyCheckState[] Issues => SkyScanner.Instance.Entities.SkyCheckStates.Query(
|
||||||
//Query.Contains<SkyCheckState,CheckState>("CheckState",new CheckState[] { CheckState.CRITICAL, CheckState.WARN, CheckState.ERROR })
|
|
||||||
Query.OR(
|
Query.OR(
|
||||||
Query.Equals<SkyCheckState>("currentCheckState", CheckState.CRITICAL),
|
Query.Equals<SkyCheckState>("currentCheckState", CheckState.CRITICAL),
|
||||||
Query.Equals<SkyCheckState>("currentCheckState", CheckState.FAIL),
|
Query.Equals<SkyCheckState>("currentCheckState", CheckState.FAIL),
|
||||||
|
@ -59,23 +56,16 @@ namespace ln.skyscanner.checks
|
||||||
|
|
||||||
bool stopping;
|
bool stopping;
|
||||||
|
|
||||||
ODB odb;
|
|
||||||
public ODBCollection<SkyCheckState> checkStates { get; private set; }
|
|
||||||
|
|
||||||
List<SkyCheckState> saveQueue = new List<SkyCheckState>();
|
List<SkyCheckState> saveQueue = new List<SkyCheckState>();
|
||||||
|
|
||||||
public SkyChecker()
|
public SkyChecker()
|
||||||
{
|
{
|
||||||
BasePath = Path.Combine(SkyScanner.Instance.BasePath, "perfdb");
|
BasePath = Path.Combine(SkyScanner.Instance.BasePath, "perfdb");
|
||||||
|
|
||||||
|
Logging.Log(LogLevel.INFO, "SkyChecker: created");
|
||||||
|
|
||||||
SNMPEngine = new SNMPEngine();
|
SNMPEngine = new SNMPEngine();
|
||||||
SNMPEngine.Timeout = 4000;
|
SNMPEngine.Timeout = 4000;
|
||||||
|
|
||||||
odb = new ODB(Path.Combine(BasePath));
|
|
||||||
checkStates = odb.GetCollection<SkyCheckState>();
|
|
||||||
checkStates.EnableStrongCache(true);
|
|
||||||
checkStates.EnsureIndex("CheckName");
|
|
||||||
checkStates.EnsureIndex("UniqueNodeIdentifier");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Start()
|
public void Start()
|
||||||
|
@ -135,7 +125,7 @@ namespace ln.skyscanner.checks
|
||||||
|
|
||||||
if (node.AddCheck(perfName))
|
if (node.AddCheck(perfName))
|
||||||
{
|
{
|
||||||
SkyScanner.Instance.Entities.nodeCollection.Upsert(node);
|
SkyScanner.Instance.Entities.NodeCollection.Upsert(node);
|
||||||
}
|
}
|
||||||
checkState.EnsurePerformanceValue(perfName);
|
checkState.EnsurePerformanceValue(perfName);
|
||||||
|
|
||||||
|
@ -184,14 +174,14 @@ namespace ln.skyscanner.checks
|
||||||
{
|
{
|
||||||
foreach (SkyCheckState checkState in saveQueue)
|
foreach (SkyCheckState checkState in saveQueue)
|
||||||
{
|
{
|
||||||
SkyScanner.Instance.Checker.checkStates.Upsert(checkState);
|
SkyScanner.Instance.Entities.SkyCheckStates.Upsert(checkState);
|
||||||
}
|
}
|
||||||
saveQueue.Clear();
|
saveQueue.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
Logging.Log(LogLevel.INFO, "SkyChecker.scheduler(): scheduler starts");
|
Logging.Log(LogLevel.INFO, "SkyChecker.scheduler(): scheduler starts");
|
||||||
|
|
||||||
foreach (Node node in SkyScanner.Instance.Entities.GlobalNetwork.Nodes)
|
foreach (Node node in SkyScanner.Instance.Entities.NodeCollection)
|
||||||
{
|
{
|
||||||
CheckJob checkJob = new CheckJob(node);
|
CheckJob checkJob = new CheckJob(node);
|
||||||
checkJobs.Add(checkJob);
|
checkJobs.Add(checkJob);
|
||||||
|
|
|
@ -113,7 +113,7 @@ namespace ln.skyscanner.crawl
|
||||||
Host.LastCheck = dateTime;
|
Host.LastCheck = dateTime;
|
||||||
Host.NextCheck = dateTime + TimeSpan.FromHours(24);
|
Host.NextCheck = dateTime + TimeSpan.FromHours(24);
|
||||||
|
|
||||||
bool updated = Crawler.CrawledHosts.Upsert( Host );
|
bool updated = SkyScanner.Instance.Entities.CrawledHosts.Upsert( Host );
|
||||||
|
|
||||||
foreach (Network4 network in Host.Networks)
|
foreach (Network4 network in Host.Networks)
|
||||||
Crawler.EnsureSubnet(network);
|
Crawler.EnsureSubnet(network);
|
||||||
|
|
|
@ -103,7 +103,7 @@ namespace ln.skyscanner.crawl
|
||||||
Subnet.NextScan = startTime + TimeSpan.FromHours(24);
|
Subnet.NextScan = startTime + TimeSpan.FromHours(24);
|
||||||
}
|
}
|
||||||
|
|
||||||
Crawler.CrawledSubnets.Upsert(Subnet);
|
SkyScanner.Instance.Entities.CrawledHosts.Upsert(Subnet);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override int GetHashCode()
|
public override int GetHashCode()
|
||||||
|
|
|
@ -58,16 +58,6 @@ namespace ln.skyscanner.crawl
|
||||||
|
|
||||||
Thread threadScheduler;
|
Thread threadScheduler;
|
||||||
|
|
||||||
public ODBCollection<CrawledHost> CrawledHosts => hosts;
|
|
||||||
public ODBCollection<CrawledSubnet> CrawledSubnets => subnets;
|
|
||||||
public ODBCollection<Network4> BlockedNetworks => blockedNetworks;
|
|
||||||
|
|
||||||
private ODB odbDatabase;
|
|
||||||
private ODBCollection<CrawledHost> hosts;
|
|
||||||
private ODBCollection<CrawledSubnet> subnets;
|
|
||||||
private ODBCollection<Network4> blockedNetworks;
|
|
||||||
|
|
||||||
|
|
||||||
public Crawler(SkyScanner skyScanner)
|
public Crawler(SkyScanner skyScanner)
|
||||||
{
|
{
|
||||||
SkyScanner = skyScanner;
|
SkyScanner = skyScanner;
|
||||||
|
@ -79,17 +69,7 @@ namespace ln.skyscanner.crawl
|
||||||
Directory.CreateDirectory(BasePath);
|
Directory.CreateDirectory(BasePath);
|
||||||
if (!Directory.Exists(PoolPath))
|
if (!Directory.Exists(PoolPath))
|
||||||
Directory.CreateDirectory(PoolPath);
|
Directory.CreateDirectory(PoolPath);
|
||||||
|
|
||||||
//dbCrawlPool = new ODB<CrawlPool>(PoolPath);
|
|
||||||
|
|
||||||
odbDatabase = new ODB(BasePath);
|
|
||||||
hosts = odbDatabase.GetCollection<CrawledHost>();
|
|
||||||
subnets = odbDatabase.GetCollection<CrawledSubnet>();
|
|
||||||
blockedNetworks = odbDatabase.GetCollection<Network4>("blockedNetworks");
|
|
||||||
|
|
||||||
hosts.EnsureIndex("PrimaryIP");
|
|
||||||
hosts.EnsureIndex("IPAddresses[]");
|
|
||||||
|
|
||||||
CrawlerState = ComponentState.INITIALIZED;
|
CrawlerState = ComponentState.INITIALIZED;
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
|
@ -178,7 +158,7 @@ namespace ln.skyscanner.crawl
|
||||||
|
|
||||||
public void Crawl(Guid hostID)
|
public void Crawl(Guid hostID)
|
||||||
{
|
{
|
||||||
CrawledHost crawledHost = CrawledHosts[hostID];
|
CrawledHost crawledHost = SkyScanner.Instance.Entities.CrawledHosts[hostID];
|
||||||
Crawl(crawledHost);
|
Crawl(crawledHost);
|
||||||
}
|
}
|
||||||
public void Crawl(CrawledHost crawledHost)
|
public void Crawl(CrawledHost crawledHost)
|
||||||
|
@ -201,14 +181,14 @@ namespace ln.skyscanner.crawl
|
||||||
Query.Equals<CrawledHost>("IPAddresses[]", ip),
|
Query.Equals<CrawledHost>("IPAddresses[]", ip),
|
||||||
Query.Equals<CrawledHost>("PrimaryIP", ip)
|
Query.Equals<CrawledHost>("PrimaryIP", ip)
|
||||||
);
|
);
|
||||||
CrawledHost crawledHost = hosts.Query(nodeByIpQuery).FirstOrDefault();
|
CrawledHost crawledHost = SkyScanner.Instance.Entities.CrawledHosts.Query(nodeByIpQuery).FirstOrDefault();
|
||||||
if (crawledHost == null)
|
if (crawledHost == null)
|
||||||
{
|
{
|
||||||
crawledHost = new CrawledHost();
|
crawledHost = new CrawledHost();
|
||||||
crawledHost.PrimaryIP = ip;
|
crawledHost.PrimaryIP = ip;
|
||||||
crawledHost.Name = ip.ToString();
|
crawledHost.Name = ip.ToString();
|
||||||
|
|
||||||
CrawledHosts.Insert(crawledHost);
|
SkyScanner.Instance.Entities.CrawledHosts.Insert(crawledHost);
|
||||||
}
|
}
|
||||||
return crawledHost;
|
return crawledHost;
|
||||||
}
|
}
|
||||||
|
@ -218,12 +198,12 @@ namespace ln.skyscanner.crawl
|
||||||
lock (this)
|
lock (this)
|
||||||
{
|
{
|
||||||
Query subnetQuery = Query.Equals<CrawledSubnet>("Network", network);
|
Query subnetQuery = Query.Equals<CrawledSubnet>("Network", network);
|
||||||
CrawledSubnet sn = CrawledSubnets.Query(subnetQuery).FirstOrDefault();
|
CrawledSubnet sn = SkyScanner.Instance.Entities.CrawledSubnets.Query(subnetQuery).FirstOrDefault();
|
||||||
if (sn == null)
|
if (sn == null)
|
||||||
{
|
{
|
||||||
Logging.Log(LogLevel.INFO, "Crawler adds new subnet: {0}", network);
|
Logging.Log(LogLevel.INFO, "Crawler adds new subnet: {0}", network);
|
||||||
sn = new CrawledSubnet(network);
|
sn = new CrawledSubnet(network);
|
||||||
CrawledSubnets.Insert(sn);
|
SkyScanner.Instance.Entities.CrawledSubnets.Insert(sn);
|
||||||
}
|
}
|
||||||
return sn;
|
return sn;
|
||||||
}
|
}
|
||||||
|
@ -241,13 +221,13 @@ namespace ln.skyscanner.crawl
|
||||||
SkyScanner.Entities.GlobalNetwork.Update();
|
SkyScanner.Entities.GlobalNetwork.Update();
|
||||||
|
|
||||||
if (CrawlHosts)
|
if (CrawlHosts)
|
||||||
foreach (CrawledHost crawledHost in CrawledHosts.Where( host => (host.NextCheck < DateTime.Now)))
|
foreach (CrawledHost crawledHost in SkyScanner.Instance.Entities.CrawledHosts.Where( host => (host.NextCheck < DateTime.Now)))
|
||||||
{
|
{
|
||||||
Crawl(crawledHost);
|
Crawl(crawledHost);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CrawlSubnets)
|
if (CrawlSubnets)
|
||||||
foreach (CrawledSubnet subnet in CrawledSubnets.Where( sn => (sn.NextScan < DateTime.Now ) && sn.Network.Width >= 24))
|
foreach (CrawledSubnet subnet in SkyScanner.Instance.Entities.CrawledSubnets.Where( sn => (sn.NextScan < DateTime.Now ) && sn.Network.Width >= 24))
|
||||||
{
|
{
|
||||||
Crawl(subnet);
|
Crawl(subnet);
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,45 +20,31 @@ namespace ln.skyscanner.entities
|
||||||
{
|
{
|
||||||
public class GlobalNetwork : Persistent
|
public class GlobalNetwork : Persistent
|
||||||
{
|
{
|
||||||
[Unsynced]
|
|
||||||
public SkyScanner SkyScanner => SkyScanner.Instance;
|
|
||||||
[Unsynced]
|
|
||||||
public SkyEntities SkyEntities { get; private set; }
|
|
||||||
|
|
||||||
public IEnumerable<Subnet> Subnets => SkyEntities.subnetCollection;
|
|
||||||
public IEnumerable<Node> Nodes => SkyEntities.nodeCollection.ToArray();
|
|
||||||
|
|
||||||
public HopMap DefaultHopMap { get; private set; } = new HopMap();
|
public HopMap DefaultHopMap { get; private set; } = new HopMap();
|
||||||
|
|
||||||
private object _updateLock = new object();
|
private object _updateLock = new object();
|
||||||
|
|
||||||
public GlobalNetwork()
|
public GlobalNetwork()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public GlobalNetwork(SkyEntities skyEntities)
|
|
||||||
{
|
|
||||||
SkyEntities = skyEntities;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void EnsureSubnet(Network4 network)
|
public void EnsureSubnet(Network4 network)
|
||||||
{
|
{
|
||||||
Subnet subnet = SkyEntities.subnetCollection.Where(s => s.Network.Equals(network)).FirstOrDefault();
|
Subnet subnet = SkyScanner.Instance.Entities.SubnetCollection.Where(s => s.Network.Equals(network)).FirstOrDefault();
|
||||||
if (subnet == null)
|
if (subnet == null)
|
||||||
{
|
{
|
||||||
subnet = new Subnet(network);
|
subnet = new Subnet(network);
|
||||||
SkyEntities.subnetCollection.Upsert(subnet);
|
SkyScanner.Instance.Entities.SubnetCollection.Upsert(subnet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Node GetNode(Guid id)
|
public Node GetNode(Guid id)
|
||||||
{
|
{
|
||||||
return SkyEntities.nodeCollection[id];
|
return SkyScanner.Instance.Entities.NodeCollection[id];
|
||||||
}
|
}
|
||||||
|
|
||||||
public Subnet FindSubnetForIP(IPv4 ip)
|
public Subnet FindSubnetForIP(IPv4 ip)
|
||||||
{
|
{
|
||||||
return SkyEntities.subnetCollection.Where((net) => net.Network.Contains(ip)).FirstOrDefault();
|
return SkyScanner.Instance.Entities.SubnetCollection.Where((net) => net.Network.Contains(ip)).FirstOrDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Node> FindHostsInSubnet(Network4 network)
|
public IEnumerable<Node> FindHostsInSubnet(Network4 network)
|
||||||
|
@ -70,7 +56,7 @@ namespace ln.skyscanner.entities
|
||||||
Query.Equals<Node>("Interfaces[].ConfiguredIPs[].Network", network),
|
Query.Equals<Node>("Interfaces[].ConfiguredIPs[].Network", network),
|
||||||
Query.IF<Node>("PrimaryIP", (ip) => ((firstIP <= ip) && (ip <= lastIP)))
|
Query.IF<Node>("PrimaryIP", (ip) => ((firstIP <= ip) && (ip <= lastIP)))
|
||||||
);
|
);
|
||||||
return SkyEntities.nodeCollection.Query(nodeByIpQuery);
|
return SkyScanner.Instance.Entities.NodeCollection.Query(nodeByIpQuery);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Node> FindNeighbors(Node node)
|
public IEnumerable<Node> FindNeighbors(Node node)
|
||||||
|
@ -107,11 +93,11 @@ namespace ln.skyscanner.entities
|
||||||
|
|
||||||
public Node FindNodeByIP(IPv4 ip)
|
public Node FindNodeByIP(IPv4 ip)
|
||||||
{
|
{
|
||||||
Node node = SkyEntities.nodeCollection.Query("PrimaryIP", ip).FirstOrDefault();
|
Node node = SkyScanner.Instance.Entities.NodeCollection.Query("PrimaryIP", ip).FirstOrDefault();
|
||||||
if (node == null)
|
if (node == null)
|
||||||
{
|
{
|
||||||
Query nodeByIpQuery = Query.Equals<Node>("Interfaces[].ConfiguredIPs[].IP", ip);
|
Query nodeByIpQuery = Query.Equals<Node>("Interfaces[].ConfiguredIPs[].IP", ip);
|
||||||
node = SkyEntities.nodeCollection.Query(nodeByIpQuery).FirstOrDefault();
|
node = SkyScanner.Instance.Entities.NodeCollection.Query(nodeByIpQuery).FirstOrDefault();
|
||||||
}
|
}
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
@ -172,7 +158,7 @@ namespace ln.skyscanner.entities
|
||||||
node.Name = crawledHost.Name;
|
node.Name = crawledHost.Name;
|
||||||
node.PrimaryMac = crawledHost.PrimaryHWAddr;
|
node.PrimaryMac = crawledHost.PrimaryHWAddr;
|
||||||
|
|
||||||
SkyEntities.nodeCollection.Insert(node);
|
SkyScanner.Instance.Entities.NodeCollection.Insert(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!crawledHost.PrimaryIP.Equals(node.PrimaryIP))
|
if (!crawledHost.PrimaryIP.Equals(node.PrimaryIP))
|
||||||
|
@ -298,7 +284,7 @@ namespace ln.skyscanner.entities
|
||||||
EnsureSubnet(network);
|
EnsureSubnet(network);
|
||||||
|
|
||||||
node.LastUpdate = DateTime.Now;
|
node.LastUpdate = DateTime.Now;
|
||||||
SkyEntities.nodeCollection.Upsert(node);
|
SkyScanner.Instance.Entities.NodeCollection.Upsert(node);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,7 +47,7 @@ namespace ln.skyscanner.entities
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public IEnumerable<Network4> Networks => Interfaces.SelectMany(intf => intf.ConfiguredIPs.Select(nip => nip.Network)).Distinct();
|
public IEnumerable<Network4> Networks => Interfaces.SelectMany(intf => intf.ConfiguredIPs.Select(nip => nip.Network)).Distinct();
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public IEnumerable<Subnet> Subnets => SkyScanner.Instance.Entities.subnetCollection.Query(Query.Equals<Network4>("Network", Networks.Select(net => net.Network)));
|
public IEnumerable<Subnet> Subnets => SkyScanner.Instance.Entities.SubnetCollection.Query(Query.Equals<Network4>("Network", Networks.Select(net => net.Network)));
|
||||||
|
|
||||||
private string uniqueIdentity;
|
private string uniqueIdentity;
|
||||||
public String UniqueIdentity {
|
public String UniqueIdentity {
|
||||||
|
|
|
@ -14,6 +14,7 @@ using System.Linq;
|
||||||
using ln.types;
|
using ln.types;
|
||||||
using ln.types.odb.attributes;
|
using ln.types.odb.attributes;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
using ln.types.odb.collections;
|
||||||
namespace ln.skyscanner.entities
|
namespace ln.skyscanner.entities
|
||||||
{
|
{
|
||||||
public class PointOfPresence
|
public class PointOfPresence
|
||||||
|
@ -24,20 +25,17 @@ namespace ln.skyscanner.entities
|
||||||
public String Name { get; set; }
|
public String Name { get; set; }
|
||||||
public String ForeignName { get; set; }
|
public String ForeignName { get; set; }
|
||||||
|
|
||||||
|
public RefList<Node> Nodes { get; private set; } = new RefList<Node>();
|
||||||
|
|
||||||
public GeoLocation GeoLocation { get; set; }
|
public GeoLocation GeoLocation { get; set; }
|
||||||
|
|
||||||
[JsonIgnore]
|
|
||||||
public Node[] Nodes => SkyScanner.Instance.Entities.nodeCollection.Query(Query.Equals<Node>("ID", nodeIDList.Select(id => ODBMapper.Default.MapValue(id)).ToArray())).ToArray();
|
|
||||||
HashSet<Guid> nodeIDList = new HashSet<Guid>();
|
|
||||||
|
|
||||||
public DateTime Created { get; private set; } = DateTime.Now;
|
public DateTime Created { get; private set; } = DateTime.Now;
|
||||||
|
|
||||||
public PointOfPresence()
|
public PointOfPresence()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddNode(Node node) => nodeIDList.Add(node.ID);
|
public void AddNode(Node node) => Nodes.Add(node);
|
||||||
public void RemoveNode(Node node) => nodeIDList.Remove(node.ID);
|
public void RemoveNode(Node node) => Nodes.Remove(node);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -24,13 +24,13 @@ namespace ln.skyscanner.http
|
||||||
[Callable]
|
[Callable]
|
||||||
public CrawledSubnet[] GetSubnets()
|
public CrawledSubnet[] GetSubnets()
|
||||||
{
|
{
|
||||||
return Crawler?.CrawledSubnets.ToArray();
|
return SkyScanner.Instance.Entities.CrawledSubnets.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Callable]
|
[Callable]
|
||||||
public CrawledHost[] GetHosts()
|
public CrawledHost[] GetHosts()
|
||||||
{
|
{
|
||||||
CrawledHost[] result = Crawler?.CrawledHosts.ToArray();
|
CrawledHost[] result = SkyScanner.Instance.Entities.CrawledHosts.ToArray();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,17 +46,17 @@ namespace ln.skyscanner.http
|
||||||
IPv4 ip = IPv4.Parse(_ip);
|
IPv4 ip = IPv4.Parse(_ip);
|
||||||
CrawledHost host = SkyScanner.Crawler.FindHostForIP(ip);
|
CrawledHost host = SkyScanner.Crawler.FindHostForIP(ip);
|
||||||
host.Name = name;
|
host.Name = name;
|
||||||
SkyScanner.Crawler.CrawledHosts.Upsert(host);
|
SkyScanner.Instance.Entities.CrawledHosts.Upsert(host);
|
||||||
return host;
|
return host;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Callable]
|
[Callable]
|
||||||
public void TriggerRecrawl()
|
public void TriggerRecrawl()
|
||||||
{
|
{
|
||||||
foreach (CrawledHost host in Crawler.CrawledHosts.ToArray())
|
foreach (CrawledHost host in SkyScanner.Instance.Entities.CrawledHosts.ToArray())
|
||||||
{
|
{
|
||||||
host.NextCheck = DateTime.Now;
|
host.NextCheck = DateTime.Now;
|
||||||
Crawler.CrawledHosts.Upsert(host);
|
SkyScanner.Instance.Entities.CrawledHosts.Upsert(host);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,26 +115,26 @@ namespace ln.skyscanner.http
|
||||||
[Callable]
|
[Callable]
|
||||||
public Network4[] GetBlockedNetworks()
|
public Network4[] GetBlockedNetworks()
|
||||||
{
|
{
|
||||||
return Crawler.BlockedNetworks.ToArray();
|
return SkyScanner.Instance.Entities.BlockedNetworks.ToArray();
|
||||||
}
|
}
|
||||||
[Callable]
|
[Callable]
|
||||||
public void AddBlockedNetwork(string _network)
|
public void AddBlockedNetwork(string _network)
|
||||||
{
|
{
|
||||||
Network4 blocked = Network4.Parse(_network);
|
Network4 blocked = Network4.Parse(_network);
|
||||||
if (!Crawler.BlockedNetworks.Contains(blocked))
|
if (!SkyScanner.Instance.Entities.BlockedNetworks.Contains(blocked))
|
||||||
{
|
{
|
||||||
Crawler.BlockedNetworks.Insert(blocked);
|
SkyScanner.Instance.Entities.BlockedNetworks.Insert(blocked);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
[Callable]
|
[Callable]
|
||||||
public void RemoveBlockedNetwork(string _network)
|
public void RemoveBlockedNetwork(string _network)
|
||||||
{
|
{
|
||||||
Network4 blocked = Network4.Parse(_network);
|
Network4 blocked = Network4.Parse(_network);
|
||||||
foreach (Network4 blockedNetwork in Crawler.BlockedNetworks)
|
foreach (Network4 blockedNetwork in SkyScanner.Instance.Entities.BlockedNetworks)
|
||||||
{
|
{
|
||||||
if (blockedNetwork.Equals(blocked))
|
if (blockedNetwork.Equals(blocked))
|
||||||
{
|
{
|
||||||
Crawler.BlockedNetworks.Delete(blockedNetwork);
|
SkyScanner.Instance.Entities.BlockedNetworks.Delete(blockedNetwork);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,13 +25,6 @@ namespace ln.skyscanner.http
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
[Callable]
|
|
||||||
public Node[] GetNodes()
|
|
||||||
{
|
|
||||||
Node[] nodes = GlobalNetwork.Nodes.ToArray();
|
|
||||||
return nodes;
|
|
||||||
}
|
|
||||||
|
|
||||||
[Callable]
|
[Callable]
|
||||||
public Node[] GetNeighbors(string pid)
|
public Node[] GetNeighbors(string pid)
|
||||||
{
|
{
|
||||||
|
|
|
@ -4,6 +4,8 @@ using ln.http.resources;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using ln.skyscanner.entities;
|
using ln.skyscanner.entities;
|
||||||
using ln.skyscanner.checks;
|
using ln.skyscanner.checks;
|
||||||
|
using ln.skyscanner.crawl;
|
||||||
|
using ln.types.net;
|
||||||
namespace ln.skyscanner.http
|
namespace ln.skyscanner.http
|
||||||
{
|
{
|
||||||
public class SkyScannerHttpApplication : ResourceApplication
|
public class SkyScannerHttpApplication : ResourceApplication
|
||||||
|
@ -35,10 +37,17 @@ namespace ln.skyscanner.http
|
||||||
SkyScannerHttpApi api = new SkyScannerHttpApi(this);
|
SkyScannerHttpApi api = new SkyScannerHttpApi(this);
|
||||||
|
|
||||||
BaseResource collections = new BaseResource(RootResource, "collections");
|
BaseResource collections = new BaseResource(RootResource, "collections");
|
||||||
new CollectionResource<PointOfPresence>(collections, skyScanner.Entities.popCollection);
|
|
||||||
new CollectionResource<Node>(collections, skyScanner.Entities.nodeCollection);
|
new CollectionResource<Node>(collections, skyScanner.Entities.NodeCollection);
|
||||||
new CollectionResource<Subnet>(collections, skyScanner.Entities.subnetCollection);
|
new CollectionResource<Subnet>(collections, skyScanner.Entities.SubnetCollection);
|
||||||
new CollectionResource<SkyCheckState>(collections, skyScanner.Checker.checkStates);
|
new CollectionResource<PointOfPresence>(collections, skyScanner.Entities.PointOfPresenceCollection);
|
||||||
|
|
||||||
|
new CollectionResource<CrawledHost>(collections, skyScanner.Entities.CrawledHosts);
|
||||||
|
new CollectionResource<CrawledSubnet>(collections, skyScanner.Entities.CrawledSubnets);
|
||||||
|
|
||||||
|
new CollectionResource<SkyCheckState>(collections, skyScanner.Entities.SkyCheckStates);
|
||||||
|
|
||||||
|
new CollectionResource<Network4>(collections, skyScanner.Entities.BlockedNetworks);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Resource ResourceTypeHook(DirectoryResource directoryResource, FileInfo fileInfo)
|
private Resource ResourceTypeHook(DirectoryResource directoryResource, FileInfo fileInfo)
|
||||||
|
|
|
@ -17,10 +17,10 @@
|
||||||
var dtDef = {
|
var dtDef = {
|
||||||
columns: [
|
columns: [
|
||||||
{ title: "CheckName", data: "CheckName" },
|
{ title: "CheckName", data: "CheckName" },
|
||||||
{ title: "UniqueNodeIdentifier", data: "UniqueNodeIdentifier" },
|
{ title: "Node", data: "Node.Name" },
|
||||||
{ title: "LastCheckTime", data: "LastCheckTime" },
|
{ title: "LastCheckTime", data: "LastCheckTime" },
|
||||||
{ title: "CheckState", data: "CheckState" },
|
{ title: "CheckState", data: "CheckState" },
|
||||||
{ title: "Check Schwere", data: null, render: function(d,t,r){ return "-"; } },
|
{ title: "Check Schwere", data: "Node.Severity" },
|
||||||
],
|
],
|
||||||
ajax: {
|
ajax: {
|
||||||
url: "/collections/SkyCheckState",
|
url: "/collections/SkyCheckState",
|
||||||
|
|
Loading…
Reference in New Issue