Commit e60ecc91 authored by Naoki Kambe's avatar Naoki Kambe
Browse files

[trac930] modify statistics.cc

 - Add implementation to validate statistics data
   -- When validation is success, it sends data to statistics
   module. But when it fails, it doesn't send and logs the message.

 - Add the function to register the validation function into the class
parent 62bd7736
......@@ -37,11 +37,14 @@ public:
void inc(const AuthCounters::CounterType type);
bool submitStatistics() const;
void setStatisticsSession(isc::cc::AbstractSession* statistics_session);
void registerStatisticsValidator
(AuthCounters::validator_type validator);
// Currently for testing purpose only
uint64_t getCounter(const AuthCounters::CounterType type) const;
private:
std::vector<uint64_t> counters_;
isc::cc::AbstractSession* statistics_session_;
AuthCounters::validator_type validator_;
};
AuthCountersImpl::AuthCountersImpl() :
......@@ -78,6 +81,14 @@ AuthCountersImpl::submitStatistics() const {
<< "]}";
isc::data::ConstElementPtr statistics_element =
isc::data::Element::fromJSON(statistics_string);
// validate the statistics data before send
if (validator_) {
if (!validator_(
statistics_element->get("command")->get(1)->get("data"))) {
LOG_ERROR(auth_logger, AUTH_INVALID_STATISTICS_DATA);
return (false);
}
}
try {
// group_{send,recv}msg() can throw an exception when encountering
// an error, and group_recvmsg() will throw an exception on timeout.
......@@ -106,6 +117,13 @@ AuthCountersImpl::setStatisticsSession
statistics_session_ = statistics_session;
}
void
AuthCountersImpl::registerStatisticsValidator
(AuthCounters::validator_type validator)
{
validator_ = validator;
}
// Currently for testing purpose only
uint64_t
AuthCountersImpl::getCounter(const AuthCounters::CounterType type) const {
......@@ -140,3 +158,10 @@ uint64_t
AuthCounters::getCounter(const AuthCounters::CounterType type) const {
return (impl_->getCounter(type));
}
void
AuthCounters::registerStatisticsValidator
(AuthCounters::validator_type validator) const
{
return (impl_->registerStatisticsValidator(validator));
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment