osquery-1/osquery/dispatcher/distributed.cpp

62 lines
1.7 KiB
C++
Raw Normal View History

2015-09-07 18:09:06 +00:00
/*
* Copyright (c) 2014-present, Facebook, Inc.
2015-09-07 18:09:06 +00:00
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
2016-09-12 23:53:42 +00:00
#include <osquery/database.h>
#include <osquery/distributed.h>
#include <osquery/flags.h>
2016-09-12 23:53:42 +00:00
#include <osquery/system.h>
2016-09-12 23:53:42 +00:00
#include "osquery/core/conversions.h"
2015-09-07 18:09:06 +00:00
#include "osquery/dispatcher/distributed.h"
namespace osquery {
FLAG(uint64,
2015-10-02 18:33:50 +00:00
distributed_interval,
2015-09-07 18:09:06 +00:00
60,
2015-10-02 18:33:50 +00:00
"Seconds between polling for new queries (default 60)")
2015-09-07 18:09:06 +00:00
2015-10-02 18:33:50 +00:00
DECLARE_bool(disable_distributed);
2015-09-07 18:09:06 +00:00
DECLARE_string(distributed_plugin);
2016-09-12 23:53:42 +00:00
const size_t kDistributedAccelerationInterval = 5;
2015-09-07 18:09:06 +00:00
void DistributedRunner::start() {
auto dist = Distributed();
while (!interrupted()) {
2015-09-07 18:09:06 +00:00
dist.pullUpdates();
if (dist.getPendingQueryCount() > 0) {
dist.runQueries();
}
2016-09-12 23:53:42 +00:00
std::string str_acu = "0";
Status database = getDatabaseValue(
kPersistentSettings, "distributed_accelerate_checkins_expire", str_acu);
unsigned long accelerate_checkins_expire;
Status conversion = safeStrtoul(str_acu, 10, accelerate_checkins_expire);
if (!database.ok() || !conversion.ok() ||
getUnixTime() > accelerate_checkins_expire) {
pauseMilli(FLAGS_distributed_interval * 1000);
} else {
pauseMilli(kDistributedAccelerationInterval * 1000);
}
2015-09-07 18:09:06 +00:00
}
}
Status startDistributed() {
if (!FLAGS_disable_distributed) {
2015-09-07 18:09:06 +00:00
Dispatcher::addService(std::make_shared<DistributedRunner>());
return Status(0, "OK");
} else {
return Status(1, "Distributed query service not enabled.");
}
}
}