예제 #1
0
		private bool IsHostInactive (DBHostStatusView host) {
			var has_no_lanes = String.IsNullOrEmpty (host.lane);
			return has_no_lanes && !IsHostDead (host);
		}
예제 #2
0
		private bool IsHostDead (DBHostStatusView status) {
			var silence = DateTime.Now - status.report_date;
			return silence.TotalHours >= 3;
		}
예제 #3
0
		private JObject GetHostStatuses(DB db) {
			var result = new JObject ();

			var activeHosts = new JArray ();
			var inactiveHosts = new JArray ();
			var downHosts = new JArray ();

			using (var cmd = db.CreateCommand (@"
				SELECT * FROM HostStatusView;
			"))
			using (var reader = cmd.ExecuteReader ()) {
				while (reader.Read ()) {
					var status = new DBHostStatusView (reader);
					if (IsHostActive (status))
						activeHosts.Add (status.host);
					else if (IsHostInactive (status))
						inactiveHosts.Add (status.host);
					else if (IsHostDead (status))
						downHosts.Add (status.host);
					else
						log.ErrorFormat ("Host {0} ({1}) isn't active, inactive, or dead.", status.host, status.id);
				}
			}

			result ["inactiveNodes"] = inactiveHosts;
			result ["activeNodes"] = activeHosts;
			result ["downNodes"] = downHosts;
			return result;
		}