public static CBSensor getCBSensorInfo(string ComputerName) { int sensorId = -1; var answer = new CBSensor(); var client = new RestClient(iCrt_01.Properties.Resources.CBMasServer); var request = new RestRequest(); request.AddHeader("X-Auth-Token", iCrt_01.Properties.Resources.CBApiKey); request.Resource = "/v1/sensor?hostname=" + ComputerName; request.RootElement = "CBSensor"; var response = client.Execute <List <CBSensor> >(request); try { foreach (CBSensor item in response.Data) { if (item.id > sensorId) { sensorId = item.id; answer = item; } } } catch { } return(answer); }
public static int GetSensorIdForHost(string ComputerName) { int sensorId = -1; ServicePointManager.ServerCertificateValidationCallback = delegate { return(true); }; var answer = new CBSensor(); var client = new RestClient(iCrt_01.Properties.Resources.CBMasServer); var request = new RestRequest(); //int sensorId = ""; request.AddHeader("X-Auth-Token", iCrt_01.Properties.Resources.CBApiKey); request.Resource = "/v1/sensor?hostname=" + ComputerName; request.RootElement = "CBSensor"; var response = client.Execute <List <CBSensor> >(request); foreach (CBSensor item in response.Data) { if (item.id > sensorId) { sensorId = item.id; answer = item; } } sensorId = answer.id; return(sensorId); }
public void GetInfoBox() { bool Isonline; Computername = textBox1.Text; //Machine preflight checks is it online? Isonline = BEFunctions.MachineOnline(Computername); if (Isonline == true) { tb_Display.AppendText("Machine is online"); tb_Display.AppendText(Environment.NewLine); if (BEFunctions.canReachPath(Computername)) { tb_Display.AppendText("Admin share is accessible"); tb_Display.AppendText(Environment.NewLine); rb_Online.Checked = true; bt_Install.Enabled = true; } else { tb_Display.AppendText("Admin share is inaccessible"); tb_Display.AppendText(Environment.NewLine); rb_Offline.Checked = true; } //IS CB Installed? if (rb_Online.Checked) { if (BEFunctions.isCBInstalled(Computername)) { tb_Display.AppendText("Carbon Black local install found"); tb_Display.AppendText(Environment.NewLine); bt_Uninstall.Enabled = true; } else { tb_Display.AppendText("Carbon Black local install NOT found"); tb_Display.AppendText(Environment.NewLine); } } CBSensor cbSensor = BEFunctions.getCBSensorInfo(Computername); if (!(cbSensor.id == 0)) { tb_Display.AppendText("Carbon Black sensor found on server: " + cbSensor.id); tb_Display.AppendText(Environment.NewLine); tb_Display.AppendText("Carbon Black sensor version: " + cbSensor.build_version_string); tb_Display.AppendText(Environment.NewLine); tb_Display.AppendText("CB Last check-in: " + cbSensor.last_checkin_time); tb_Display.AppendText(Environment.NewLine); tb_Display.AppendText("CB Client OS: " + cbSensor.os_environment_display_string); tb_Display.AppendText(Environment.NewLine); bt_ViewFiles.Enabled = true; bt_LR_Install.Enabled = true; } else { tb_Display.AppendText("Carbon Black sensor instance not found."); tb_Display.AppendText(Environment.NewLine); } } else { tb_Display.AppendText("Machine hostname is offline."); tb_Display.AppendText(Environment.NewLine); rb_Offline.Checked = true; bt_Install_Sched.Enabled = true; CBSensor cbSensor = BEFunctions.getCBSensorInfo(Computername); if (!(cbSensor.id == 0)) { tb_Display.AppendText("Carbon Black sensor found on server: " + cbSensor.id); tb_Display.AppendText(Environment.NewLine); tb_Display.AppendText("Carbon Black sensor version: " + cbSensor.build_version_string); tb_Display.AppendText(Environment.NewLine); tb_Display.AppendText("CB Last check-in: " + cbSensor.last_checkin_time); tb_Display.AppendText(Environment.NewLine); tb_Display.AppendText("CB Client OS: " + cbSensor.os_environment_display_string); tb_Display.AppendText(Environment.NewLine); //bt_ViewFiles.Enabled = true; bt_LR_Install.Enabled = true; } else { tb_Display.AppendText("Carbon Black sensor instance not found."); tb_Display.AppendText(Environment.NewLine); } } }