예제 #1
0
		public void NotifyRalph(object stateObject)
		{
			if (
				RalphURL.Trim().Length == 0 || 
				ApiUser.Trim().Length == 0 || 
				ApiKey.Trim().Length == 0
			)
			{
				Logger.Instance.LogWarning(
					"To send data to Ralph set up ralph_url, api_user and api_key in your config file."
				);
				return;
			}
			
			Detector d = new Detector();
			string jsonData = d.GetAllComponentsJSON();

			Logger.Instance.LogInformation("Sending to: " + ReportURL);

			int tries = 0;
			while (tries < MaxTries)
			{
				tries++;
				try
				{
					apiClient.Post(ReportURL + "/?username="******"&api_key=" + ApiKey, jsonData);
					return;
				}
				catch (System.Net.WebException e)
				{
					string serverMessage = "";
					if (e.Response != null)
					{
						StreamReader s = new StreamReader(e.Response.GetResponseStream());
						serverMessage = s.ReadToEnd();
					}
					Logger.Instance.LogError(
						String.Format(
							"Error while sending data to {0}: {1}. Full response: \"{2}\". Waiting for {3} try.",
							RalphURL, 
							e.Message,
							serverMessage, 
							tries + 1
						)
					);
					System.Threading.Thread.Sleep(SecondsInterval * 1000);
				}
				catch (Exception e)
				{
					Logger.Instance.LogError(e.ToString());
				}
			}
		}
예제 #2
0
		public void Print(Detector d, bool jsonOnly)
		{
			if (jsonOnly)
			{
				Console.WriteLine(d.GetAllComponentsJSON());
			}
			else
			{
				Console.WriteLine("Detected CPUs:");
				foreach(ProcessorDTOResponse item in d.GetProcessorsInfo())
				{
					PropertiesPrinter.Print(item);
				}
				
				Console.WriteLine("\nDetected memory:");
				foreach(MemoryDTOResponse item in d.GetMemoryInfo())
				{
					PropertiesPrinter.Print(item);
				}
				
				Console.WriteLine("\nDetected OS:");
				OperatingSystemDTOResponse os = d.GetOperatingSystemInfo();
				PropertiesPrinter.Print(os);
				
				Console.WriteLine("\nDetected storage:");
				foreach(StorageDTOResponse item in d.GetStorageInfo())
				{
					PropertiesPrinter.Print(item);
				}
				
				Console.WriteLine("\nDetected IP addresses:");
				foreach(IPAddressDTOResponse item in d.GetIPAddressInfo())
				{
					PropertiesPrinter.Print(item);
				}
				
				Console.WriteLine("\nDetected MAC addresses:");
				foreach(MacAddressDTOResponse item in d.GetMacAddressInfo())
				{
					PropertiesPrinter.Print(item);
				}
				
				Console.WriteLine("\nDetected fc cards:");
				foreach(FibreChannelDTOResponse item in d.GetFibreChannelInfo())
				{
					PropertiesPrinter.Print(item);
				}
				
				Console.WriteLine("\nDetected shares:");
				foreach(DiskShareMountDTOResponse item in d.GetDiskShareMountInfo())
				{
					PropertiesPrinter.Print(item);
				}
				
				Console.WriteLine("\nDetected software:");
				foreach(SoftwareDTOResponse item in d.GetSoftwareInfo())
				{
					PropertiesPrinter.Print(item);
				}
				
				Console.WriteLine("\nDetected device:");
				DeviceDTOResponse dev = d.GetDeviceInfo();
				PropertiesPrinter.Print(dev);
			}
		}