diff --git a/.env.dist b/.env.dist new file mode 100644 index 0000000..268dbbf --- /dev/null +++ b/.env.dist @@ -0,0 +1,11 @@ + +MIKROTIK_IP=10.0.0.1 + +NETWORK_RANGE=10.10.0.0-10.10.255.255 + +INFLUXDB_HOST=10.10.10.40 +INFLUXDB_PORT=8086 +INFLUXDB_USER=user +INFLUXDB_PASS=pass + +INFLXUDB_DATABASE=influxdbname \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..699724c --- /dev/null +++ b/.gitignore @@ -0,0 +1,32 @@ +# Cache and logs (Symfony2) +/app/cache/* +/app/logs/* +!app/cache/.gitkeep +!app/logs/.gitkeep + +# Cache and logs (Symfony3) +/var/cache/* +/var/logs/* +!var/cache/.gitkeep +!var/logs/.gitkeep + +# Managed by Composer +/app/bootstrap.php.cache +/var/bootstrap.php.cache +/bin/* +!bin/console +!bin/symfony_requirements +/vendor/ + +# PHPUnit +/app/phpunit.xml +/phpunit.xml + +# Build data +/build/ + +# Intellij +*idea/ + +# Config File +.env \ No newline at end of file diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..c637c51 --- /dev/null +++ b/composer.json @@ -0,0 +1,26 @@ +{ + "name": "ncareau/mikro-watch", + "description": "Get and push data from Mikrotik Accounting to influxdb.", + "homepage": "https://github.com/ncareau/mikro-watch", + "license": "MIT", + "authors": [ + { + "name": "NMC", + "email": "info@nmc-lab.com" + } + ], + "require": { + "symfony/console": "^3.4", + "symfony/var-dumper": "^3.4", + "symfony/dotenv": "^3.4", + "guzzlehttp/guzzle": "^6.3", + "s1lentium/iptools": "^1.1", + "influxdb/influxdb-php": "^1.14", + "wrep/daemonizable-command": "^2.0" + }, + "autoload": { + "psr-4": { + "App\\": "src/" + } + } +} diff --git a/composer.lock b/composer.lock new file mode 100644 index 0000000..fac5594 --- /dev/null +++ b/composer.lock @@ -0,0 +1,954 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "This file is @generated automatically" + ], + "content-hash": "b4acab28cadc839b45ef343c91c90622", + "packages": [ + { + "name": "guzzlehttp/guzzle", + "version": "6.3.0", + "source": { + "type": "git", + "url": "https://github.com/guzzle/guzzle.git", + "reference": "f4db5a78a5ea468d4831de7f0bf9d9415e348699" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/guzzle/zipball/f4db5a78a5ea468d4831de7f0bf9d9415e348699", + "reference": "f4db5a78a5ea468d4831de7f0bf9d9415e348699", + "shasum": "" + }, + "require": { + "guzzlehttp/promises": "^1.0", + "guzzlehttp/psr7": "^1.4", + "php": ">=5.5" + }, + "require-dev": { + "ext-curl": "*", + "phpunit/phpunit": "^4.0 || ^5.0", + "psr/log": "^1.0" + }, + "suggest": { + "psr/log": "Required for using the Log middleware" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "6.2-dev" + } + }, + "autoload": { + "files": [ + "src/functions_include.php" + ], + "psr-4": { + "GuzzleHttp\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + } + ], + "description": "Guzzle is a PHP HTTP client library", + "homepage": "http://guzzlephp.org/", + "keywords": [ + "client", + "curl", + "framework", + "http", + "http client", + "rest", + "web service" + ], + "time": "2017-06-22T18:50:49+00:00" + }, + { + "name": "guzzlehttp/promises", + "version": "v1.3.1", + "source": { + "type": "git", + "url": "https://github.com/guzzle/promises.git", + "reference": "a59da6cf61d80060647ff4d3eb2c03a2bc694646" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/promises/zipball/a59da6cf61d80060647ff4d3eb2c03a2bc694646", + "reference": "a59da6cf61d80060647ff4d3eb2c03a2bc694646", + "shasum": "" + }, + "require": { + "php": ">=5.5.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.4-dev" + } + }, + "autoload": { + "psr-4": { + "GuzzleHttp\\Promise\\": "src/" + }, + "files": [ + "src/functions_include.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + } + ], + "description": "Guzzle promises library", + "keywords": [ + "promise" + ], + "time": "2016-12-20T10:07:11+00:00" + }, + { + "name": "guzzlehttp/psr7", + "version": "1.4.2", + "source": { + "type": "git", + "url": "https://github.com/guzzle/psr7.git", + "reference": "f5b8a8512e2b58b0071a7280e39f14f72e05d87c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/psr7/zipball/f5b8a8512e2b58b0071a7280e39f14f72e05d87c", + "reference": "f5b8a8512e2b58b0071a7280e39f14f72e05d87c", + "shasum": "" + }, + "require": { + "php": ">=5.4.0", + "psr/http-message": "~1.0" + }, + "provide": { + "psr/http-message-implementation": "1.0" + }, + "require-dev": { + "phpunit/phpunit": "~4.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.4-dev" + } + }, + "autoload": { + "psr-4": { + "GuzzleHttp\\Psr7\\": "src/" + }, + "files": [ + "src/functions_include.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + }, + { + "name": "Tobias Schultze", + "homepage": "https://github.com/Tobion" + } + ], + "description": "PSR-7 message implementation that also provides common utility methods", + "keywords": [ + "http", + "message", + "request", + "response", + "stream", + "uri", + "url" + ], + "time": "2017-03-20T17:10:46+00:00" + }, + { + "name": "influxdb/influxdb-php", + "version": "1.14.5", + "source": { + "type": "git", + "url": "https://github.com/influxdata/influxdb-php.git", + "reference": "64c79de3f3e0e7f8c20b5fc51f50da8736767de9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/influxdata/influxdb-php/zipball/64c79de3f3e0e7f8c20b5fc51f50da8736767de9", + "reference": "64c79de3f3e0e7f8c20b5fc51f50da8736767de9", + "shasum": "" + }, + "require": { + "guzzlehttp/guzzle": "^6.0", + "php": "^5.5 || ^7.0", + "symfony/event-dispatcher": "^2.0 || ^3.0 || ^4.0" + }, + "require-dev": { + "codeclimate/php-test-reporter": "0.*", + "symfony/config": "~2.8|~3.0|~4.0", + "symfony/console": "~2.8|~3.0|~4.0", + "symfony/filesystem": "~2.8|~3.0|~4.0", + "symfony/phpunit-bridge": "^3.4 || ^4.0", + "symfony/stopwatch": "~2.8|~3.0|~4.0", + "symfony/yaml": "~2.8|~3.0|~4.0" + }, + "suggest": { + "stefanotorresi/influxdb-php-async": "An asyncronous client for InfluxDB, implemented via ReactPHP." + }, + "type": "library", + "autoload": { + "psr-4": { + "InfluxDB\\": "src/InfluxDB" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Gianluca Arbezzano", + "email": "gianarb92@gmail.com" + }, + { + "name": "Daniel Martinez", + "email": "danimartcas@hotmail.com" + }, + { + "name": "Stephen Hoogendijk", + "email": "stephen@tca0.nl" + } + ], + "description": "InfluxDB client library for PHP", + "keywords": [ + "client", + "influxdata", + "influxdb", + "influxdb class", + "influxdb client", + "influxdb library", + "time series" + ], + "time": "2018-01-03T13:09:43+00:00" + }, + { + "name": "psr/container", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/php-fig/container.git", + "reference": "b7ce3b176482dbbc1245ebf52b181af44c2cf55f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/container/zipball/b7ce3b176482dbbc1245ebf52b181af44c2cf55f", + "reference": "b7ce3b176482dbbc1245ebf52b181af44c2cf55f", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Container\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common Container Interface (PHP FIG PSR-11)", + "homepage": "https://github.com/php-fig/container", + "keywords": [ + "PSR-11", + "container", + "container-interface", + "container-interop", + "psr" + ], + "time": "2017-02-14T16:28:37+00:00" + }, + { + "name": "psr/http-message", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-message.git", + "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-message/zipball/f6561bf28d520154e4b0ec72be95418abe6d9363", + "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Message\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interface for HTTP messages", + "homepage": "https://github.com/php-fig/http-message", + "keywords": [ + "http", + "http-message", + "psr", + "psr-7", + "request", + "response" + ], + "time": "2016-08-06T14:39:51+00:00" + }, + { + "name": "psr/log", + "version": "1.0.2", + "source": { + "type": "git", + "url": "https://github.com/php-fig/log.git", + "reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/log/zipball/4ebe3a8bf773a19edfe0a84b6585ba3d401b724d", + "reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Log\\": "Psr/Log/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interface for logging libraries", + "homepage": "https://github.com/php-fig/log", + "keywords": [ + "log", + "psr", + "psr-3" + ], + "time": "2016-10-10T12:19:37+00:00" + }, + { + "name": "s1lentium/iptools", + "version": "v1.1.0", + "source": { + "type": "git", + "url": "https://github.com/S1lentium/IPTools.git", + "reference": "cb4843d4077872643b5d38d18b8591b4aaf605ea" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/S1lentium/IPTools/zipball/cb4843d4077872643b5d38d18b8591b4aaf605ea", + "reference": "cb4843d4077872643b5d38d18b8591b4aaf605ea", + "shasum": "" + }, + "require": { + "ext-bcmath": "*", + "php": ">=5.4.0" + }, + "require-dev": { + "satooshi/php-coveralls": "~1.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "IPTools\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Safarov Alisher", + "email": "alisher.safarov@outlook.com", + "homepage": "https://github.com/S1lentium" + } + ], + "description": "PHP Library for manipulating network addresses (IPv4 and IPv6)", + "keywords": [ + "IP", + "IP-Tools", + "cidr", + "ipv4", + "ipv6", + "network", + "subnet" + ], + "time": "2016-08-21T15:57:09+00:00" + }, + { + "name": "symfony/console", + "version": "v3.4.6", + "source": { + "type": "git", + "url": "https://github.com/symfony/console.git", + "reference": "067339e9b8ec30d5f19f5950208893ff026b94f7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/console/zipball/067339e9b8ec30d5f19f5950208893ff026b94f7", + "reference": "067339e9b8ec30d5f19f5950208893ff026b94f7", + "shasum": "" + }, + "require": { + "php": "^5.5.9|>=7.0.8", + "symfony/debug": "~2.8|~3.0|~4.0", + "symfony/polyfill-mbstring": "~1.0" + }, + "conflict": { + "symfony/dependency-injection": "<3.4", + "symfony/process": "<3.3" + }, + "require-dev": { + "psr/log": "~1.0", + "symfony/config": "~3.3|~4.0", + "symfony/dependency-injection": "~3.4|~4.0", + "symfony/event-dispatcher": "~2.8|~3.0|~4.0", + "symfony/lock": "~3.4|~4.0", + "symfony/process": "~3.3|~4.0" + }, + "suggest": { + "psr/log": "For using the console logger", + "symfony/event-dispatcher": "", + "symfony/lock": "", + "symfony/process": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.4-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Console\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Console Component", + "homepage": "https://symfony.com", + "time": "2018-02-26T15:46:28+00:00" + }, + { + "name": "symfony/debug", + "version": "v4.0.6", + "source": { + "type": "git", + "url": "https://github.com/symfony/debug.git", + "reference": "1721e4e7effb23480966690cdcdc7d2a4152d489" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/debug/zipball/1721e4e7effb23480966690cdcdc7d2a4152d489", + "reference": "1721e4e7effb23480966690cdcdc7d2a4152d489", + "shasum": "" + }, + "require": { + "php": "^7.1.3", + "psr/log": "~1.0" + }, + "conflict": { + "symfony/http-kernel": "<3.4" + }, + "require-dev": { + "symfony/http-kernel": "~3.4|~4.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.0-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Debug\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Debug Component", + "homepage": "https://symfony.com", + "time": "2018-02-28T21:50:02+00:00" + }, + { + "name": "symfony/dependency-injection", + "version": "v3.4.6", + "source": { + "type": "git", + "url": "https://github.com/symfony/dependency-injection.git", + "reference": "12e901abc1cb0d637a0e5abe9923471361d96b07" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/dependency-injection/zipball/12e901abc1cb0d637a0e5abe9923471361d96b07", + "reference": "12e901abc1cb0d637a0e5abe9923471361d96b07", + "shasum": "" + }, + "require": { + "php": "^5.5.9|>=7.0.8", + "psr/container": "^1.0" + }, + "conflict": { + "symfony/config": "<3.3.7", + "symfony/finder": "<3.3", + "symfony/proxy-manager-bridge": "<3.4", + "symfony/yaml": "<3.4" + }, + "provide": { + "psr/container-implementation": "1.0" + }, + "require-dev": { + "symfony/config": "~3.3|~4.0", + "symfony/expression-language": "~2.8|~3.0|~4.0", + "symfony/yaml": "~3.4|~4.0" + }, + "suggest": { + "symfony/config": "", + "symfony/expression-language": "For using expressions in service container configuration", + "symfony/finder": "For using double-star glob patterns or when GLOB_BRACE portability is required", + "symfony/proxy-manager-bridge": "Generate service proxies to lazy load them", + "symfony/yaml": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.4-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\DependencyInjection\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony DependencyInjection Component", + "homepage": "https://symfony.com", + "time": "2018-03-04T03:54:53+00:00" + }, + { + "name": "symfony/dotenv", + "version": "v3.4.6", + "source": { + "type": "git", + "url": "https://github.com/symfony/dotenv.git", + "reference": "66265f80c0f585cd6aec3fbdfc4ffdf7a0d75992" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/dotenv/zipball/66265f80c0f585cd6aec3fbdfc4ffdf7a0d75992", + "reference": "66265f80c0f585cd6aec3fbdfc4ffdf7a0d75992", + "shasum": "" + }, + "require": { + "php": "^5.5.9|>=7.0.8" + }, + "require-dev": { + "symfony/process": "~3.2|~4.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.4-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Dotenv\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Registers environment variables from a .env file", + "homepage": "https://symfony.com", + "keywords": [ + "dotenv", + "env", + "environment" + ], + "time": "2018-01-03T17:14:19+00:00" + }, + { + "name": "symfony/event-dispatcher", + "version": "v4.0.6", + "source": { + "type": "git", + "url": "https://github.com/symfony/event-dispatcher.git", + "reference": "85eaf6a8ec915487abac52e133efc4a268204428" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/85eaf6a8ec915487abac52e133efc4a268204428", + "reference": "85eaf6a8ec915487abac52e133efc4a268204428", + "shasum": "" + }, + "require": { + "php": "^7.1.3" + }, + "conflict": { + "symfony/dependency-injection": "<3.4" + }, + "require-dev": { + "psr/log": "~1.0", + "symfony/config": "~3.4|~4.0", + "symfony/dependency-injection": "~3.4|~4.0", + "symfony/expression-language": "~3.4|~4.0", + "symfony/stopwatch": "~3.4|~4.0" + }, + "suggest": { + "symfony/dependency-injection": "", + "symfony/http-kernel": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.0-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\EventDispatcher\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony EventDispatcher Component", + "homepage": "https://symfony.com", + "time": "2018-02-14T14:11:10+00:00" + }, + { + "name": "symfony/polyfill-mbstring", + "version": "v1.7.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-mbstring.git", + "reference": "78be803ce01e55d3491c1397cf1c64beb9c1b63b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/78be803ce01e55d3491c1397cf1c64beb9c1b63b", + "reference": "78be803ce01e55d3491c1397cf1c64beb9c1b63b", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "suggest": { + "ext-mbstring": "For best performance" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.7-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Mbstring\\": "" + }, + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill for the Mbstring extension", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "mbstring", + "polyfill", + "portable", + "shim" + ], + "time": "2018-01-30T19:27:44+00:00" + }, + { + "name": "symfony/var-dumper", + "version": "v3.4.6", + "source": { + "type": "git", + "url": "https://github.com/symfony/var-dumper.git", + "reference": "80964679d81da3d5618519e0e4be488c3d7ecd7d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/var-dumper/zipball/80964679d81da3d5618519e0e4be488c3d7ecd7d", + "reference": "80964679d81da3d5618519e0e4be488c3d7ecd7d", + "shasum": "" + }, + "require": { + "php": "^5.5.9|>=7.0.8", + "symfony/polyfill-mbstring": "~1.0" + }, + "conflict": { + "phpunit/phpunit": "<4.8.35|<5.4.3,>=5.0" + }, + "require-dev": { + "ext-iconv": "*", + "twig/twig": "~1.34|~2.4" + }, + "suggest": { + "ext-iconv": "To convert non-UTF-8 strings to UTF-8 (or symfony/polyfill-iconv in case ext-iconv cannot be used).", + "ext-intl": "To show region name in time zone dump", + "ext-symfony_debug": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.4-dev" + } + }, + "autoload": { + "files": [ + "Resources/functions/dump.php" + ], + "psr-4": { + "Symfony\\Component\\VarDumper\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony mechanism for exploring and dumping PHP variables", + "homepage": "https://symfony.com", + "keywords": [ + "debug", + "dump" + ], + "time": "2018-02-22T17:29:24+00:00" + }, + { + "name": "wrep/daemonizable-command", + "version": "2.0.1", + "source": { + "type": "git", + "url": "https://github.com/mac-cain13/daemonizable-command.git", + "reference": "7530020fdd5fd450c1d2ec629a2d9d508cac9a06" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/mac-cain13/daemonizable-command/zipball/7530020fdd5fd450c1d2ec629a2d9d508cac9a06", + "reference": "7530020fdd5fd450c1d2ec629a2d9d508cac9a06", + "shasum": "" + }, + "require": { + "php": ">=5.5.9", + "symfony/console": "3.*", + "symfony/dependency-injection": "3.*" + }, + "type": "library", + "autoload": { + "psr-0": { + "Wrep\\Daemonizable\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Mathijs Kadijk", + "email": "mathijs@wrep.nl" + } + ], + "description": "Daemonizable (endless running) commands for Symfony.", + "homepage": "https://github.com/mac-cain13/daemonizable-command", + "keywords": [ + "Symfony2", + "background process", + "backgrounding", + "daemon", + "long running process", + "symfony", + "symfony3" + ], + "time": "2016-12-06T11:55:56+00:00" + } + ], + "packages-dev": [], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": [], + "platform-dev": [] +} diff --git a/demo/grafana.json b/demo/grafana.json new file mode 100644 index 0000000..e78be0e --- /dev/null +++ b/demo/grafana.json @@ -0,0 +1,143 @@ +{ + "aliasColors": {}, + "bars": false, + "dashLength": 10, + "dashes": false, + "datasource": "YOURDATASOURCE", + "decimals": null, + "fill": 1, + "gridPos": { + "h": 7, + "w": 24, + "x": 0, + "y": 15 + }, + "id": 4, + "legend": { + "alignAsTable": true, + "avg": true, + "current": true, + "max": true, + "min": false, + "rightSide": true, + "show": true, + "total": false, + "values": true + }, + "lines": true, + "linewidth": 1, + "links": [], + "nullPointMode": "null", + "percentage": false, + "pointradius": 5, + "points": false, + "renderer": "flot", + "seriesOverrides": [], + "spaceLength": 10, + "stack": false, + "steppedLine": false, + "targets": [ + { + "alias": "$tag_ip:$col", + "groupBy": [ + { + "params": [ + "$__interval" + ], + "type": "time" + }, + { + "params": [ + "ip" + ], + "type": "tag" + } + ], + "measurement": "net_traffic", + "orderByTime": "ASC", + "policy": "default", + "refId": "A", + "resultFormat": "time_series", + "select": [ + [ + { + "type": "field", + "params": [ + "down_byte" + ] + }, + { + "type": "mean", + "params": [] + }, + { + "type": "alias", + "params": [ + "in" + ] + } + ], + [ + { + "type": "field", + "params": [ + "up_byte" + ] + }, + { + "type": "mean", + "params": [] + }, + { + "type": "math", + "params": [ + "*-1" + ] + }, + { + "type": "alias", + "params": [ + "out" + ] + } + ] + ], + "tags": [] + } + ], + "thresholds": [], + "timeFrom": null, + "timeShift": null, + "title": "Network By IP", + "tooltip": { + "shared": true, + "sort": 0, + "value_type": "individual" + }, + "type": "graph", + "xaxis": { + "buckets": null, + "mode": "time", + "name": null, + "show": true, + "values": [] + }, + "yaxes": [ + { + "format": "Bps", + "label": null, + "logBase": 1, + "max": null, + "min": null, + "show": true + }, + { + "format": "short", + "label": null, + "logBase": 1, + "max": null, + "min": null, + "show": true + } + ] +} \ No newline at end of file diff --git a/demo/panel.PNG b/demo/panel.PNG new file mode 100644 index 0000000..d21e6d7 Binary files /dev/null and b/demo/panel.PNG differ diff --git a/mikro-watch b/mikro-watch new file mode 100644 index 0000000..4d7adc6 --- /dev/null +++ b/mikro-watch @@ -0,0 +1,18 @@ +#!/usr/bin/env php +load(__DIR__.'/.env'); + +$application = new Application(); + +$application->add(new \App\Command\DaemonCommand()); +$application->add(new \App\Command\InfluxDBCommand()); + +$application->run(); \ No newline at end of file diff --git a/src/Command/DaemonCommand.php b/src/Command/DaemonCommand.php new file mode 100644 index 0000000..64a6322 --- /dev/null +++ b/src/Command/DaemonCommand.php @@ -0,0 +1,60 @@ +setName('daemon') + ->setDescription('Push data to InfluxDB endlessly') + ->setHelp('This command allows you to push data periodically to InfluxDB as an endless process') + ->setDefinition( + new InputDefinition([ + new InputOption('timeout', 't', InputOption::VALUE_OPTIONAL) + ]) + ) + ->setTimeout(10); + } + + protected function initialize(InputInterface $input, OutputInterface $output) + { + $this->http_client = new \GuzzleHttp\Client(); + + $influx_client = new Client(getenv('INFLUXDB_HOST')); + $this->influxdb_database = $influx_client->selectDB(getenv('INFLXUDB_DATABASE')); + + if ($input->getOption('timeout')) { + $this->setTimeout($input->getOption('timeout')); + } + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + + $accounting_service = new AccountingService($this->influxdb_database, $this->http_client); + + try { + $accounting_service->fetch(); + $accounting_service->parse(); + $accounting_service->push(); + } catch (\Exception $e) { + $output->writeln($e->getMessage()); + + } + } + +} \ No newline at end of file diff --git a/src/Command/InfluxDBCommand.php b/src/Command/InfluxDBCommand.php new file mode 100644 index 0000000..96db1c7 --- /dev/null +++ b/src/Command/InfluxDBCommand.php @@ -0,0 +1,41 @@ +setName('influxdb') + ->setDescription('Push data to InfluxDB') + ->setHelp('This command allows you to push data to InfluxDB') + ; + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $client = new \GuzzleHttp\Client(); + + $influx_client = new Client(getenv('INFLUXDB_HOST')); + $database = $influx_client->selectDB(getenv('INFLXUDB_DATABASE')); + + $accounting_service = new AccountingService($database, $client); + + try { + $accounting_service->fetch(); + $accounting_service->parse(); + $accounting_service->push(); + } catch (\Exception $e) { + } + + } + +} \ No newline at end of file diff --git a/src/Entity/IpAccount.php b/src/Entity/IpAccount.php new file mode 100644 index 0000000..bfe9e63 --- /dev/null +++ b/src/Entity/IpAccount.php @@ -0,0 +1,43 @@ +ip = $ip; + } + + /** + * @param int $bytes + * @param int $packets + */ + public function add_upload($bytes, $packets) + { + $this->up_packet = $this->up_packet + $packets; + $this->up_byte = $this->up_byte + $bytes; + } + + /** + * @param int $bytes + * @param int $packets + */ + public function add_download($bytes, $packets) + { + $this->down_packet = $this->down_packet + $packets; + $this->down_byte = $this->down_byte + $bytes; + } + + +} \ No newline at end of file diff --git a/src/Service/AccountingService.php b/src/Service/AccountingService.php new file mode 100644 index 0000000..34d3d67 --- /dev/null +++ b/src/Service/AccountingService.php @@ -0,0 +1,127 @@ +influxdb_database = $influxdb_database; + $this->http_client = $http_client; + } + + /** + * @throws \Exception + */ + public function fetch() + { + $res = $this->http_client->request('GET', 'http://' . getenv('MIKROTIK_IP') . '/accounting/ip.cgi'); + + $this->body_result = $res->getBody(); + + //Only continue if the status is OK 200 and there is data + if ($res->getStatusCode() != 200 || empty($res->getBody())) { + throw new \Exception($res->getReasonPhrase()); + } + } + + /** + * @throws \Exception + */ + public function parse() + { + $lines = explode("\n", $this->body_result); + + foreach ($lines as $line) { + + if (empty($line)) { + break; + } + + $line = explode(" ", $line); + + $source = new IP($line[0]); + $dest = new IP($line[1]); + $bytes = $line[2];//byte + $packets = $line[3];//packet + + if (Range::parse(getenv('NETWORK_RANGE'))->contains($source)) { + $ip = $source->__toString(); + + if (!isset($this->data[$ip])) { + $this->data[$ip] = new IpAccount($ip); + } + + $this->data[$ip]->add_upload($bytes, $packets); + } + + if (Range::parse(getenv('NETWORK_RANGE'))->contains($dest)) { + $ip = $dest->__toString(); + + if (!isset($this->data[$ip])) { + $this->data[$ip] = new IpAccount($ip); + } + + $this->data[$ip]->add_download($bytes, $packets); + } + + } + } + + /** + * @throws Database\Exception + * @throws \InfluxDB\Exception + */ + public function push() + { + $points = []; + + foreach ($this->data as $d) { + + $points[] = new Point( + 'net_traffic', + null, + ["ip" => $d->ip, "host" => getenv('MIKROTIK_IP')], + [ + "down_packet" => (int)$d->down_packet, + "down_byte" => (int)$d->down_byte, + "up_packet" => (int)$d->up_packet, + "up_byte" => (int)$d->up_byte + ] + ); + + } + + $this->influxdb_database->writePoints($points, Database::PRECISION_MILLISECONDS); + } + + public function show() + { + + } + +} \ No newline at end of file