/// <summary> /// OMSBaseline custom checks configuration enabled predicate /// </summary> protected IEnumerable <BaselinePayload> ExecuteBaseline(string command) { string output = _processUtil.ExecuteBashShellCommand(command); if (string.IsNullOrWhiteSpace(output)) { throw new ApplicationException("attempt to run baseline scan failed"); } BaselineScanOutput deserializedOutput = JsonConvert.DeserializeObject <BaselineScanOutput>(output); if (!string.IsNullOrWhiteSpace(deserializedOutput.Error)) { throw new ApplicationException($"baseline scan failed with error: {deserializedOutput.Error}"); } else if (deserializedOutput.Results == null) { throw new ApplicationException($"baseline results are null"); } deserializedOutput.Results.RemoveAll(result => result.Result == BaselineResult.ResultType.Pass || result.Result == BaselineResult.ResultType.Skip); var payloads = deserializedOutput.Results.Select(GetPayloadFromResult); SimpleLogger.Debug($"BaselineEventGenerator returns {payloads.Count()} payloads"); return(payloads); }
/// <summary> /// Run the baseline scan and get the results as a baseline event /// </summary> /// <returns>Baseline event</returns> protected override List <IEvent> GetEventsImpl() { string agentDirectory = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); string bitnessSuffix = RuntimeInformation.OSArchitecture == Architecture.Arm64 || RuntimeInformation.OSArchitecture == Architecture.X64 ? "x64" : "x86"; string output = _processUtil.ExecuteBashShellCommand(string.Format(BaselineExecCommandTemplate, agentDirectory, bitnessSuffix)); if (string.IsNullOrWhiteSpace(output)) { throw new ApplicationException("attempt to run baseline scan failed"); } BaselineScanOutput deserializedOutput = JsonConvert.DeserializeObject <BaselineScanOutput>(output); if (!string.IsNullOrWhiteSpace(deserializedOutput.Error)) { throw new ApplicationException($"baseline scan failed with error: {deserializedOutput.Error}"); } else if (deserializedOutput.Results == null) { throw new ApplicationException($"baseline results are null"); } deserializedOutput.Results.RemoveAll(result => result.Result == BaselineResult.ResultType.Pass || result.Result == BaselineResult.ResultType.Skip); var payloads = deserializedOutput.Results.Select(GetPayloadFromResult); SimpleLogger.Debug($"BaselineEventGenerator returns {payloads.Count()} payloads"); var ev = new OSBaseline(Priority, payloads.ToArray()); return(new List <IEvent> { ev }); }