diff --git a/lib/hooks.php b/lib/hooks.php index 1f8c1c4..e724bc1 100755 --- a/lib/hooks.php +++ b/lib/hooks.php @@ -13,11 +13,14 @@ class OC_esLog_Hooks { // For now just reading and writing data // --------------------- + // This function is called every time a file is read static public function read($path) { - OC_esLog::log($path,'File read'); + OC_esLog::sendToStatsd($path,'File read'); } + + // This function is called every time a file is written static public function write($path) { - OC_esLog::log($path,'File write'); + OC_esLog::sendToStatsd($path,'File write'); } } diff --git a/lib/log.php b/lib/log.php index 0d20358..d6c3c3e 100755 --- a/lib/log.php +++ b/lib/log.php @@ -1,133 +1,33 @@ increment('read'); + } elseif ($action == "File write"){ + $service->increment('write'); } - $client = new Elasticsearch\Client($params); - - // $date = date('Y-m-d H:i:s'); - $date = date('c'); - $request=$_REQUEST; - if(isset($request['password'])) $request['password']='******'; - - $server=$_SERVER; - if(isset($server['PHP_AUTH_PW'])) $server['PHP_AUTH_PW']='******'; - if(isset($server['HTTP_COOKIE'])) $server['HTTP_COOKIE']='******'; - if(isset($server['HTTP_AUTHORIZATION'])) $server['HTTP_AUTHORIZATION']='******'; - - if (isset($server['REMOTE_ADDR'])) { - $remote_address = $server['REMOTE_ADDR']; - } - if (isset($server['REMOTE_PORT'])) { - $remote_port = $server['REMOTE_PORT']; - } - - $vars=serialize(array( - 'request'=>$request, - 'server'=>$server - )); - $params = array(); - $params['index'] = OC_Appconfig::getValue('eslog', 'eslog_index', 'owncloud'); - $params['type'] = OC_Appconfig::getValue('eslog', 'eslog_type', 'owncloud'); - $params['body'] = array( - '@timestamp' => $date, - 'user' => $user, - 'src_ip' => $remote_address, - 'src_port' => $remote_port, - 'date' => $date, - 'proto' => $protocol, - 'content_type' => $type, - 'folder' => $folder, - 'file' => $file, - 'folder2' => $folder2, - 'file2' => $file2, - 'action' => $action, - 'variables' => $vars - ); - $ret = $client->index($params); + // Send the data over the socket to statsd + $service->flush(); } }