Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 22 additions & 22 deletions DEPNotify/TrackProgress.swift
Original file line number Diff line number Diff line change
Expand Up @@ -327,32 +327,12 @@ class TrackProgress: NSObject {
case OtherLogs.munki :
if (line.contains("Installing") || line.contains("Downloading"))
&& !line.contains(" at ") && !line.contains(" from ") {

do {
let installerRegEx = try NSRegularExpression(pattern: "^.{0,27}")
let status = installerRegEx.stringByReplacingMatches(in: line,
options: NSRegularExpression.MatchingOptions.anchored,
range: NSMakeRange(0, line.count),
withTemplate: "").trimmingCharacters(in: .whitespacesAndNewlines)
statusText = status
} catch {
NSLog("Couldn't parse ManagedSoftwareUpdate.log")
}
statusText = stripMunkiTimestamp(line)
}
case OtherLogs.airwatch :
if (line.contains("Installing") || line.contains("Downloading") || line.contains("Install of"))
&& !line.contains(" at ") && !line.contains(" from ") {

do {
let installerRegEx = try NSRegularExpression(pattern: "^.{0,27}")
let status = installerRegEx.stringByReplacingMatches(in: line,
options: NSRegularExpression.MatchingOptions.anchored,
range: NSMakeRange(0, line.count),
withTemplate: "").trimmingCharacters(in: .whitespacesAndNewlines)
statusText = status
} catch {
NSLog("Couldn't parse ManagedSoftwareUpdate.log")
}
statusText = stripMunkiTimestamp(line)
}
case OtherLogs.none :
break
Expand All @@ -364,6 +344,26 @@ class TrackProgress: NSObject {
}
}

// Strips the leading timestamp from a Munki/AirWatch log line, returning the
// status message. Handles both the pre-7 month-name format
// ("Aug 13 2026 02:11:46 -0700 ") and the Munki 7 ISO format with
// milliseconds and colon timezone ("2026-08-12 07:22:31.771-07:00 ").
func stripMunkiTimestamp(_ line: String) -> String {
let legacy = "[A-Za-z]{3} \\d{1,2} \\d{4} \\d{2}:\\d{2}:\\d{2} [-+]\\d{4}"
let iso = "\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}(\\.\\d+)?\\s*[-+]\\d{2}:?\\d{2}"
let pattern = "^(\(legacy)|\(iso))\\s+"
do {
let regex = try NSRegularExpression(pattern: pattern)
return regex.stringByReplacingMatches(in: line,
options: NSRegularExpression.MatchingOptions.anchored,
range: NSMakeRange(0, line.count),
withTemplate: "").trimmingCharacters(in: .whitespacesAndNewlines)
} catch {
NSLog("Couldn't parse ManagedSoftwareUpdate.log")
return line.trimmingCharacters(in: .whitespacesAndNewlines)
}
}

func killCommandFile() {
// delete the command file

Expand Down
15 changes: 12 additions & 3 deletions DEPNotifyTests/DEPNotifyTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,18 @@ class DEPNotifyTests: XCTestCase {
super.tearDown()
}

func testExample() {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct results.
func testStripMunkiTimestampMunki7() {
// Munki 7 format: milliseconds + colon timezone, no space before tz.
let tp = TrackProgress()
let line = "2026-08-12 07:22:31.771-07:00 Downloading GoogleChrome-1.5.pkg..."
XCTAssertEqual(tp.stripMunkiTimestamp(line), "Downloading GoogleChrome-1.5.pkg...")
}

func testStripMunkiTimestampLegacy() {
// Pre-7 format: month-name date, space before tz.
let tp = TrackProgress()
let line = "Aug 13 2026 02:11:46 -0700 Installing Foo"
XCTAssertEqual(tp.stripMunkiTimestamp(line), "Installing Foo")
}

func testPerformanceExample() {
Expand Down