Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

carver: Refactor carver to use the Scheduler #6671

Merged
merged 4 commits into from
Oct 14, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Update tests and use flag for carver_expiry
  • Loading branch information
Ted Reed committed Sep 27, 2020
commit 0c97799e2009c10690f833d1508d186d5385248c
14 changes: 11 additions & 3 deletions osquery/carver/carver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,18 @@ CLI_FLAG(uint32,
8192,
"Size of blocks used for POSTing data back to remote endpoints");

/// Boolean if compression should be used.
CLI_FLAG(bool,
carver_compression,
false,
"Compress archives using zstd prior to upload (default false)");

/// Time to expire successful carves from the local cache.
CLI_FLAG(uint32,
carver_expiry,
86400,
"Seconds to store successful carve result metadata (in carves table)");

DECLARE_bool(disable_carver);
DECLARE_uint64(read_max);

Expand Down Expand Up @@ -97,13 +104,14 @@ void CarverRunnable::start() {
if (status == kCarverStatusSuccess) {
uint64_t start_time(doc["time"].GetUint());
auto delta = getUnixTime() - start_time;
if (delta > 86400) {
// Expire results after 1 day.
if (delta > FLAGS_carver_expiry) {
VLOG(1) << "Expiring successful carve metadata for GUID: " << guid;
deleteDatabaseValue(kCarves, key);
continue;
}
} else if (status != kCarverStatusScheduled) {
}

if (status != kCarverStatusScheduled) {
continue;
}

Expand Down
10 changes: 10 additions & 0 deletions osquery/carver/tests/carver_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,16 @@ TEST_F(CarverTests, test_schedule_carves) {

EXPECT_EQ(runner.carves(), 1);
}

{
FakeCarverRunner runner;
ASSERT_TRUE(FakeCarverRunner::running());
runner.start();

// All carves were previously completed.
EXPECT_EQ(runner.carves(), 0);
}

ASSERT_FALSE(FakeCarverRunner::running());
}

Expand Down