Skip to content

Commit

Permalink
Merge c4a9a1e into 66c32dc
Browse files Browse the repository at this point in the history
  • Loading branch information
pmarkowsky committed Sep 21, 2021
2 parents 66c32dc + c4a9a1e commit f6d7121
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 1 deletion.
6 changes: 6 additions & 0 deletions Source/common/SNTCommonEnums.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ typedef NS_ENUM(NSInteger, SNTEventLogType) {
SNTEventLogTypeFilelog,
};

typedef NS_ENUM(NSInteger, SNTMetricFormatType) {
SNTMetricFormatTypeUnknown,
SNTMetricFormatTypeRawJSON,
SNTMetricFormatTypeJSON,
};

static const char *kKextPath = "/Library/Extensions/santa-driver.kext";
static const char *kSantaDPath =
"/Applications/Santa.app/Contents/Library/SystemExtensions/"
Expand Down
16 changes: 16 additions & 0 deletions Source/common/SNTConfigurator.h
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,22 @@
///
@property(readonly, nonatomic) BOOL fcmEnabled;

///
/// True if metricsFormat and metricsURL are set. False otherwise.
///
@property(readonly, nonatomic) BOOL exportMetrics;

///
/// Format to export Metrics as.
///
@property(readonly, nonatomic) SNTMetricFormatType metricFormat;

///
/// URL describing where metrics are exported, defaults to nil.
///
@property(readonly, nonatomic) NSURL *metricURL;


///
/// Retrieve an initialized singleton configurator object using the default file path.
///
Expand Down
36 changes: 35 additions & 1 deletion Source/common/SNTConfigurator.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// Copyright 2015 Google Inc. All rights reserved.
/// Copyright 2021 Google Inc. All rights reserved.
///
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -101,6 +101,12 @@ @implementation SNTConfigurator
static NSString *const kBlockedPathRegexKey = @"BlockedPathRegex";
static NSString *const kBlockedPathRegexKeyDeprecated = @"BlacklistRegex";

// TODO(markowsky): move these to sync server only.
// Valid values for kMetricsFormat should be rawjson, and json.
// TODO(markowsky): add support for prometheus.
static NSString *const kMetricsFormat = @"MetricsFormat";
static NSString *const kMetricsURL = @"MetricsURL";

// The keys managed by a sync server.
static NSString *const kFullSyncLastSuccess = @"FullSyncLastSuccess";
static NSString *const kRuleSyncLastSuccess = @"RuleSyncLastSuccess";
Expand Down Expand Up @@ -171,6 +177,8 @@ - (instancetype)init {
kFCMProject : string,
kFCMEntity : string,
kFCMAPIKey : string,
kMetricsFormat : number,
kMetricsURL : string,
};
_defaults = [NSUserDefaults standardUserDefaults];
[_defaults addSuiteNamed:@"com.google.santa"];
Expand Down Expand Up @@ -654,6 +662,32 @@ - (BOOL)fcmEnabled {
return (self.fcmProject.length && self.fcmEntity.length && self.fcmAPIKey.length);
}


///
/// Returns YES if all of the necessary options are set to export metrics, NO
/// otherwise.
///
- (BOOL) exportMetrics {
return self.configState[kMetricsFormat] != SNTMetricFormatTypeUnknown &&
![self.configState[kMetricsURL] isEqualToString:@""];
}

- (SNTMetricFormatType)metricsFormat {
switch ([self.configState[kMetricsFormat] longLongValue]) {
case SNTMetricFormatTypeRawJSON:
return SNTMetricFormatTypeRawJSON;
case SNTMetricFormatTypeJSON:
return SNTMetricFormatTypeJSON;
default:
return SNTMetricFormatTypeUnknown;
}
}

- (NSURL *)metricsURL {
return [NSURL URLWithString:self.configState[kMetricsURL]];
}


#pragma mark Private

///
Expand Down
2 changes: 2 additions & 0 deletions docs/deployment/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ Additionally, there are options that can be controlled by both.
| EventLogType | String | Defines how event logs are stored. Options are 1) syslog: Sent to ASL or ULS (if built with the 10.12 SDK or later). 2) filelog: Sent to a file on disk. Use EventLogPath to specify a path. Defaults to filelog |
| EventLogPath | String | If EventLogType is set to filelog, EventLogPath will provide the path to save logs. Defaults to /var/db/santa/santa.log. If you change this value ensure you also update com.google.santa.newsyslog.conf with the new path. |
| EnableMachineIDDecoration | Bool | If YES, this appends the MachineID to the end of each log line. Defaults to NO. |
| MetricFormat | Integer | Format to export metrics as 0 = None, 1 = Raw JSON blob, 2 = JSON one metric per line. Defaults to 0. |
| MetricURL | String | URL describing where monitoring metrics should be exported. |

*overridable by the sync server: run `santactl status` to check the current
running config
Expand Down

0 comments on commit f6d7121

Please sign in to comment.