public ShellCommand(CommandConfiguration commandConfiguration, string unparsedCommand) : base(commandConfiguration, unparsedCommand) { var cmd = unparsedCommand.Split(new char[] { ' ' }, 2); _filename = cmd[0]; if (cmd.Length > 1) _arguments = cmd[1]; }
public static Command Create(CommandConfiguration commandConfiguration, string command) { var command_lower = command.ToLower(); if (command_lower.StartsWith(PerformanceCounterCommand.PREFIX)) return new PerformanceCounterCommand(commandConfiguration, command); if (command_lower.StartsWith(HTTPCommand.PREFIX)) return new HTTPCommand(commandConfiguration, command); if (command_lower.Contains(".ps1")) return new PowerShellCommand(commandConfiguration, command); if (command_lower.Contains(".rb")) return new RubyCommand(commandConfiguration, command); return new ShellCommand(commandConfiguration, command); }
public bool ExecuteUpdateCheck(CommandConfiguration configuration, JObject check) { UpdateFile file = new Update.UpdateFile(configuration.Plugins, check); if (File.Exists(file.filepath)) { try { file = ReadUpdateFile(file); bool performUpdate = CompareTimeForUpdate(file); if (performUpdate) { file.FileTimestamp = DateTime.Today; DownloadUpdate(file, check); WriteUpdateFile(file); return true; } } catch (Exception e) { if (e is IOException) { throw new Exception("IOException: " + e.StackTrace); } else if (e is UnauthorizedAccessException) { FileAttributes attr = (new FileInfo(file.filepath)).Attributes; string exception = "UnAuthorizedAccesException: Unable to access file. "; if ((attr & FileAttributes.ReadOnly) > 0) { exception = exception + "File is readonly"; } throw new Exception(exception + " Stacktrace: " + e.StackTrace); } } } else if (!File.Exists(file.filepath) || !File.Exists(file.checkFilePath)) { file.FileTimestamp = DateTime.Today; DownloadUpdate(file, check); createUpdateFile(file); return true; } return false; }
public void ExecuteCheckCommand(JObject check, bool withUpdateCheck) { Log.Debug("Attempting to execute check command {0}", JsonConvert.SerializeObject(check, SerializerSettings)); if (check["name"] == null) { CheckDidNotHaveValidName(check); return; } var checkName = check["name"].ToString(); if (!checksInProgress.Lock(checkName)) return; try { var commandParseErrors = ""; check["command"] = SensuClientHelper.SubstitueCommandTokens( check, out commandParseErrors, (JObject)_sensuClientConfigurationReader.Configuration.Config["client"]); if (!String.IsNullOrEmpty(commandParseErrors)) { Log.Warn("Errors parsing the command: {0}", commandParseErrors); CheckDidNotHaveValidParameters(check, commandParseErrors); throw new Exception(String.Format("Errors parsing the command {0}", commandParseErrors)); } Log.Debug("Preparing check to be launched: {0}", checkName); int? timeout = null; if (check["timeout"] != null) timeout = SensuClientHelper.TryParseNullable(check["timeout"].ToString()); CommandConfiguration configuration = new CommandConfiguration(); configuration.Plugins = _sensuClientConfigurationReader.SensuClientConfig.Client.Plugins; configuration.TimeOut = timeout; var commandToExcecute = CommandFactory.Create(configuration , check["command"].ToString()); if (commandToExcecute is Command.RemoteCommand) { try { Log.Debug("About to run update: " + checkName); UpdateScheduler scheduler = new UpdateScheduler(); scheduler.ExecuteUpdateCheck(configuration, check); } catch (Exception e) { Log.Warn(e, "Error preparing update {0}", checkName); } } Log.Debug("About to run command: " + checkName); var executingTask = ExecuteCheck(check, commandToExcecute); checksInProgress.SetTask(checkName, executingTask); executingTask.ContinueWith<JObject>(ReportCheckResultAfterCompletion).ContinueWith(CheckCompleted); } catch (Exception e) { Log.Error(e, "Error preparing check {0}", checkName); checksInProgress.UnlockAnyway(checkName); } }
/*RemoteCommand that allows the sensu client to execute a powershell script from a specific URL*/ public RemoteCommand(CommandConfiguration commandConfiguration, string unparsedCommand) : base(commandConfiguration, unparsedCommand) { }
protected Command(CommandConfiguration commandConfiguration, string unparsedCommand) { _commandConfiguration = commandConfiguration; _unparsedCommand = unparsedCommand; }
public PerformanceCounterCommand(CommandConfiguration commandConfiguration, string unparsedCommand) : base(commandConfiguration, unparsedCommand) { }
public HTTPCommand(CommandConfiguration commandConfiguration, string unparsedCommand) : base(commandConfiguration, unparsedCommand) { ParseArguments(); }
public PowerShellCommand(CommandConfiguration commandConfiguration, string unparsedCommand) : base(commandConfiguration, unparsedCommand) { }
public RubyCommand(CommandConfiguration commandConfiguration, string unparsedCommand) : base(commandConfiguration, unparsedCommand) { }
public void Init() { _configuration = new CommandConfiguration { Plugins = @"c:\etc\plugins" }; }