public override int Scan() { if (!Open()) { return(-1); } base.Scan(); var totalLines = 0; foreach (var kpi in Kpis) { var lines = Ssh.Exec(kpi.Command).Split(Environment.NewLine.ToCharArray()) .Select(i => i.Trim()).Where(i => !string.IsNullOrEmpty(i)) .Select(LineToObject).ToList(); totalLines += lines.Count; Result.Add(kpi.Name, lines); } if (Persistence != null) { Persistence.Save(Machine, GetResult()); } return(totalLines); }
/// <summary> /// In progress... /// Get the operating system of specified machine. The credentials must be provided. /// For now it can identify Ubuntu, Debian and Windows /// </summary> /// <param name="machineName"></param> /// <param name="userName"></param> /// <param name="password"></param> /// <param name="privateKeyFileName"></param> /// <returns></returns> public static OperatingSystems GetMachineOs(string machineName, string userName, string password, string privateKeyFileName) { //TODO: This function did not detect Windows on localhost! var result = OperatingSystems.Unknown; var ssh = new SshHelper.SshHelper() { Host = machineName, UserName = userName, Password = password, PrivateKeyFileName = privateKeyFileName }; var os = ssh.Exec("cat /etc/issue"); if (!string.IsNullOrEmpty(os)) { os = os.ToLower(); if (os.IndexOf("ubuntu", StringComparison.Ordinal) >= 0 || os.IndexOf("debian", StringComparison.Ordinal) >= 0) { result = OperatingSystems.Aptitude; } } else { var ws = new WindowsScanner(machineName, userName, password, null); if (!ws.Open()) { return(result); } ws.ScanWmiClass("Win32_OperatingSystem", (new[] { new Field { Name = "Name", MapTo = "Name" } }).ToList()); if (ws.Result.Count > 0) { result = OperatingSystems.Windows; } } return(result); }