public override List <System.Data.DataTable> GetDetailDataTables() { List <System.Data.DataTable> tables = new List <System.Data.DataTable>(); System.Data.DataTable dt = new System.Data.DataTable(); try { dt.Columns.Add(new System.Data.DataColumn("Computer", typeof(string))); dt.Columns.Add(new System.Data.DataColumn("Name", typeof(string))); dt.Columns.Add(new System.Data.DataColumn("Output", typeof(string))); LinuxSSHCommandCollectorConfig currentConfig = (LinuxSSHCommandCollectorConfig)AgentConfig; foreach (LinuxSSHCommandEntry entry in currentConfig.Entries) { string output = entry.ExecuteCommand(); dt.Rows.Add(entry.SSHConnection.ComputerName, entry.Name, output); } } catch (Exception ex) { dt = new System.Data.DataTable("Exception"); dt.Columns.Add(new System.Data.DataColumn("Text", typeof(string))); dt.Rows.Add(ex.ToString()); } tables.Add(dt); return(tables); }
public override MonitorState RefreshState() { MonitorState returnState = new MonitorState(); string lastAction = ""; int errors = 0; int warnings = 0; int success = 0; double sumValue = 0; try { LinuxSSHCommandCollectorConfig currentConfig = (LinuxSSHCommandCollectorConfig)AgentConfig; returnState.CurrentValue = null; foreach (LinuxSSHCommandEntry entry in currentConfig.Entries) { string value = entry.ExecuteCommand(); CollectorState currentState = CollectorAgentReturnValueCompareEngine.GetState(entry.ValueReturnCheckSequence, entry.SuccessMatchType, entry.SuccessValueOrMacro, entry.WarningMatchType, entry.WarningValueOrMacro, entry.ErrorMatchType, entry.ErrorValueOrMacro, value); if (value.IsNumber()) { sumValue += Double.Parse(value.ToString()); } if (currentState == CollectorState.Error) { errors++; } else if (currentState == CollectorState.Warning) { warnings++; } else { success++; } returnState.ChildStates.Add( new MonitorState() { ForAgent = entry.Name, State = currentState, CurrentValue = value.ToString(), CurrentValueUnit = "" }); } if (sumValue > 0) { returnState.CurrentValue = sumValue; } if (errors > 0 && warnings == 0 && success == 0) // any errors { returnState.State = CollectorState.Error; } else if (errors > 0 || warnings > 0) //any warnings { returnState.State = CollectorState.Warning; } else { returnState.State = CollectorState.Good; } } catch (Exception ex) { returnState.RawDetails = ex.Message; returnState.HtmlDetails = string.Format("<p><b>Last action:</b> {0}</p><blockquote>{1}</blockquote>", lastAction, ex.Message); returnState.State = CollectorState.Error; } return(returnState); }
public LinuxSSHCommandCollector() { AgentConfig = new LinuxSSHCommandCollectorConfig(); }