From 983230fe86cb2bdbe870d89ef32db64f1d156538 Mon Sep 17 00:00:00 2001 From: Danila Troschinsky Date: Tue, 25 Jul 2017 11:19:30 +0300 Subject: [PATCH] Import of plugin's code Change-Id: Ic773558145bd86d46f02151644f1dc435c7b23c2 --- README.md | 71 ++ .../puppet/files/embedded/bin/check-cpu.rb | 22 + .../embedded/bin/check-influxdb-query.rb | 22 + .../files/embedded/bin/check-influxdb.rb | 22 + .../puppet/files/embedded/bin/jsonpath | 22 + .../files/embedded/bin/metrics-cpu-mpstat.rb | 22 + .../embedded/bin/metrics-cpu-pcnt-usage.rb | 22 + .../puppet/files/embedded/bin/metrics-cpu.rb | 22 + .../files/embedded/bin/metrics-influxdb.rb | 22 + .../files/embedded/bin/metrics-numastat.rb | 22 + .../embedded/bin/metrics-user-pct-usage.rb | 22 + .../bin/mutator-influxdb-line-protocol.rb | 22 + .../gems/2.3.0/gems/cause-0.1/LICENCE.MIT | 19 + .../ruby/gems/2.3.0/gems/cause-0.1/README.md | 32 + .../gems/2.3.0/gems/cause-0.1/cause.gemspec | 17 + .../gems/2.3.0/gems/cause-0.1/lib/cause.rb | 12 + .../gems/2.3.0/gems/dentaku-2.0.9/.gitignore | 11 + .../ruby/gems/2.3.0/gems/dentaku-2.0.9/.pryrc | 2 + .../gems/2.3.0/gems/dentaku-2.0.9/.travis.yml | 13 + .../2.3.0/gems/dentaku-2.0.9/CHANGELOG.md | 141 ++++ .../gems/2.3.0/gems/dentaku-2.0.9/Gemfile | 9 + .../gems/2.3.0/gems/dentaku-2.0.9/README.md | 297 ++++++++ .../gems/2.3.0/gems/dentaku-2.0.9/Rakefile | 28 + .../2.3.0/gems/dentaku-2.0.9/dentaku.gemspec | 27 + .../2.3.0/gems/dentaku-2.0.9/lib/dentaku.rb | 43 ++ .../gems/dentaku-2.0.9/lib/dentaku/ast.rb | 21 + .../lib/dentaku/ast/arithmetic.rb | 129 ++++ .../dentaku-2.0.9/lib/dentaku/ast/case.rb | 52 ++ .../lib/dentaku/ast/case/case_conditional.rb | 23 + .../lib/dentaku/ast/case/case_else.rb | 21 + .../dentaku/ast/case/case_switch_variable.rb | 21 + .../lib/dentaku/ast/case/case_then.rb | 21 + .../lib/dentaku/ast/case/case_when.rb | 21 + .../lib/dentaku/ast/combinators.rb | 36 + .../lib/dentaku/ast/comparators.rb | 51 ++ .../dentaku-2.0.9/lib/dentaku/ast/function.rb | 73 ++ .../lib/dentaku/ast/functions/if.rb | 30 + .../lib/dentaku/ast/functions/max.rb | 5 + .../lib/dentaku/ast/functions/min.rb | 5 + .../lib/dentaku/ast/functions/not.rb | 5 + .../lib/dentaku/ast/functions/round.rb | 5 + .../lib/dentaku/ast/functions/rounddown.rb | 7 + .../lib/dentaku/ast/functions/roundup.rb | 7 + .../lib/dentaku/ast/functions/ruby_math.rb | 8 + .../dentaku/ast/functions/string_functions.rb | 111 +++ .../dentaku-2.0.9/lib/dentaku/ast/grouping.rb | 21 + .../lib/dentaku/ast/identifier.rb | 36 + .../dentaku-2.0.9/lib/dentaku/ast/literal.rb | 20 + .../dentaku-2.0.9/lib/dentaku/ast/logical.rb | 8 + .../dentaku-2.0.9/lib/dentaku/ast/negation.rb | 40 + .../gems/dentaku-2.0.9/lib/dentaku/ast/nil.rb | 9 + .../dentaku-2.0.9/lib/dentaku/ast/node.rb | 17 + .../dentaku-2.0.9/lib/dentaku/ast/numeric.rb | 8 + .../lib/dentaku/ast/operation.rb | 22 + .../dentaku-2.0.9/lib/dentaku/ast/string.rb | 8 + .../lib/dentaku/bulk_expression_solver.rb | 99 +++ .../dentaku-2.0.9/lib/dentaku/calculator.rb | 124 ++++ .../lib/dentaku/dependency_resolver.rb | 24 + .../dentaku-2.0.9/lib/dentaku/exceptions.rb | 25 + .../gems/dentaku-2.0.9/lib/dentaku/parser.rb | 222 ++++++ .../gems/dentaku-2.0.9/lib/dentaku/token.rb | 32 + .../lib/dentaku/token_matcher.rb | 137 ++++ .../lib/dentaku/token_matchers.rb | 29 + .../lib/dentaku/token_scanner.rb | 142 ++++ .../dentaku-2.0.9/lib/dentaku/tokenizer.rb | 54 ++ .../gems/dentaku-2.0.9/lib/dentaku/version.rb | 3 + .../dentaku-2.0.9/spec/ast/addition_spec.rb | 29 + .../gems/dentaku-2.0.9/spec/ast/and_spec.rb | 32 + .../gems/dentaku-2.0.9/spec/ast/case_spec.rb | 80 ++ .../dentaku-2.0.9/spec/ast/division_spec.rb | 29 + .../dentaku-2.0.9/spec/ast/function_spec.rb | 21 + .../gems/dentaku-2.0.9/spec/ast/node_spec.rb | 40 + .../dentaku-2.0.9/spec/ast/numeric_spec.rb | 16 + .../spec/ast/string_functions_spec.rb | 135 ++++ .../gems/dentaku-2.0.9/spec/benchmark.rb | 70 ++ .../spec/bulk_expression_solver_spec.rb | 77 ++ .../dentaku-2.0.9/spec/calculator_spec.rb | 450 ++++++++++++ .../gems/dentaku-2.0.9/spec/dentaku_spec.rb | 22 + .../dentaku-2.0.9/spec/exceptions_spec.rb | 9 + .../spec/external_function_spec.rb | 56 ++ .../gems/dentaku-2.0.9/spec/parser_spec.rb | 150 ++++ .../gems/dentaku-2.0.9/spec/spec_helper.rb | 41 ++ .../dentaku-2.0.9/spec/token_matcher_spec.rb | 135 ++++ .../dentaku-2.0.9/spec/token_scanner_spec.rb | 53 ++ .../gems/dentaku-2.0.9/spec/token_spec.rb | 10 + .../gems/dentaku-2.0.9/spec/tokenizer_spec.rb | 212 ++++++ .../2.3.0/gems/influxdb-0.3.13/.gitignore | 23 + .../2.3.0/gems/influxdb-0.3.13/.rubocop.yml | 35 + .../2.3.0/gems/influxdb-0.3.13/.travis.yml | 52 ++ .../2.3.0/gems/influxdb-0.3.13/CHANGELOG.md | 125 ++++ .../gems/2.3.0/gems/influxdb-0.3.13/Gemfile | 14 + .../2.3.0/gems/influxdb-0.3.13/LICENSE.txt | 22 + .../gems/2.3.0/gems/influxdb-0.3.13/README.md | 687 ++++++++++++++++++ .../gems/2.3.0/gems/influxdb-0.3.13/Rakefile | 51 ++ .../gems/influxdb-0.3.13/influxdb.gemspec | 30 + .../gems/influxdb-0.3.13/lib/influxdb.rb | 19 + .../influxdb-0.3.13/lib/influxdb/client.rb | 82 +++ .../lib/influxdb/client/http.rb | 134 ++++ .../influxdb-0.3.13/lib/influxdb/config.rb | 120 +++ .../influxdb-0.3.13/lib/influxdb/errors.rb | 52 ++ .../influxdb-0.3.13/lib/influxdb/logging.rb | 23 + .../influxdb-0.3.13/lib/influxdb/max_queue.rb | 18 + .../lib/influxdb/point_value.rb | 77 ++ .../lib/influxdb/query/builder.rb | 44 ++ .../lib/influxdb/query/cluster.rb | 17 + .../lib/influxdb/query/continuous_query.rb | 31 + .../lib/influxdb/query/core.rb | 149 ++++ .../lib/influxdb/query/database.rb | 22 + .../lib/influxdb/query/retention_policy.rb | 34 + .../lib/influxdb/query/user.rb | 51 ++ .../influxdb-0.3.13/lib/influxdb/version.rb | 3 + .../lib/influxdb/writer/async.rb | 127 ++++ .../lib/influxdb/writer/udp.rb | 21 + .../smoke/connect-and-get-version.rb | 18 + .../influxdb-0.3.13/smoke/noaa-sample-data.rb | 79 ++ .../gems/influxdb-0.3.13/smoke/provision.sh | 92 +++ .../spec/influxdb/cases/async_client_spec.rb | 58 ++ .../spec/influxdb/cases/query_cluster_spec.rb | 81 +++ .../cases/query_continuous_query_spec.rb | 120 +++ .../spec/influxdb/cases/query_core_spec.rb | 36 + .../influxdb/cases/query_database_spec.rb | 73 ++ .../cases/query_retention_policy_spec.rb | 81 +++ .../spec/influxdb/cases/query_series_spec.rb | 50 ++ .../influxdb/cases/query_shard_space_spec.rb | 105 +++ .../spec/influxdb/cases/query_shard_spec.rb | 43 ++ .../spec/influxdb/cases/query_user_spec.rb | 124 ++++ .../influxdb/cases/query_with_params_spec.rb | 69 ++ .../cases/querying_issue_7000_spec.rb | 89 +++ .../spec/influxdb/cases/querying_spec.rb | 265 +++++++ .../influxdb/cases/retry_requests_spec.rb | 104 +++ .../spec/influxdb/cases/udp_client_spec.rb | 21 + .../spec/influxdb/cases/write_points_spec.rb | 184 +++++ .../spec/influxdb/client_spec.rb | 120 +++ .../spec/influxdb/config_spec.rb | 127 ++++ .../spec/influxdb/logging_spec.rb | 51 ++ .../spec/influxdb/max_queue_spec.rb | 29 + .../spec/influxdb/point_value_spec.rb | 89 +++ .../spec/influxdb/query_builder_spec.rb | 63 ++ .../spec/influxdb/worker_spec.rb | 27 + .../gems/influxdb-0.3.13/spec/spec_helper.rb | 39 + .../gems/2.3.0/gems/jsonpath-0.5.8/.gemtest | 0 .../gems/2.3.0/gems/jsonpath-0.5.8/.gitignore | 5 + .../gems/2.3.0/gems/jsonpath-0.5.8/.rspec | 3 + .../2.3.0/gems/jsonpath-0.5.8/.travis.yml | 5 + .../gems/2.3.0/gems/jsonpath-0.5.8/Gemfile | 2 + .../gems/2.3.0/gems/jsonpath-0.5.8/README.md | 132 ++++ .../gems/2.3.0/gems/jsonpath-0.5.8/Rakefile | 12 + .../2.3.0/gems/jsonpath-0.5.8/bin/jsonpath | 22 + .../gems/jsonpath-0.5.8/jsonpath.gemspec | 32 + .../2.3.0/gems/jsonpath-0.5.8/lib/jsonpath.rb | 93 +++ .../jsonpath-0.5.8/lib/jsonpath/enumerable.rb | 135 ++++ .../gems/jsonpath-0.5.8/lib/jsonpath/proxy.rb | 54 ++ .../jsonpath-0.5.8/lib/jsonpath/version.rb | 3 + .../gems/jsonpath-0.5.8/test/test_jsonpath.rb | 231 ++++++ .../jsonpath-0.5.8/test/test_jsonpath_bin.rb | 21 + .../linux-kstat-0.1.3-universal-linux/CHANGES | 11 + .../MANIFEST | 7 + .../linux-kstat-0.1.3-universal-linux/README | 43 ++ .../Rakefile | 36 + .../lib/linux/kstat.rb | 78 ++ .../linux-kstat.gemspec | 24 + .../test/test_linux_kstat.rb | 36 + .../2.3.0/gems/multi_json-1.12.1/CHANGELOG.md | 245 +++++++ .../gems/multi_json-1.12.1/CONTRIBUTING.md | 46 ++ .../2.3.0/gems/multi_json-1.12.1/LICENSE.md | 20 + .../2.3.0/gems/multi_json-1.12.1/README.md | 121 +++ .../gems/multi_json-1.12.1/lib/multi_json.rb | 161 ++++ .../lib/multi_json/adapter.rb | 49 ++ .../lib/multi_json/adapter_error.rb | 15 + .../lib/multi_json/adapters/gson.rb | 20 + .../lib/multi_json/adapters/jr_jackson.rb | 25 + .../lib/multi_json/adapters/json_common.rb | 23 + .../lib/multi_json/adapters/json_gem.rb | 11 + .../lib/multi_json/adapters/json_pure.rb | 11 + .../adapters/nsjsonserialization.rb | 32 + .../lib/multi_json/adapters/oj.rb | 25 + .../lib/multi_json/adapters/ok_json.rb | 23 + .../lib/multi_json/adapters/yajl.rb | 19 + .../lib/multi_json/convertible_hash_keys.rb | 43 ++ .../lib/multi_json/options.rb | 39 + .../lib/multi_json/options_cache.rb | 29 + .../lib/multi_json/parse_error.rb | 17 + .../lib/multi_json/vendor/okjson.rb | 606 +++++++++++++++ .../lib/multi_json/version.rb | 17 + .../gems/multi_json-1.12.1/multi_json.gemspec | 20 + .../CHANGELOG.md | 47 ++ .../sensu-plugins-cpu-checks-1.0.0/LICENSE | 22 + .../sensu-plugins-cpu-checks-1.0.0/README.md | 25 + .../bin/check-cpu.rb | 120 +++ .../bin/check-cpu.sh | 84 +++ .../bin/metrics-cpu-mpstat.rb | 87 +++ .../bin/metrics-cpu-pcnt-usage.rb | 85 +++ .../bin/metrics-cpu.rb | 71 ++ .../bin/metrics-numastat.rb | 58 ++ .../bin/metrics-user-pct-usage.rb | 79 ++ .../lib/sensu-plugins-cpu-checks.rb | 1 + .../lib/sensu-plugins-cpu-checks/version.rb | 9 + .../sensu-plugins-influxdb-1.1.0/CHANGELOG.md | 77 ++ .../gems/sensu-plugins-influxdb-1.1.0/LICENSE | 22 + .../sensu-plugins-influxdb-1.1.0/README.md | 108 +++ .../bin/check-influxdb-query.rb | 197 +++++ .../bin/check-influxdb.rb | 97 +++ .../bin/metrics-influxdb.rb | 90 +++ .../bin/mutator-influxdb-line-protocol.rb | 62 ++ .../lib/sensu-plugins-influxdb.rb | 1 + .../lib/sensu-plugins-influxdb/version.rb | 9 + .../puppet/manifests/haproxy.pp | 47 ++ .../puppet/manifests/hiera_override.pp | 108 +++ .../puppet/manifests/influxdb_config.pp | 8 + .../puppet/manifests/packages.pp | 15 + .../puppet/manifests/rabbitmq_firewall.pp | 78 ++ .../puppet/manifests/rabbitmq_sensu.pp | 25 + .../puppet/manifests/redis_haproxy.pp | 59 ++ .../puppet/manifests/redis_sentinel_config.pp | 8 + .../puppet/manifests/sensu_config.pp | 8 + .../modules/influxdb_config/manifests/init.pp | 20 + .../redis_sentinel_config/manifests/init.pp | 19 + .../templates/redis-sentinel.erb | 77 ++ .../templates/sentinel.conf.erb | 6 + .../files/embedded/bin/check-cpu.rb | 22 + .../embedded/bin/check-influxdb-query.rb | 22 + .../files/embedded/bin/check-influxdb.rb | 22 + .../sensu_config/files/embedded/bin/jsonpath | 22 + .../files/embedded/bin/metrics-cpu-mpstat.rb | 22 + .../embedded/bin/metrics-cpu-pcnt-usage.rb | 22 + .../files/embedded/bin/metrics-cpu.rb | 22 + .../files/embedded/bin/metrics-influxdb.rb | 22 + .../files/embedded/bin/metrics-numastat.rb | 22 + .../embedded/bin/metrics-user-pct-usage.rb | 22 + .../bin/mutator-influxdb-line-protocol.rb | 22 + .../gems/2.3.0/gems/cause-0.1/LICENCE.MIT | 19 + .../ruby/gems/2.3.0/gems/cause-0.1/README.md | 32 + .../gems/2.3.0/gems/cause-0.1/cause.gemspec | 17 + .../gems/2.3.0/gems/cause-0.1/lib/cause.rb | 12 + .../gems/2.3.0/gems/dentaku-2.0.9/.gitignore | 11 + .../ruby/gems/2.3.0/gems/dentaku-2.0.9/.pryrc | 2 + .../gems/2.3.0/gems/dentaku-2.0.9/.travis.yml | 13 + .../2.3.0/gems/dentaku-2.0.9/CHANGELOG.md | 141 ++++ .../gems/2.3.0/gems/dentaku-2.0.9/Gemfile | 9 + .../gems/2.3.0/gems/dentaku-2.0.9/README.md | 297 ++++++++ .../gems/2.3.0/gems/dentaku-2.0.9/Rakefile | 28 + .../2.3.0/gems/dentaku-2.0.9/dentaku.gemspec | 27 + .../2.3.0/gems/dentaku-2.0.9/lib/dentaku.rb | 43 ++ .../gems/dentaku-2.0.9/lib/dentaku/ast.rb | 21 + .../lib/dentaku/ast/arithmetic.rb | 129 ++++ .../dentaku-2.0.9/lib/dentaku/ast/case.rb | 52 ++ .../lib/dentaku/ast/case/case_conditional.rb | 23 + .../lib/dentaku/ast/case/case_else.rb | 21 + .../dentaku/ast/case/case_switch_variable.rb | 21 + .../lib/dentaku/ast/case/case_then.rb | 21 + .../lib/dentaku/ast/case/case_when.rb | 21 + .../lib/dentaku/ast/combinators.rb | 36 + .../lib/dentaku/ast/comparators.rb | 51 ++ .../dentaku-2.0.9/lib/dentaku/ast/function.rb | 73 ++ .../lib/dentaku/ast/functions/if.rb | 30 + .../lib/dentaku/ast/functions/max.rb | 5 + .../lib/dentaku/ast/functions/min.rb | 5 + .../lib/dentaku/ast/functions/not.rb | 5 + .../lib/dentaku/ast/functions/round.rb | 5 + .../lib/dentaku/ast/functions/rounddown.rb | 7 + .../lib/dentaku/ast/functions/roundup.rb | 7 + .../lib/dentaku/ast/functions/ruby_math.rb | 8 + .../dentaku/ast/functions/string_functions.rb | 111 +++ .../dentaku-2.0.9/lib/dentaku/ast/grouping.rb | 21 + .../lib/dentaku/ast/identifier.rb | 36 + .../dentaku-2.0.9/lib/dentaku/ast/literal.rb | 20 + .../dentaku-2.0.9/lib/dentaku/ast/logical.rb | 8 + .../dentaku-2.0.9/lib/dentaku/ast/negation.rb | 40 + .../gems/dentaku-2.0.9/lib/dentaku/ast/nil.rb | 9 + .../dentaku-2.0.9/lib/dentaku/ast/node.rb | 17 + .../dentaku-2.0.9/lib/dentaku/ast/numeric.rb | 8 + .../lib/dentaku/ast/operation.rb | 22 + .../dentaku-2.0.9/lib/dentaku/ast/string.rb | 8 + .../lib/dentaku/bulk_expression_solver.rb | 99 +++ .../dentaku-2.0.9/lib/dentaku/calculator.rb | 124 ++++ .../lib/dentaku/dependency_resolver.rb | 24 + .../dentaku-2.0.9/lib/dentaku/exceptions.rb | 25 + .../gems/dentaku-2.0.9/lib/dentaku/parser.rb | 222 ++++++ .../gems/dentaku-2.0.9/lib/dentaku/token.rb | 32 + .../lib/dentaku/token_matcher.rb | 137 ++++ .../lib/dentaku/token_matchers.rb | 29 + .../lib/dentaku/token_scanner.rb | 142 ++++ .../dentaku-2.0.9/lib/dentaku/tokenizer.rb | 54 ++ .../gems/dentaku-2.0.9/lib/dentaku/version.rb | 3 + .../dentaku-2.0.9/spec/ast/addition_spec.rb | 29 + .../gems/dentaku-2.0.9/spec/ast/and_spec.rb | 32 + .../gems/dentaku-2.0.9/spec/ast/case_spec.rb | 80 ++ .../dentaku-2.0.9/spec/ast/division_spec.rb | 29 + .../dentaku-2.0.9/spec/ast/function_spec.rb | 21 + .../gems/dentaku-2.0.9/spec/ast/node_spec.rb | 40 + .../dentaku-2.0.9/spec/ast/numeric_spec.rb | 16 + .../spec/ast/string_functions_spec.rb | 135 ++++ .../gems/dentaku-2.0.9/spec/benchmark.rb | 70 ++ .../spec/bulk_expression_solver_spec.rb | 77 ++ .../dentaku-2.0.9/spec/calculator_spec.rb | 450 ++++++++++++ .../gems/dentaku-2.0.9/spec/dentaku_spec.rb | 22 + .../dentaku-2.0.9/spec/exceptions_spec.rb | 9 + .../spec/external_function_spec.rb | 56 ++ .../gems/dentaku-2.0.9/spec/parser_spec.rb | 150 ++++ .../gems/dentaku-2.0.9/spec/spec_helper.rb | 41 ++ .../dentaku-2.0.9/spec/token_matcher_spec.rb | 135 ++++ .../dentaku-2.0.9/spec/token_scanner_spec.rb | 53 ++ .../gems/dentaku-2.0.9/spec/token_spec.rb | 10 + .../gems/dentaku-2.0.9/spec/tokenizer_spec.rb | 212 ++++++ .../2.3.0/gems/influxdb-0.3.13/.gitignore | 23 + .../2.3.0/gems/influxdb-0.3.13/.rubocop.yml | 35 + .../2.3.0/gems/influxdb-0.3.13/.travis.yml | 52 ++ .../2.3.0/gems/influxdb-0.3.13/CHANGELOG.md | 125 ++++ .../gems/2.3.0/gems/influxdb-0.3.13/Gemfile | 14 + .../2.3.0/gems/influxdb-0.3.13/LICENSE.txt | 22 + .../gems/2.3.0/gems/influxdb-0.3.13/README.md | 687 ++++++++++++++++++ .../gems/2.3.0/gems/influxdb-0.3.13/Rakefile | 51 ++ .../gems/influxdb-0.3.13/influxdb.gemspec | 30 + .../gems/influxdb-0.3.13/lib/influxdb.rb | 19 + .../influxdb-0.3.13/lib/influxdb/client.rb | 82 +++ .../lib/influxdb/client/http.rb | 134 ++++ .../influxdb-0.3.13/lib/influxdb/config.rb | 120 +++ .../influxdb-0.3.13/lib/influxdb/errors.rb | 52 ++ .../influxdb-0.3.13/lib/influxdb/logging.rb | 23 + .../influxdb-0.3.13/lib/influxdb/max_queue.rb | 18 + .../lib/influxdb/point_value.rb | 77 ++ .../lib/influxdb/query/builder.rb | 44 ++ .../lib/influxdb/query/cluster.rb | 17 + .../lib/influxdb/query/continuous_query.rb | 31 + .../lib/influxdb/query/core.rb | 149 ++++ .../lib/influxdb/query/database.rb | 22 + .../lib/influxdb/query/retention_policy.rb | 34 + .../lib/influxdb/query/user.rb | 51 ++ .../influxdb-0.3.13/lib/influxdb/version.rb | 3 + .../lib/influxdb/writer/async.rb | 127 ++++ .../lib/influxdb/writer/udp.rb | 21 + .../smoke/connect-and-get-version.rb | 18 + .../influxdb-0.3.13/smoke/noaa-sample-data.rb | 79 ++ .../gems/influxdb-0.3.13/smoke/provision.sh | 92 +++ .../spec/influxdb/cases/async_client_spec.rb | 58 ++ .../spec/influxdb/cases/query_cluster_spec.rb | 81 +++ .../cases/query_continuous_query_spec.rb | 120 +++ .../spec/influxdb/cases/query_core_spec.rb | 36 + .../influxdb/cases/query_database_spec.rb | 73 ++ .../cases/query_retention_policy_spec.rb | 81 +++ .../spec/influxdb/cases/query_series_spec.rb | 50 ++ .../influxdb/cases/query_shard_space_spec.rb | 105 +++ .../spec/influxdb/cases/query_shard_spec.rb | 43 ++ .../spec/influxdb/cases/query_user_spec.rb | 124 ++++ .../influxdb/cases/query_with_params_spec.rb | 69 ++ .../cases/querying_issue_7000_spec.rb | 89 +++ .../spec/influxdb/cases/querying_spec.rb | 265 +++++++ .../influxdb/cases/retry_requests_spec.rb | 104 +++ .../spec/influxdb/cases/udp_client_spec.rb | 21 + .../spec/influxdb/cases/write_points_spec.rb | 184 +++++ .../spec/influxdb/client_spec.rb | 120 +++ .../spec/influxdb/config_spec.rb | 127 ++++ .../spec/influxdb/logging_spec.rb | 51 ++ .../spec/influxdb/max_queue_spec.rb | 29 + .../spec/influxdb/point_value_spec.rb | 89 +++ .../spec/influxdb/query_builder_spec.rb | 63 ++ .../spec/influxdb/worker_spec.rb | 27 + .../gems/influxdb-0.3.13/spec/spec_helper.rb | 39 + .../gems/2.3.0/gems/jsonpath-0.5.8/.gemtest | 0 .../gems/2.3.0/gems/jsonpath-0.5.8/.gitignore | 5 + .../gems/2.3.0/gems/jsonpath-0.5.8/.rspec | 3 + .../2.3.0/gems/jsonpath-0.5.8/.travis.yml | 5 + .../gems/2.3.0/gems/jsonpath-0.5.8/Gemfile | 2 + .../gems/2.3.0/gems/jsonpath-0.5.8/README.md | 132 ++++ .../gems/2.3.0/gems/jsonpath-0.5.8/Rakefile | 12 + .../2.3.0/gems/jsonpath-0.5.8/bin/jsonpath | 22 + .../gems/jsonpath-0.5.8/jsonpath.gemspec | 32 + .../2.3.0/gems/jsonpath-0.5.8/lib/jsonpath.rb | 93 +++ .../jsonpath-0.5.8/lib/jsonpath/enumerable.rb | 135 ++++ .../gems/jsonpath-0.5.8/lib/jsonpath/proxy.rb | 54 ++ .../jsonpath-0.5.8/lib/jsonpath/version.rb | 3 + .../gems/jsonpath-0.5.8/test/test_jsonpath.rb | 231 ++++++ .../jsonpath-0.5.8/test/test_jsonpath_bin.rb | 21 + .../linux-kstat-0.1.3-universal-linux/CHANGES | 11 + .../MANIFEST | 7 + .../linux-kstat-0.1.3-universal-linux/README | 43 ++ .../Rakefile | 36 + .../lib/linux/kstat.rb | 78 ++ .../linux-kstat.gemspec | 24 + .../test/test_linux_kstat.rb | 36 + .../2.3.0/gems/multi_json-1.12.1/CHANGELOG.md | 245 +++++++ .../gems/multi_json-1.12.1/CONTRIBUTING.md | 46 ++ .../2.3.0/gems/multi_json-1.12.1/LICENSE.md | 20 + .../2.3.0/gems/multi_json-1.12.1/README.md | 121 +++ .../gems/multi_json-1.12.1/lib/multi_json.rb | 161 ++++ .../lib/multi_json/adapter.rb | 49 ++ .../lib/multi_json/adapter_error.rb | 15 + .../lib/multi_json/adapters/gson.rb | 20 + .../lib/multi_json/adapters/jr_jackson.rb | 25 + .../lib/multi_json/adapters/json_common.rb | 23 + .../lib/multi_json/adapters/json_gem.rb | 11 + .../lib/multi_json/adapters/json_pure.rb | 11 + .../adapters/nsjsonserialization.rb | 32 + .../lib/multi_json/adapters/oj.rb | 25 + .../lib/multi_json/adapters/ok_json.rb | 23 + .../lib/multi_json/adapters/yajl.rb | 19 + .../lib/multi_json/convertible_hash_keys.rb | 43 ++ .../lib/multi_json/options.rb | 39 + .../lib/multi_json/options_cache.rb | 29 + .../lib/multi_json/parse_error.rb | 17 + .../lib/multi_json/vendor/okjson.rb | 606 +++++++++++++++ .../lib/multi_json/version.rb | 17 + .../gems/multi_json-1.12.1/multi_json.gemspec | 20 + .../CHANGELOG.md | 47 ++ .../sensu-plugins-cpu-checks-1.0.0/LICENSE | 22 + .../sensu-plugins-cpu-checks-1.0.0/README.md | 25 + .../bin/check-cpu.rb | 120 +++ .../bin/check-cpu.sh | 84 +++ .../bin/metrics-cpu-mpstat.rb | 87 +++ .../bin/metrics-cpu-pcnt-usage.rb | 85 +++ .../bin/metrics-cpu.rb | 71 ++ .../bin/metrics-numastat.rb | 58 ++ .../bin/metrics-user-pct-usage.rb | 79 ++ .../lib/sensu-plugins-cpu-checks.rb | 1 + .../lib/sensu-plugins-cpu-checks/version.rb | 9 + .../sensu-plugins-influxdb-1.1.0/CHANGELOG.md | 77 ++ .../gems/sensu-plugins-influxdb-1.1.0/LICENSE | 22 + .../sensu-plugins-influxdb-1.1.0/README.md | 108 +++ .../bin/check-influxdb-query.rb | 197 +++++ .../bin/check-influxdb.rb | 97 +++ .../bin/metrics-influxdb.rb | 90 +++ .../bin/mutator-influxdb-line-protocol.rb | 62 ++ .../lib/sensu-plugins-influxdb.rb | 1 + .../lib/sensu-plugins-influxdb/version.rb | 9 + .../2.3.0/specifications/cause-0.1.gemspec | 21 + .../specifications/dentaku-2.0.9.gemspec | 39 + .../specifications/influxdb-0.3.13.gemspec | 50 ++ .../specifications/jsonpath-0.5.8.gemspec | 52 ++ .../specifications/multi_json-1.12.1.gemspec | 33 + .../sensu-plugins-influxdb-1.1.0.gemspec | 73 ++ .../modules/sensu_config/manifests/init.pp | 116 +++ .../sensu_config/templates/redis-sentinel.erb | 47 ++ .../sensu_config/templates/sentinel.conf.erb | 6 + deployment_tasks.yaml | 126 ++++ environment_config.yaml | 14 + metadata.yaml | 20 + network_roles.yaml | 12 + repositories/centos/.gitkeep | 0 repositories/ubuntu/.gitkeep | 0 439 files changed, 26248 insertions(+) create mode 100644 README.md create mode 100755 deployment_scripts/puppet/files/embedded/bin/check-cpu.rb create mode 100755 deployment_scripts/puppet/files/embedded/bin/check-influxdb-query.rb create mode 100755 deployment_scripts/puppet/files/embedded/bin/check-influxdb.rb create mode 100755 deployment_scripts/puppet/files/embedded/bin/jsonpath create mode 100755 deployment_scripts/puppet/files/embedded/bin/metrics-cpu-mpstat.rb create mode 100755 deployment_scripts/puppet/files/embedded/bin/metrics-cpu-pcnt-usage.rb create mode 100755 deployment_scripts/puppet/files/embedded/bin/metrics-cpu.rb create mode 100755 deployment_scripts/puppet/files/embedded/bin/metrics-influxdb.rb create mode 100755 deployment_scripts/puppet/files/embedded/bin/metrics-numastat.rb create mode 100755 deployment_scripts/puppet/files/embedded/bin/metrics-user-pct-usage.rb create mode 100755 deployment_scripts/puppet/files/embedded/bin/mutator-influxdb-line-protocol.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/cause-0.1/LICENCE.MIT create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/cause-0.1/README.md create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/cause-0.1/cause.gemspec create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/cause-0.1/lib/cause.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/.gitignore create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/.pryrc create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/.travis.yml create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/CHANGELOG.md create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/Gemfile create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/README.md create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/Rakefile create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/dentaku.gemspec create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/arithmetic.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/case.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/case/case_conditional.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/case/case_else.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/case/case_switch_variable.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/case/case_then.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/case/case_when.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/combinators.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/comparators.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/function.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/if.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/max.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/min.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/not.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/round.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/rounddown.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/roundup.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/ruby_math.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/string_functions.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/grouping.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/identifier.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/literal.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/logical.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/negation.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/nil.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/node.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/numeric.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/operation.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/string.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/bulk_expression_solver.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/calculator.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/dependency_resolver.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/exceptions.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/parser.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/token.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/token_matcher.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/token_matchers.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/token_scanner.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/tokenizer.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/version.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/ast/addition_spec.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/ast/and_spec.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/ast/case_spec.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/ast/division_spec.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/ast/function_spec.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/ast/node_spec.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/ast/numeric_spec.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/ast/string_functions_spec.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/benchmark.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/bulk_expression_solver_spec.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/calculator_spec.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/dentaku_spec.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/exceptions_spec.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/external_function_spec.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/parser_spec.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/spec_helper.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/token_matcher_spec.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/token_scanner_spec.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/token_spec.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/tokenizer_spec.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/.gitignore create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/.rubocop.yml create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/.travis.yml create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/CHANGELOG.md create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/Gemfile create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/LICENSE.txt create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/README.md create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/Rakefile create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/influxdb.gemspec create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/client.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/client/http.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/config.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/errors.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/logging.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/max_queue.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/point_value.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/query/builder.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/query/cluster.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/query/continuous_query.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/query/core.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/query/database.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/query/retention_policy.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/query/user.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/version.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/writer/async.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/writer/udp.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/smoke/connect-and-get-version.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/smoke/noaa-sample-data.rb create mode 100755 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/smoke/provision.sh create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/async_client_spec.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/query_cluster_spec.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/query_continuous_query_spec.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/query_core_spec.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/query_database_spec.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/query_retention_policy_spec.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/query_series_spec.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/query_shard_space_spec.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/query_shard_spec.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/query_user_spec.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/query_with_params_spec.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/querying_issue_7000_spec.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/querying_spec.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/retry_requests_spec.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/udp_client_spec.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/write_points_spec.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/client_spec.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/config_spec.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/logging_spec.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/max_queue_spec.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/point_value_spec.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/query_builder_spec.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/worker_spec.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/spec_helper.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/.gemtest create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/.gitignore create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/.rspec create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/.travis.yml create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/Gemfile create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/README.md create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/Rakefile create mode 100755 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/bin/jsonpath create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/jsonpath.gemspec create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/lib/jsonpath.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/lib/jsonpath/enumerable.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/lib/jsonpath/proxy.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/lib/jsonpath/version.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/test/test_jsonpath.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/test/test_jsonpath_bin.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/linux-kstat-0.1.3-universal-linux/CHANGES create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/linux-kstat-0.1.3-universal-linux/MANIFEST create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/linux-kstat-0.1.3-universal-linux/README create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/linux-kstat-0.1.3-universal-linux/Rakefile create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/linux-kstat-0.1.3-universal-linux/lib/linux/kstat.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/linux-kstat-0.1.3-universal-linux/linux-kstat.gemspec create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/linux-kstat-0.1.3-universal-linux/test/test_linux_kstat.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/CHANGELOG.md create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/CONTRIBUTING.md create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/LICENSE.md create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/README.md create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapter.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapter_error.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapters/gson.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapters/jr_jackson.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapters/json_common.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapters/json_gem.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapters/json_pure.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapters/nsjsonserialization.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapters/oj.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapters/ok_json.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapters/yajl.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/convertible_hash_keys.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/options.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/options_cache.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/parse_error.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/vendor/okjson.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/version.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/multi_json.gemspec create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/CHANGELOG.md create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/LICENSE create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/README.md create mode 100755 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/bin/check-cpu.rb create mode 100755 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/bin/check-cpu.sh create mode 100755 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/bin/metrics-cpu-mpstat.rb create mode 100755 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/bin/metrics-cpu-pcnt-usage.rb create mode 100755 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/bin/metrics-cpu.rb create mode 100755 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/bin/metrics-numastat.rb create mode 100755 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/bin/metrics-user-pct-usage.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/lib/sensu-plugins-cpu-checks.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/lib/sensu-plugins-cpu-checks/version.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-influxdb-1.1.0/CHANGELOG.md create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-influxdb-1.1.0/LICENSE create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-influxdb-1.1.0/README.md create mode 100755 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-influxdb-1.1.0/bin/check-influxdb-query.rb create mode 100755 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-influxdb-1.1.0/bin/check-influxdb.rb create mode 100755 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-influxdb-1.1.0/bin/metrics-influxdb.rb create mode 100755 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-influxdb-1.1.0/bin/mutator-influxdb-line-protocol.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-influxdb-1.1.0/lib/sensu-plugins-influxdb.rb create mode 100644 deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-influxdb-1.1.0/lib/sensu-plugins-influxdb/version.rb create mode 100644 deployment_scripts/puppet/manifests/haproxy.pp create mode 100644 deployment_scripts/puppet/manifests/hiera_override.pp create mode 100644 deployment_scripts/puppet/manifests/influxdb_config.pp create mode 100644 deployment_scripts/puppet/manifests/packages.pp create mode 100644 deployment_scripts/puppet/manifests/rabbitmq_firewall.pp create mode 100644 deployment_scripts/puppet/manifests/rabbitmq_sensu.pp create mode 100644 deployment_scripts/puppet/manifests/redis_haproxy.pp create mode 100644 deployment_scripts/puppet/manifests/redis_sentinel_config.pp create mode 100644 deployment_scripts/puppet/manifests/sensu_config.pp create mode 100644 deployment_scripts/puppet/modules/influxdb_config/manifests/init.pp create mode 100644 deployment_scripts/puppet/modules/redis_sentinel_config/manifests/init.pp create mode 100644 deployment_scripts/puppet/modules/redis_sentinel_config/templates/redis-sentinel.erb create mode 100644 deployment_scripts/puppet/modules/redis_sentinel_config/templates/sentinel.conf.erb create mode 100755 deployment_scripts/puppet/modules/sensu_config/files/embedded/bin/check-cpu.rb create mode 100755 deployment_scripts/puppet/modules/sensu_config/files/embedded/bin/check-influxdb-query.rb create mode 100755 deployment_scripts/puppet/modules/sensu_config/files/embedded/bin/check-influxdb.rb create mode 100755 deployment_scripts/puppet/modules/sensu_config/files/embedded/bin/jsonpath create mode 100755 deployment_scripts/puppet/modules/sensu_config/files/embedded/bin/metrics-cpu-mpstat.rb create mode 100755 deployment_scripts/puppet/modules/sensu_config/files/embedded/bin/metrics-cpu-pcnt-usage.rb create mode 100755 deployment_scripts/puppet/modules/sensu_config/files/embedded/bin/metrics-cpu.rb create mode 100755 deployment_scripts/puppet/modules/sensu_config/files/embedded/bin/metrics-influxdb.rb create mode 100755 deployment_scripts/puppet/modules/sensu_config/files/embedded/bin/metrics-numastat.rb create mode 100755 deployment_scripts/puppet/modules/sensu_config/files/embedded/bin/metrics-user-pct-usage.rb create mode 100755 deployment_scripts/puppet/modules/sensu_config/files/embedded/bin/mutator-influxdb-line-protocol.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/cause-0.1/LICENCE.MIT create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/cause-0.1/README.md create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/cause-0.1/cause.gemspec create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/cause-0.1/lib/cause.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/.gitignore create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/.pryrc create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/.travis.yml create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/CHANGELOG.md create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/Gemfile create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/README.md create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/Rakefile create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/dentaku.gemspec create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/arithmetic.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/case.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/case/case_conditional.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/case/case_else.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/case/case_switch_variable.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/case/case_then.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/case/case_when.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/combinators.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/comparators.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/function.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/if.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/max.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/min.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/not.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/round.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/rounddown.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/roundup.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/ruby_math.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/string_functions.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/grouping.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/identifier.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/literal.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/logical.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/negation.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/nil.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/node.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/numeric.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/operation.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/string.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/bulk_expression_solver.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/calculator.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/dependency_resolver.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/exceptions.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/parser.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/token.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/token_matcher.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/token_matchers.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/token_scanner.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/tokenizer.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/version.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/ast/addition_spec.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/ast/and_spec.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/ast/case_spec.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/ast/division_spec.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/ast/function_spec.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/ast/node_spec.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/ast/numeric_spec.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/ast/string_functions_spec.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/benchmark.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/bulk_expression_solver_spec.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/calculator_spec.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/dentaku_spec.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/exceptions_spec.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/external_function_spec.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/parser_spec.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/spec_helper.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/token_matcher_spec.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/token_scanner_spec.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/token_spec.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/tokenizer_spec.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/.gitignore create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/.rubocop.yml create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/.travis.yml create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/CHANGELOG.md create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/Gemfile create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/LICENSE.txt create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/README.md create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/Rakefile create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/influxdb.gemspec create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/client.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/client/http.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/config.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/errors.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/logging.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/max_queue.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/point_value.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/query/builder.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/query/cluster.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/query/continuous_query.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/query/core.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/query/database.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/query/retention_policy.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/query/user.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/version.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/writer/async.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/writer/udp.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/smoke/connect-and-get-version.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/smoke/noaa-sample-data.rb create mode 100755 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/smoke/provision.sh create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/async_client_spec.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/query_cluster_spec.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/query_continuous_query_spec.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/query_core_spec.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/query_database_spec.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/query_retention_policy_spec.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/query_series_spec.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/query_shard_space_spec.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/query_shard_spec.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/query_user_spec.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/query_with_params_spec.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/querying_issue_7000_spec.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/querying_spec.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/retry_requests_spec.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/udp_client_spec.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/write_points_spec.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/client_spec.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/config_spec.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/logging_spec.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/max_queue_spec.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/point_value_spec.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/query_builder_spec.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/worker_spec.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/spec_helper.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/.gemtest create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/.gitignore create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/.rspec create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/.travis.yml create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/Gemfile create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/README.md create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/Rakefile create mode 100755 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/bin/jsonpath create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/jsonpath.gemspec create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/lib/jsonpath.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/lib/jsonpath/enumerable.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/lib/jsonpath/proxy.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/lib/jsonpath/version.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/test/test_jsonpath.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/test/test_jsonpath_bin.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/linux-kstat-0.1.3-universal-linux/CHANGES create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/linux-kstat-0.1.3-universal-linux/MANIFEST create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/linux-kstat-0.1.3-universal-linux/README create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/linux-kstat-0.1.3-universal-linux/Rakefile create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/linux-kstat-0.1.3-universal-linux/lib/linux/kstat.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/linux-kstat-0.1.3-universal-linux/linux-kstat.gemspec create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/linux-kstat-0.1.3-universal-linux/test/test_linux_kstat.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/CHANGELOG.md create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/CONTRIBUTING.md create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/LICENSE.md create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/README.md create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapter.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapter_error.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapters/gson.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapters/jr_jackson.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapters/json_common.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapters/json_gem.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapters/json_pure.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapters/nsjsonserialization.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapters/oj.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapters/ok_json.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapters/yajl.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/convertible_hash_keys.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/options.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/options_cache.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/parse_error.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/vendor/okjson.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/version.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/multi_json.gemspec create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/CHANGELOG.md create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/LICENSE create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/README.md create mode 100755 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/bin/check-cpu.rb create mode 100755 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/bin/check-cpu.sh create mode 100755 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/bin/metrics-cpu-mpstat.rb create mode 100755 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/bin/metrics-cpu-pcnt-usage.rb create mode 100755 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/bin/metrics-cpu.rb create mode 100755 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/bin/metrics-numastat.rb create mode 100755 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/bin/metrics-user-pct-usage.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/lib/sensu-plugins-cpu-checks.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/lib/sensu-plugins-cpu-checks/version.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-influxdb-1.1.0/CHANGELOG.md create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-influxdb-1.1.0/LICENSE create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-influxdb-1.1.0/README.md create mode 100755 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-influxdb-1.1.0/bin/check-influxdb-query.rb create mode 100755 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-influxdb-1.1.0/bin/check-influxdb.rb create mode 100755 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-influxdb-1.1.0/bin/metrics-influxdb.rb create mode 100755 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-influxdb-1.1.0/bin/mutator-influxdb-line-protocol.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-influxdb-1.1.0/lib/sensu-plugins-influxdb.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-influxdb-1.1.0/lib/sensu-plugins-influxdb/version.rb create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/specifications/cause-0.1.gemspec create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/specifications/dentaku-2.0.9.gemspec create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/specifications/influxdb-0.3.13.gemspec create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/specifications/jsonpath-0.5.8.gemspec create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/specifications/multi_json-1.12.1.gemspec create mode 100644 deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/specifications/sensu-plugins-influxdb-1.1.0.gemspec create mode 100644 deployment_scripts/puppet/modules/sensu_config/manifests/init.pp create mode 100755 deployment_scripts/puppet/modules/sensu_config/templates/redis-sentinel.erb create mode 100644 deployment_scripts/puppet/modules/sensu_config/templates/sentinel.conf.erb create mode 100644 deployment_tasks.yaml create mode 100644 environment_config.yaml create mode 100644 metadata.yaml create mode 100644 network_roles.yaml create mode 100644 repositories/centos/.gitkeep create mode 100644 repositories/ubuntu/.gitkeep diff --git a/README.md b/README.md new file mode 100644 index 0000000..ab77e97 --- /dev/null +++ b/README.md @@ -0,0 +1,71 @@ +Sensu plugin for Fuel +================================= + +Overview +-------- + +Sensu plugin for Fuel extends Mirantis OpenStack functionality by adding +Sensu monitoring. It can be deployed on hosts with Stacklight plugins roles. +Sensu plugin is 100% hot-pluggable. + + +Compatible Fuel versions +------------------------ + +9.0 + + +User Guide +---------- + +1. Create an environment or open existing. In case of new environment select new nodes + with LMA Stacklights roles +2. Enable the plugin on the Settings/Other tab of the Fuel web UI and fill in form + fields: + * in development + +3. Deploy the environment. + + +Installation Guide +================== + +Sensu Plugin for Fuel installation +---------------------------------------------- + +To install Sensu plugin, follow these steps: + +1. Download the plugin + git clone https://github.com/openstack/fuel-plugin-sensu + +2. Copy the plugin on already installed Fuel Master node; ssh can be used for + that. If you do not have the Fuel Master node yet, see + [Quick Start Guide](https://software.mirantis.com/quick-start/): + + # scp fuel-plugin-sensu-0.1.1-1.noarch.rpm root@:/tmp + +3. Log into the Fuel Master node. Install the plugin: + + # cd /tmp + # fuel plugins --install fuel-plugin-sensu-0.1.1-1.noarch.rpm + +4. Check if the plugin was installed successfully: + + # fuel plugins + id | name | version | package_version + ---|---------------------------------|---------|---------------- + 1 | fuel-plugin-sensu | 0.1.1 | 4.0.0 + + +Requirements +------------ + +| Requirement | Version/Comment | +|:---------------------------------|:----------------| +| Mirantis OpenStack compatibility | 9.0 | + + +Limitations +----------- + +This plugin can be used only with Stacklight LMA nodes diff --git a/deployment_scripts/puppet/files/embedded/bin/check-cpu.rb b/deployment_scripts/puppet/files/embedded/bin/check-cpu.rb new file mode 100755 index 0000000..5c7cf07 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/bin/check-cpu.rb @@ -0,0 +1,22 @@ +#!/opt/sensu/embedded/bin/ruby +# +# This file was generated by RubyGems. +# +# The application 'sensu-plugins-cpu-checks' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require 'rubygems' + +version = ">= 0.a" + +if ARGV.first + str = ARGV.first + str = str.dup.force_encoding("BINARY") if str.respond_to? :force_encoding + if str =~ /\A_(.*)_\z/ and Gem::Version.correct?($1) then + version = $1 + ARGV.shift + end +end + +load Gem.activate_bin_path('sensu-plugins-cpu-checks', 'check-cpu.rb', version) diff --git a/deployment_scripts/puppet/files/embedded/bin/check-influxdb-query.rb b/deployment_scripts/puppet/files/embedded/bin/check-influxdb-query.rb new file mode 100755 index 0000000..dd971cb --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/bin/check-influxdb-query.rb @@ -0,0 +1,22 @@ +#!/opt/sensu/embedded/bin/ruby +# +# This file was generated by RubyGems. +# +# The application 'sensu-plugins-influxdb' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require 'rubygems' + +version = ">= 0.a" + +if ARGV.first + str = ARGV.first + str = str.dup.force_encoding("BINARY") if str.respond_to? :force_encoding + if str =~ /\A_(.*)_\z/ and Gem::Version.correct?($1) then + version = $1 + ARGV.shift + end +end + +load Gem.activate_bin_path('sensu-plugins-influxdb', 'check-influxdb-query.rb', version) diff --git a/deployment_scripts/puppet/files/embedded/bin/check-influxdb.rb b/deployment_scripts/puppet/files/embedded/bin/check-influxdb.rb new file mode 100755 index 0000000..9da41d2 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/bin/check-influxdb.rb @@ -0,0 +1,22 @@ +#!/opt/sensu/embedded/bin/ruby +# +# This file was generated by RubyGems. +# +# The application 'sensu-plugins-influxdb' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require 'rubygems' + +version = ">= 0.a" + +if ARGV.first + str = ARGV.first + str = str.dup.force_encoding("BINARY") if str.respond_to? :force_encoding + if str =~ /\A_(.*)_\z/ and Gem::Version.correct?($1) then + version = $1 + ARGV.shift + end +end + +load Gem.activate_bin_path('sensu-plugins-influxdb', 'check-influxdb.rb', version) diff --git a/deployment_scripts/puppet/files/embedded/bin/jsonpath b/deployment_scripts/puppet/files/embedded/bin/jsonpath new file mode 100755 index 0000000..c81fc85 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/bin/jsonpath @@ -0,0 +1,22 @@ +#!/opt/sensu/embedded/bin/ruby +# +# This file was generated by RubyGems. +# +# The application 'jsonpath' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require 'rubygems' + +version = ">= 0.a" + +if ARGV.first + str = ARGV.first + str = str.dup.force_encoding("BINARY") if str.respond_to? :force_encoding + if str =~ /\A_(.*)_\z/ and Gem::Version.correct?($1) then + version = $1 + ARGV.shift + end +end + +load Gem.activate_bin_path('jsonpath', 'jsonpath', version) diff --git a/deployment_scripts/puppet/files/embedded/bin/metrics-cpu-mpstat.rb b/deployment_scripts/puppet/files/embedded/bin/metrics-cpu-mpstat.rb new file mode 100755 index 0000000..d62ddee --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/bin/metrics-cpu-mpstat.rb @@ -0,0 +1,22 @@ +#!/opt/sensu/embedded/bin/ruby +# +# This file was generated by RubyGems. +# +# The application 'sensu-plugins-cpu-checks' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require 'rubygems' + +version = ">= 0.a" + +if ARGV.first + str = ARGV.first + str = str.dup.force_encoding("BINARY") if str.respond_to? :force_encoding + if str =~ /\A_(.*)_\z/ and Gem::Version.correct?($1) then + version = $1 + ARGV.shift + end +end + +load Gem.activate_bin_path('sensu-plugins-cpu-checks', 'metrics-cpu-mpstat.rb', version) diff --git a/deployment_scripts/puppet/files/embedded/bin/metrics-cpu-pcnt-usage.rb b/deployment_scripts/puppet/files/embedded/bin/metrics-cpu-pcnt-usage.rb new file mode 100755 index 0000000..86e8c9e --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/bin/metrics-cpu-pcnt-usage.rb @@ -0,0 +1,22 @@ +#!/opt/sensu/embedded/bin/ruby +# +# This file was generated by RubyGems. +# +# The application 'sensu-plugins-cpu-checks' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require 'rubygems' + +version = ">= 0.a" + +if ARGV.first + str = ARGV.first + str = str.dup.force_encoding("BINARY") if str.respond_to? :force_encoding + if str =~ /\A_(.*)_\z/ and Gem::Version.correct?($1) then + version = $1 + ARGV.shift + end +end + +load Gem.activate_bin_path('sensu-plugins-cpu-checks', 'metrics-cpu-pcnt-usage.rb', version) diff --git a/deployment_scripts/puppet/files/embedded/bin/metrics-cpu.rb b/deployment_scripts/puppet/files/embedded/bin/metrics-cpu.rb new file mode 100755 index 0000000..beb9f4e --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/bin/metrics-cpu.rb @@ -0,0 +1,22 @@ +#!/opt/sensu/embedded/bin/ruby +# +# This file was generated by RubyGems. +# +# The application 'sensu-plugins-cpu-checks' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require 'rubygems' + +version = ">= 0.a" + +if ARGV.first + str = ARGV.first + str = str.dup.force_encoding("BINARY") if str.respond_to? :force_encoding + if str =~ /\A_(.*)_\z/ and Gem::Version.correct?($1) then + version = $1 + ARGV.shift + end +end + +load Gem.activate_bin_path('sensu-plugins-cpu-checks', 'metrics-cpu.rb', version) diff --git a/deployment_scripts/puppet/files/embedded/bin/metrics-influxdb.rb b/deployment_scripts/puppet/files/embedded/bin/metrics-influxdb.rb new file mode 100755 index 0000000..51c0a75 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/bin/metrics-influxdb.rb @@ -0,0 +1,22 @@ +#!/opt/sensu/embedded/bin/ruby +# +# This file was generated by RubyGems. +# +# The application 'sensu-plugins-influxdb' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require 'rubygems' + +version = ">= 0.a" + +if ARGV.first + str = ARGV.first + str = str.dup.force_encoding("BINARY") if str.respond_to? :force_encoding + if str =~ /\A_(.*)_\z/ and Gem::Version.correct?($1) then + version = $1 + ARGV.shift + end +end + +load Gem.activate_bin_path('sensu-plugins-influxdb', 'metrics-influxdb.rb', version) diff --git a/deployment_scripts/puppet/files/embedded/bin/metrics-numastat.rb b/deployment_scripts/puppet/files/embedded/bin/metrics-numastat.rb new file mode 100755 index 0000000..eed5bc5 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/bin/metrics-numastat.rb @@ -0,0 +1,22 @@ +#!/opt/sensu/embedded/bin/ruby +# +# This file was generated by RubyGems. +# +# The application 'sensu-plugins-cpu-checks' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require 'rubygems' + +version = ">= 0.a" + +if ARGV.first + str = ARGV.first + str = str.dup.force_encoding("BINARY") if str.respond_to? :force_encoding + if str =~ /\A_(.*)_\z/ and Gem::Version.correct?($1) then + version = $1 + ARGV.shift + end +end + +load Gem.activate_bin_path('sensu-plugins-cpu-checks', 'metrics-numastat.rb', version) diff --git a/deployment_scripts/puppet/files/embedded/bin/metrics-user-pct-usage.rb b/deployment_scripts/puppet/files/embedded/bin/metrics-user-pct-usage.rb new file mode 100755 index 0000000..a5fd00d --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/bin/metrics-user-pct-usage.rb @@ -0,0 +1,22 @@ +#!/opt/sensu/embedded/bin/ruby +# +# This file was generated by RubyGems. +# +# The application 'sensu-plugins-cpu-checks' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require 'rubygems' + +version = ">= 0.a" + +if ARGV.first + str = ARGV.first + str = str.dup.force_encoding("BINARY") if str.respond_to? :force_encoding + if str =~ /\A_(.*)_\z/ and Gem::Version.correct?($1) then + version = $1 + ARGV.shift + end +end + +load Gem.activate_bin_path('sensu-plugins-cpu-checks', 'metrics-user-pct-usage.rb', version) diff --git a/deployment_scripts/puppet/files/embedded/bin/mutator-influxdb-line-protocol.rb b/deployment_scripts/puppet/files/embedded/bin/mutator-influxdb-line-protocol.rb new file mode 100755 index 0000000..d2742db --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/bin/mutator-influxdb-line-protocol.rb @@ -0,0 +1,22 @@ +#!/opt/sensu/embedded/bin/ruby +# +# This file was generated by RubyGems. +# +# The application 'sensu-plugins-influxdb' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require 'rubygems' + +version = ">= 0.a" + +if ARGV.first + str = ARGV.first + str = str.dup.force_encoding("BINARY") if str.respond_to? :force_encoding + if str =~ /\A_(.*)_\z/ and Gem::Version.correct?($1) then + version = $1 + ARGV.shift + end +end + +load Gem.activate_bin_path('sensu-plugins-influxdb', 'mutator-influxdb-line-protocol.rb', version) diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/cause-0.1/LICENCE.MIT b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/cause-0.1/LICENCE.MIT new file mode 100644 index 0000000..381d9cf --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/cause-0.1/LICENCE.MIT @@ -0,0 +1,19 @@ +Copyright (c) 2013 Conrad Irwin + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/cause-0.1/README.md b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/cause-0.1/README.md new file mode 100644 index 0000000..1ddb52e --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/cause-0.1/README.md @@ -0,0 +1,32 @@ +This is a back-port of Ruby 2.1.0's [`Exception#cause`](http://www.ruby-doc.org/core-2.1.0/Exception.html#method-i-cause) to older versions of Ruby. + +Installation +------------ + +Add `gem 'cause'` to your `Gemfile`, then run `bundle install`. If you're not +using bundler, then just `gem install cause`. + +Usage +----- + +Just continue programming as normal. When you rescue from exceptions they'll +have a third property, cause, in addition to backtrace and message. The cause +is the exception object that was being handled when the error was raised. + +While this is not directly useful in normal programming, it's very useful for +debugging. Exception trackers like [Bugsnag](https://bugsnag.com/) can then pick up +the cause of the exception to help you find out what went wrong. + +Limitations +----------- + +At the moment you cannot set the cause yourself. Overriding `raise` is hairy +business and I wrote this gem late at night, but with sufficient care it's +probably doable. + +Meta-fu +------- + +This gem is Copyright under the MIT licence. See LICENCE.MIT for details. + +Contributions and bug-reports are welcome. diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/cause-0.1/cause.gemspec b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/cause-0.1/cause.gemspec new file mode 100644 index 0000000..0a1d6da --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/cause-0.1/cause.gemspec @@ -0,0 +1,17 @@ +Gem::Specification.new do |gem| + gem.name = 'cause' + gem.version = '0.1' + + gem.summary = 'A backport of Exception#cause from Ruby 2.1.0' + gem.description = "Allows you access to the error that was being handled when this exception was raised." + + gem.authors = ['Conrad Irwin'] + gem.email = %w(conrad@bugsnag.com) + gem.homepage = 'http://github.com/ConradIrwin/cause' + + gem.license = 'MIT' + + gem.required_ruby_version = '>= 1.8.7' + + gem.files = `git ls-files`.split("\n") +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/cause-0.1/lib/cause.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/cause-0.1/lib/cause.rb new file mode 100644 index 0000000..0c3394c --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/cause-0.1/lib/cause.rb @@ -0,0 +1,12 @@ +class Exception + unless method_defined?(:cause) + attr_reader :cause + + alias old_initialize initialize + + def initialize(*a) + @cause = $! + old_initialize(*a) + end + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/.gitignore b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/.gitignore new file mode 100644 index 0000000..6a0a948 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/.gitignore @@ -0,0 +1,11 @@ +*.gem +.bundle +.rbenv-version +Gemfile.lock +bin/* +pkg/* +vendor/* + +/.ruby-gemset +/.ruby-version +/.rspec diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/.pryrc b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/.pryrc new file mode 100644 index 0000000..562c9c5 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/.pryrc @@ -0,0 +1,2 @@ +require "bundler" +Bundler.require diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/.travis.yml b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/.travis.yml new file mode 100644 index 0000000..45b8912 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/.travis.yml @@ -0,0 +1,13 @@ +language: ruby +sudo: false +rvm: + - 1.9.3 + - 2.0.0 + - 2.1.0 + - 2.1.1 + - 2.2.0 + - 2.2.1 + - 2.2.2 + - 2.2.3 + - 2.3.0 + - rbx-2 diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/CHANGELOG.md b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/CHANGELOG.md new file mode 100644 index 0000000..61f36cb --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/CHANGELOG.md @@ -0,0 +1,141 @@ +# Change Log + +## [v2.0.9] 2016-09-19 +- namespace tokenization errors +- automatically coerce arguments to string functions as strings +- selectively disable or clear AST cache + +## [v2.0.8] 2016-05-10 +- numeric input validations +- fail with gem-specific error for invalid arithmetic operands +- add `LEFT`, `RIGHT`, `MID`, `LEN`, `FIND`, `SUBSTITUTE`, and `CONCAT` string functions + +## [v2.0.7] 2016-02-25 +- fail with gem-specific error for parsing issues +- support NULL literals and nil variables +- keep reference to variable that caused failure when bulk-solving + +## [v2.0.6] 2016-01-26 +- support array parameters for external functions +- support case statements +- support precision for `ROUNDUP` and `ROUNDDOWN` functions +- prevent errors from corrupting calculator memory + +## [v2.0.5] 2015-09-03 +- fix bug with detecting unbound nodes +- silence warnings +- allow registration of custom token scanners + +## [v2.0.4] 2015-09-03 +- fix BigDecimal conversion bug +- add caching for bulk expression solving dependency order +- allow for custom configuration for token scanners + +## [v2.0.3] 2015-08-25 +- bug fixes +- performance enhancements +- code cleanup + +## [v2.0.1] 2015-08-15 +- add support for boolean literals +- implement basic parse-time type checking + +## [v2.0.0] 2015-08-07 +- shunting-yard parser for performance enhancement and AST generation +- AST caching for performance enhancement +- support comments in formulas +- support all functions from the Ruby Math module + +## [v1.2.6] 2015-05-30 +- support custom error handlers for systems of formulas + +## [v1.2.5] 2015-05-23 +- fix memory leak + +## [v1.2.2] 2014-12-19 +- performance enhancements +- unary minus bug fixes +- preserve provided hash keys for systems of formulas + +## [v1.2.0] 2014-10-21 +- add dependency resolution to automatically solve systems of formulas + +## [v1.1.0] 2014-07-30 +- add strict evaluation mode to raise `UnboundVariableError` if not all variable values are provided +- return division results as `BigDecimal` values + +## [v1.0.0] 2014-03-06 +- cleanup and 1.0 release + +## [v0.2.14] 2014-01-24 +- add modulo operator +- add unary percentage operator +- support registration of custom functions at runtime + +## [v0.2.10] 2012-12-10 +- return integer result for exact division, decimal otherwise + +## [v0.2.9] 2012-10-17 +- add `ROUNDUP` / `ROUNDDOWN` functions + +## [v0.2.8] 2012-09-30 +- make function name matching case-insensitive + +## [v0.2.7] 2012-09-26 +- support passing arbitrary expressions as function arguments + +## [v0.2.6] 2012-09-19 +- add `NOT` function + +## [v0.2.5] 2012-06-20 +- add exponent operator +- add support for digits in variable identifiers + +## [v0.2.4] 2012-02-29 +- add support for `min < x < max` syntax for inequality ranges + +## [v0.2.2] 2012-02-22 +- support `ROUND` to arbitrary decimal place on older Rubies +- ensure case is preserved for string values + +## [v0.2.1] 2012-02-12 +- add `ROUND` function + +## [v0.1.3] 2012-01-31 +- add support for string datatype + +## [v0.1.1] 2012-01-24 +- change from square bracket to parentheses for top-level evaluation +- add `IF` function + +## [v0.1.0] 2012-01-20 +- initial release + +[v2.0.9]: https://github.com/rubysolo/dentaku/compare/v2.0.8...v2.0.9 +[v2.0.8]: https://github.com/rubysolo/dentaku/compare/v2.0.7...v2.0.8 +[v2.0.7]: https://github.com/rubysolo/dentaku/compare/v2.0.6...v2.0.7 +[v2.0.6]: https://github.com/rubysolo/dentaku/compare/v2.0.5...v2.0.6 +[v2.0.5]: https://github.com/rubysolo/dentaku/compare/v2.0.4...v2.0.5 +[v2.0.4]: https://github.com/rubysolo/dentaku/compare/v2.0.3...v2.0.4 +[v2.0.3]: https://github.com/rubysolo/dentaku/compare/v2.0.1...v2.0.3 +[v2.0.1]: https://github.com/rubysolo/dentaku/compare/v2.0.0...v2.0.1 +[v2.0.0]: https://github.com/rubysolo/dentaku/compare/v1.2.6...v2.0.0 +[v1.2.6]: https://github.com/rubysolo/dentaku/compare/v1.2.5...v1.2.6 +[v1.2.5]: https://github.com/rubysolo/dentaku/compare/v1.2.2...v1.2.5 +[v1.2.2]: https://github.com/rubysolo/dentaku/compare/v1.2.0...v1.2.2 +[v1.2.0]: https://github.com/rubysolo/dentaku/compare/v1.1.0...v1.2.0 +[v1.1.0]: https://github.com/rubysolo/dentaku/compare/v1.0.0...v1.1.0 +[v1.0.0]: https://github.com/rubysolo/dentaku/compare/v0.2.14...v1.0.0 +[v0.2.14]: https://github.com/rubysolo/dentaku/compare/v0.2.10...v0.2.14 +[v0.2.10]: https://github.com/rubysolo/dentaku/compare/v0.2.9...v0.2.10 +[v0.2.9]: https://github.com/rubysolo/dentaku/compare/v0.2.8...v0.2.9 +[v0.2.8]: https://github.com/rubysolo/dentaku/compare/v0.2.7...v0.2.8 +[v0.2.7]: https://github.com/rubysolo/dentaku/compare/v0.2.6...v0.2.7 +[v0.2.6]: https://github.com/rubysolo/dentaku/compare/v0.2.5...v0.2.6 +[v0.2.5]: https://github.com/rubysolo/dentaku/compare/v0.2.4...v0.2.5 +[v0.2.4]: https://github.com/rubysolo/dentaku/compare/v0.2.2...v0.2.4 +[v0.2.2]: https://github.com/rubysolo/dentaku/compare/v0.2.1...v0.2.2 +[v0.2.1]: https://github.com/rubysolo/dentaku/compare/v0.1.3...v0.2.1 +[v0.1.3]: https://github.com/rubysolo/dentaku/compare/v0.1.1...v0.1.3 +[v0.1.1]: https://github.com/rubysolo/dentaku/compare/v0.1.0...v0.1.1 +[v0.1.0]: https://github.com/rubysolo/dentaku/commit/68724fd9c8fa637baf7b9d5515df0caa31e226bd diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/Gemfile b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/Gemfile new file mode 100644 index 0000000..5a20cac --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/Gemfile @@ -0,0 +1,9 @@ +source "http://rubygems.org" + +# Specify your gem's dependencies in dentaku.gemspec +gemspec + +if RUBY_VERSION.to_f >= 2.0 && RUBY_ENGINE == 'ruby' + gem 'pry-byebug' + gem 'pry-stack_explorer' +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/README.md b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/README.md new file mode 100644 index 0000000..b8c485e --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/README.md @@ -0,0 +1,297 @@ +Dentaku +======= + +[![Join the chat at https://gitter.im/rubysolo/dentaku](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/rubysolo/dentaku?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) +[![Gem Version](https://badge.fury.io/rb/dentaku.png)](http://badge.fury.io/rb/dentaku) +[![Build Status](https://travis-ci.org/rubysolo/dentaku.png?branch=master)](https://travis-ci.org/rubysolo/dentaku) +[![Code Climate](https://codeclimate.com/github/rubysolo/dentaku.png)](https://codeclimate.com/github/rubysolo/dentaku) +[![Hakiri](https://hakiri.io/github/rubysolo/dentaku/master.svg)](https://hakiri.io/github/rubysolo/dentaku) + +DESCRIPTION +----------- + +Dentaku is a parser and evaluator for a mathematical and logical formula +language that allows run-time binding of values to variables referenced in the +formulas. It is intended to safely evaluate untrusted expressions without +opening security holes. + +EXAMPLE +------- + +This is probably simplest to illustrate in code: + +```ruby +calculator = Dentaku::Calculator.new +calculator.evaluate('10 * 2') +#=> 20 +``` + +Okay, not terribly exciting. But what if you want to have a reference to a +variable, and evaluate it at run-time? Here's how that would look: + +```ruby +calculator.evaluate('kiwi + 5', kiwi: 2) +#=> 7 +``` + +You can also store the variable values in the calculator's memory and then +evaluate expressions against those stored values: + +```ruby +calculator.store(peaches: 15) +calculator.evaluate('peaches - 5') +#=> 10 +calculator.evaluate('peaches >= 15') +#=> true +``` + +For maximum CS geekery, `bind` is an alias of `store`. + +Dentaku understands precedence order and using parentheses to group expressions +to ensure proper evaluation: + +```ruby +calculator.evaluate('5 + 3 * 2') +#=> 11 +calculator.evaluate('(5 + 3) * 2') +#=> 16 +``` + +The `evaluate` method will return `nil` if there is an error in the formula. +If this is not the desired behavior, use `evaluate!`, which will raise an +exception. + +```ruby +calculator.evaluate('10 * x') +#=> nil +calculator.evaluate!('10 * x') +Dentaku::UnboundVariableError: Dentaku::UnboundVariableError +``` + +Dentaku has built-in functions (including `if`, `not`, `min`, `max`, and +`round`) and the ability to define custom functions (see below). Functions +generally work like their counterparts in Excel: + +```ruby +calculator.evaluate('if (pears < 10, 10, 20)', pears: 5) +#=> 10 +calculator.evaluate('if (pears < 10, 10, 20)', pears: 15) +#=> 20 +``` + +`round` can be called with or without the number of decimal places: + +```ruby +calculator.evaluate('round(8.2)') +#=> 8 +calculator.evaluate('round(8.2759, 2)') +#=> 8.28 +``` + +`round` follows rounding rules, while `roundup` and `rounddown` are `ceil` and +`floor`, respectively. + +If you're too lazy to be building calculator objects, there's a shortcut just +for you: + +```ruby +Dentaku('plums * 1.5', plums: 2) +#=> 3.0 +``` + +PERFORMANCE +----------- + +The flexibility and safety of Dentaku don't come without a price. Tokenizing a +string, parsing to an AST, and then evaluating that AST are about 2 orders of +magnitude slower than doing the same math in pure Ruby! + +The good news is that most of the time is spent in the tokenization and parsing +phases, so if performance is a concern, you can enable AST caching: + +```ruby +Dentaku.enable_ast_cache! +``` + +After this, Dentaku will cache the AST of each formula that it evaluates, so +subsequent evaluations (even with different values for variables) will be much +faster -- closer to 4x native Ruby speed. As usual, these benchmarks should be +considered rough estimates, and you should measure with representative formulas +from your application. Also, if new formulas are constantly introduced to your +application, AST caching will consume more memory with each new formula. + +BUILT-IN OPERATORS AND FUNCTIONS +--------------------------------- + +Math: `+`, `-`, `*`, `/`, `%` + +Logic: `<`, `>`, `<=`, `>=`, `<>`, `!=`, `=`, `AND`, `OR` + +Functions: `IF`, `NOT`, `MIN`, `MAX`, `ROUND`, `ROUNDDOWN`, `ROUNDUP` + +Selections: `CASE` (syntax see [spec](https://github.com/rubysolo/dentaku/blob/master/spec/calculator_spec.rb#L292)) + +Math: all functions from Ruby's Math module, including `SIN`, `COS`, `TAN`, etc. + +String: `LEFT`, `RIGHT`, `MID`, `LEN`, `FIND`, `SUBSTITUTE`, `CONCAT` + +RESOLVING DEPENDENCIES +---------------------- + +If your formulas rely on one another, they may need to be resolved in a +particular order. For example: + +```ruby +calc = Dentaku::Calculator.new +calc.store(monthly_income: 50) +need_to_compute = { + income_taxes: "annual_income / 5", + annual_income: "monthly_income * 12" +} +``` + +In the example, `annual_income` needs to be computed (and stored) before +`income_taxes`. + +Dentaku provides two methods to help resolve formulas in order: + +#### Calculator.dependencies +Pass a (string) expression to Dependencies and get back a list of variables (as +`:symbols`) that are required for the expression. `Dependencies` also takes +into account variables already (explicitly) stored into the calculator. + +```ruby +calc.dependencies("monthly_income * 12") +#=> [] +# (since monthly_income is in memory) + +calc.dependencies("annual_income / 5") +#=> [:annual_income] +``` + +#### Calculator.solve! / Calculator.solve +Have Dentaku figure out the order in which your formulas need to be evaluated. + +Pass in a hash of `{eventual_variable_name: "expression"}` to `solve!` and +have Dentaku resolve dependencies (using `TSort`) for you. + +Raises `TSort::Cyclic` when a valid expression order cannot be found. + +```ruby +calc = Dentaku::Calculator.new +calc.store(monthly_income: 50) +need_to_compute = { + income_taxes: "annual_income / 5", + annual_income: "monthly_income * 12" +} +calc.solve!(need_to_compute) +#=> {annual_income: 600, income_taxes: 120} + +calc.solve!( + make_money: "have_money", + have_money: "make_money" +} +#=> raises TSort::Cyclic +``` + +`solve!` will also raise an exception if any of the formulas in the set cannot +be evaluated (e.g. raise `ZeroDivisionError`). The non-bang `solve` method will +find as many solutions as possible and return the symbol `:undefined` for the +problem formulas. + +INLINE COMMENTS +--------------------------------- + +If your expressions grow long or complex, you may add inline comments for future +reference. This is particularly useful if you save your expressions in a model. + +```ruby +calculator.evaluate('kiwi + 5 /* This is a comment */', kiwi: 2) +#=> 7 +``` + +Comments can be single or multi-line. The following are also valid. + +``` +/* + * This is a multi-line comment + */ + +/* + This is another type of multi-line comment + */ +``` + +EXTERNAL FUNCTIONS +------------------ + +I don't know everything, so I might not have implemented all the functions you +need. Please implement your favorites and send a pull request! Okay, so maybe +that's not feasible because: + +1. You can't be bothered to share +1. You can't wait for me to respond to a pull request, you need it `NOW()` +1. The formula is the secret sauce for your startup + +Whatever your reasons, Dentaku supports adding functions at runtime. To add a +function, you'll need to specify a name, a return type, and a lambda that +accepts all function arguments and returns the result value. + +Here's an example of adding a function named `POW` that implements +exponentiation. + +```ruby +> c = Dentaku::Calculator.new +> c.add_function(:pow, :numeric, ->(mantissa, exponent) { mantissa ** exponent }) +> c.evaluate('POW(3,2)') +#=> 9 +> c.evaluate('POW(2,3)') +#=> 8 +``` + +Here's an example of adding a variadic function: + +```ruby +> c = Dentaku::Calculator.new +> c.add_function(:max, :numeric, ->(*args) { args.max }) +> c.evaluate 'MAX(8,6,7,5,3,0,9)' +#=> 9 +``` + +(However both of these are already built-in -- the `^` operator and the `MAX` +function) + +Functions can be added individually using Calculator#add_function, or en masse +using Calculator#add_functions. + +THANKS +------ + +Big thanks to [ElkStone Basements](http://www.elkstonebasements.com/) for +allowing me to extract and open source this code. Thanks also to all the +[contributors](https://github.com/rubysolo/dentaku/graphs/contributors)! + + +LICENSE +------- + +(The MIT License) + +Copyright © 2012-2016 Solomon White + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the ‘Software’), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/Rakefile b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/Rakefile new file mode 100644 index 0000000..dba88e6 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/Rakefile @@ -0,0 +1,28 @@ +require 'bundler/gem_tasks' +require 'rspec/core/rake_task' + +desc "Run specs" +task :spec do + RSpec::Core::RakeTask.new(:spec) do |t| + t.rspec_opts = %w{--colour --format progress} + t.pattern = 'spec/**/*_spec.rb' + end +end + +desc "Default: run specs." +task default: :spec + +task :console do + begin + require 'pry' + console = Pry + rescue LoadError + require 'irb' + require 'irb/completion' + console = IRB + end + + require 'dentaku' + ARGV.clear + console.start +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/dentaku.gemspec b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/dentaku.gemspec new file mode 100644 index 0000000..3cb51fc --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/dentaku.gemspec @@ -0,0 +1,27 @@ +# -*- encoding: utf-8 -*- +$:.push File.expand_path("../lib", __FILE__) +require "dentaku/version" + +Gem::Specification.new do |s| + s.name = "dentaku" + s.version = Dentaku::VERSION + s.authors = ["Solomon White"] + s.email = ["rubysolo@gmail.com"] + s.homepage = "http://github.com/rubysolo/dentaku" + s.licenses = %w(MIT) + s.summary = %q{A formula language parser and evaluator} + s.description = <<-DESC + Dentaku is a parser and evaluator for mathematical formulas + DESC + + s.rubyforge_project = "dentaku" + + s.add_development_dependency('rake') + s.add_development_dependency('rspec') + s.add_development_dependency('pry') + + s.files = `git ls-files`.split("\n") + s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") + s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } + s.require_paths = ["lib"] +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku.rb new file mode 100644 index 0000000..1b081b8 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku.rb @@ -0,0 +1,43 @@ +require "bigdecimal" +require "dentaku/calculator" +require "dentaku/version" + +module Dentaku + @enable_ast_caching = false + @enable_dependency_order_caching = false + + def self.evaluate(expression, data={}) + calculator.evaluate(expression, data) + end + + def self.enable_caching! + enable_ast_cache! + enable_dependency_order_cache! + end + + def self.enable_ast_cache! + @enable_ast_caching = true + end + + def self.cache_ast? + @enable_ast_caching + end + + def self.enable_dependency_order_cache! + @enable_dependency_order_caching = true + end + + def self.cache_dependency_order? + @enable_dependency_order_caching + end + + private + + def self.calculator + @calculator ||= Dentaku::Calculator.new + end +end + +def Dentaku(expression, data={}) + Dentaku.evaluate(expression, data) +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast.rb new file mode 100644 index 0000000..95cd512 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast.rb @@ -0,0 +1,21 @@ +require_relative './ast/node' +require_relative './ast/nil' +require_relative './ast/numeric' +require_relative './ast/logical' +require_relative './ast/string' +require_relative './ast/identifier' +require_relative './ast/arithmetic' +require_relative './ast/negation' +require_relative './ast/comparators' +require_relative './ast/combinators' +require_relative './ast/grouping' +require_relative './ast/case' +require_relative './ast/functions/if' +require_relative './ast/functions/max' +require_relative './ast/functions/min' +require_relative './ast/functions/not' +require_relative './ast/functions/round' +require_relative './ast/functions/roundup' +require_relative './ast/functions/rounddown' +require_relative './ast/functions/ruby_math' +require_relative './ast/functions/string_functions' diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/arithmetic.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/arithmetic.rb new file mode 100644 index 0000000..74ac064 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/arithmetic.rb @@ -0,0 +1,129 @@ +require_relative './operation' +require 'bigdecimal' +require 'bigdecimal/util' + +module Dentaku + module AST + class Arithmetic < Operation + def initialize(*) + super + unless valid_node?(left) && valid_node?(right) + fail ParseError, "#{ self.class } requires numeric operands" + end + end + + def type + :numeric + end + + def value(context={}) + l = cast(left.value(context)) + r = cast(right.value(context)) + l.public_send(operator, r) + end + + private + + def cast(value, prefer_integer=true) + validate_numeric(value) + v = BigDecimal.new(value, Float::DIG+1) + v = v.to_i if prefer_integer && v.frac.zero? + v + end + + def valid_node?(node) + node && (node.dependencies.any? || node.type == :numeric) + end + + def validate_numeric(value) + Float(value) + rescue ::ArgumentError, ::TypeError + fail Dentaku::ArgumentError, "#{ self.class } requires numeric operands" + end + end + + class Addition < Arithmetic + def operator + :+ + end + + def self.precedence + 10 + end + end + + class Subtraction < Arithmetic + def operator + :- + end + + def self.precedence + 10 + end + end + + class Multiplication < Arithmetic + def operator + :* + end + + def self.precedence + 20 + end + end + + class Division < Arithmetic + def value(context={}) + r = cast(right.value(context), false) + raise Dentaku::ZeroDivisionError if r.zero? + + cast(cast(left.value(context)) / r) + end + + def self.precedence + 20 + end + end + + class Modulo < Arithmetic + def initialize(left, right) + @left = left + @right = right + + unless (valid_node?(left) || left.nil?) && valid_node?(right) + fail ParseError, "#{ self.class } requires numeric operands" + end + end + + def percent? + left.nil? + end + + def value(context={}) + if percent? + cast(right.value(context)) * 0.01 + else + super + end + end + + def operator + :% + end + + def self.precedence + 20 + end + end + + class Exponentiation < Arithmetic + def operator + :** + end + + def self.precedence + 30 + end + end + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/case.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/case.rb new file mode 100644 index 0000000..449fd67 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/case.rb @@ -0,0 +1,52 @@ +require_relative './case/case_conditional' +require_relative './case/case_when' +require_relative './case/case_then' +require_relative './case/case_switch_variable' +require_relative './case/case_else' + +module Dentaku + module AST + class Case < Node + def initialize(*nodes) + @switch = nodes.shift + + unless @switch.is_a?(AST::CaseSwitchVariable) + raise 'Case missing switch variable' + end + + @conditions = nodes + + @else = @conditions.pop if @conditions.last.is_a?(AST::CaseElse) + + @conditions.each do |condition| + unless condition.is_a?(AST::CaseConditional) + raise "#{condition} is not a CaseConditional" + end + end + end + + def value(context={}) + switch_value = @switch.value(context) + @conditions.each do |condition| + if condition.when.value(context) == switch_value + return condition.then.value(context) + end + end + + if @else + return @else.value(context) + else + raise "No block matched the switch value '#{switch_value}'" + end + end + + def dependencies(context={}) + # TODO: should short-circuit + @switch.dependencies(context) + + @conditions.flat_map do |condition| + condition.dependencies(context) + end + end + end + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/case/case_conditional.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/case/case_conditional.rb new file mode 100644 index 0000000..846590f --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/case/case_conditional.rb @@ -0,0 +1,23 @@ +module Dentaku + module AST + class CaseConditional < Node + attr_reader :when, + :then + + def initialize(when_statement, then_statement) + @when = when_statement + unless @when.is_a?(AST::CaseWhen) + raise 'Expected first argument to be a CaseWhen' + end + @then = then_statement + unless @then.is_a?(AST::CaseThen) + raise 'Expected second argument to be a CaseThen' + end + end + + def dependencies(context={}) + @when.dependencies(context) + @then.dependencies(context) + end + end + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/case/case_else.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/case/case_else.rb new file mode 100644 index 0000000..bc069de --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/case/case_else.rb @@ -0,0 +1,21 @@ +module Dentaku + module AST + class CaseElse < Node + def self.arity + 1 + end + + def initialize(node) + @node = node + end + + def value(context={}) + @node.value(context) + end + + def dependencies(context={}) + @node.dependencies(context) + end + end + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/case/case_switch_variable.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/case/case_switch_variable.rb new file mode 100644 index 0000000..bc07b89 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/case/case_switch_variable.rb @@ -0,0 +1,21 @@ +module Dentaku + module AST + class CaseSwitchVariable < Node + def initialize(node) + @node = node + end + + def value(context={}) + @node.value(context) + end + + def dependencies(context={}) + @node.dependencies(context) + end + + def self.arity + 1 + end + end + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/case/case_then.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/case/case_then.rb new file mode 100644 index 0000000..4c2d5d5 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/case/case_then.rb @@ -0,0 +1,21 @@ +module Dentaku + module AST + class CaseThen < Node + def self.arity + 1 + end + + def initialize(node) + @node = node + end + + def value(context={}) + @node.value(context) + end + + def dependencies(context={}) + @node.dependencies(context) + end + end + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/case/case_when.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/case/case_when.rb new file mode 100644 index 0000000..c4079ae --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/case/case_when.rb @@ -0,0 +1,21 @@ +module Dentaku + module AST + class CaseWhen < Operation + def self.arity + 1 + end + + def initialize(node) + @node = node + end + + def value(context={}) + @node.value(context) + end + + def dependencies(context={}) + @node.dependencies(context) + end + end + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/combinators.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/combinators.rb new file mode 100644 index 0000000..a02fd58 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/combinators.rb @@ -0,0 +1,36 @@ +require_relative './operation' + +module Dentaku + module AST + class Combinator < Operation + def initialize(*) + super + unless valid_node?(left) && valid_node?(right) + fail ParseError, "#{ self.class } requires logical operands" + end + end + + def type + :logical + end + + private + + def valid_node?(node) + node.dependencies.any? || node.type == :logical + end + end + + class And < Combinator + def value(context={}) + left.value(context) && right.value(context) + end + end + + class Or < Combinator + def value(context={}) + left.value(context) || right.value(context) + end + end + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/comparators.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/comparators.rb new file mode 100644 index 0000000..c7c9ee0 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/comparators.rb @@ -0,0 +1,51 @@ +require_relative './operation' + +module Dentaku + module AST + class Comparator < Operation + def self.precedence + 5 + end + + def type + :logical + end + end + + class LessThan < Comparator + def value(context={}) + left.value(context) < right.value(context) + end + end + + class LessThanOrEqual < Comparator + def value(context={}) + left.value(context) <= right.value(context) + end + end + + class GreaterThan < Comparator + def value(context={}) + left.value(context) > right.value(context) + end + end + + class GreaterThanOrEqual < Comparator + def value(context={}) + left.value(context) >= right.value(context) + end + end + + class NotEqual < Comparator + def value(context={}) + left.value(context) != right.value(context) + end + end + + class Equal < Comparator + def value(context={}) + left.value(context) == right.value(context) + end + end + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/function.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/function.rb new file mode 100644 index 0000000..2f1b82a --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/function.rb @@ -0,0 +1,73 @@ +require_relative 'node' + +module Dentaku + module AST + class Function < Node + def initialize(*args) + @args = args + end + + def dependencies(context={}) + @args.flat_map { |a| a.dependencies(context) } + end + + def self.get(name) + registry.fetch(function_name(name)) { + fail ParseError, "Undefined function #{ name }" + } + end + + def self.register(name, type, implementation) + function = Class.new(self) do + def self.implementation=(impl) + @implementation = impl + end + + def self.implementation + @implementation + end + + def self.type=(type) + @type = type + end + + def self.type + @type + end + + def value(context={}) + args = @args.map { |a| a.value(context) } + self.class.implementation.call(*args) + end + + def type + self.class.type + end + end + + function_class = name.to_s.capitalize + Dentaku::AST.send(:remove_const, function_class) if Dentaku::AST.const_defined?(function_class) + Dentaku::AST.const_set(function_class, function) + + function.implementation = implementation + function.type = type + + registry[function_name(name)] = function + end + + def self.register_class(name, function_class) + registry[function_name(name)] = function_class + end + + private + + def self.function_name(name) + name.to_s.downcase + end + + def self.registry + @registry ||= {} + end + end + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/if.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/if.rb new file mode 100644 index 0000000..6fb240e --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/if.rb @@ -0,0 +1,30 @@ +require_relative '../function' + +module Dentaku + module AST + class If < Function + attr_reader :predicate, :left, :right + + def initialize(predicate, left, right) + @predicate = predicate + @left = left + @right = right + end + + def value(context={}) + predicate.value(context) ? left.value(context) : right.value(context) + end + + def type + left.type + end + + def dependencies(context={}) + # TODO : short-circuit? + (predicate.dependencies(context) + left.dependencies(context) + right.dependencies(context)).uniq + end + end + end +end + +Dentaku::AST::Function.register_class(:if, Dentaku::AST::If) diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/max.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/max.rb new file mode 100644 index 0000000..5d6db1d --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/max.rb @@ -0,0 +1,5 @@ +require_relative '../function' + +Dentaku::AST::Function.register(:max, :numeric, ->(*args) { + args.max +}) diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/min.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/min.rb new file mode 100644 index 0000000..b3841b3 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/min.rb @@ -0,0 +1,5 @@ +require_relative '../function' + +Dentaku::AST::Function.register(:min, :numeric, ->(*args) { + args.min +}) diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/not.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/not.rb new file mode 100644 index 0000000..35df345 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/not.rb @@ -0,0 +1,5 @@ +require_relative '../function' + +Dentaku::AST::Function.register(:not, :logical, ->(logical) { + ! logical +}) diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/round.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/round.rb new file mode 100644 index 0000000..95c329a --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/round.rb @@ -0,0 +1,5 @@ +require_relative '../function' + +Dentaku::AST::Function.register(:round, :numeric, ->(numeric, places=nil) { + numeric.round(places || 0) +}) diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/rounddown.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/rounddown.rb new file mode 100644 index 0000000..4b2625d --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/rounddown.rb @@ -0,0 +1,7 @@ +require_relative '../function' + +Dentaku::AST::Function.register(:rounddown, :numeric, ->(numeric, precision=0) { + tens = 10.0**precision + result = (numeric * tens).floor / tens + precision <= 0 ? result.to_i : result +}) diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/roundup.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/roundup.rb new file mode 100644 index 0000000..5714682 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/roundup.rb @@ -0,0 +1,7 @@ +require_relative '../function' + +Dentaku::AST::Function.register(:roundup, :numeric, ->(numeric, precision=0) { + tens = 10.0**precision + result = (numeric * tens).ceil / tens + precision <= 0 ? result.to_i : result +}) diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/ruby_math.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/ruby_math.rb new file mode 100644 index 0000000..65f4387 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/ruby_math.rb @@ -0,0 +1,8 @@ +# import all functions from Ruby's Math module +require_relative "../function" + +Math.methods(false).each do |method| + Dentaku::AST::Function.register(method, :numeric, ->(*args) { + Math.send(method, *args) + }) +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/string_functions.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/string_functions.rb new file mode 100644 index 0000000..2133c35 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/string_functions.rb @@ -0,0 +1,111 @@ +require_relative '../function' + +module Dentaku + module AST + module StringFunctions + class Left < Function + def initialize(string, length) + @string = string + @length = length + end + + def value(context={}) + string = @string.value(context).to_s + length = @length.value(context) + string[0, length] + end + end + + class Right < Function + def initialize(string, length) + @string = string + @length = length + end + + def value(context={}) + string = @string.value(context).to_s + length = @length.value(context) + string[length * -1, length] || string + end + end + + class Mid < Function + def initialize(string, offset, length) + @string = string + @offset = offset + @length = length + end + + def value(context={}) + string = @string.value(context).to_s + offset = @offset.value(context) + length = @length.value(context) + string[offset - 1, length].to_s + end + end + + class Len < Function + def initialize(string) + @string = string + end + + def value(context={}) + string = @string.value(context).to_s + string.length + end + end + + class Find < Function + def initialize(needle, haystack) + @needle = needle + @haystack = haystack + end + + def value(context={}) + needle = @needle.value(context) + needle = needle.to_s unless needle.is_a?(Regexp) + haystack = @haystack.value(context).to_s + pos = haystack.index(needle) + pos && pos + 1 + end + end + + class Substitute < Function + def initialize(original, search, replacement) + @original = original + @search = search + @replacement = replacement + end + + def value(context={}) + original = @original.value(context).to_s + search = @search.value(context) + search = search.to_s unless search.is_a?(Regexp) + replacement = @replacement.value(context).to_s + original.sub(search, replacement) + end + end + + class Concat < Function + def initialize(left, right) + @left = left + @right = right + end + + def value(context={}) + left = @left.value(context).to_s + right = @right.value(context).to_s + left + right + end + end + end + end +end + +Dentaku::AST::Function.register_class(:left, Dentaku::AST::StringFunctions::Left) +Dentaku::AST::Function.register_class(:right, Dentaku::AST::StringFunctions::Right) +Dentaku::AST::Function.register_class(:mid, Dentaku::AST::StringFunctions::Mid) +Dentaku::AST::Function.register_class(:len, Dentaku::AST::StringFunctions::Len) +Dentaku::AST::Function.register_class(:find, Dentaku::AST::StringFunctions::Find) +Dentaku::AST::Function.register_class(:substitute, Dentaku::AST::StringFunctions::Substitute) +Dentaku::AST::Function.register_class(:concat, Dentaku::AST::StringFunctions::Concat) diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/grouping.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/grouping.rb new file mode 100644 index 0000000..e319caa --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/grouping.rb @@ -0,0 +1,21 @@ +module Dentaku + module AST + class Grouping + def initialize(node) + @node = node + end + + def value(context={}) + @node.value(context) + end + + def type + @node.type + end + + def dependencies(context={}) + @node.dependencies(context) + end + end + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/identifier.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/identifier.rb new file mode 100644 index 0000000..05a87a9 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/identifier.rb @@ -0,0 +1,36 @@ +require_relative '../exceptions' + +module Dentaku + module AST + class Identifier < Node + attr_reader :identifier + + def initialize(token) + @identifier = token.value.downcase + end + + def value(context={}) + v = context.fetch(identifier) do + raise UnboundVariableError.new([identifier]) + end + + case v + when Node + v.value(context) + else + v + end + end + + def dependencies(context={}) + context.has_key?(identifier) ? dependencies_of(context[identifier]) : [identifier] + end + + private + + def dependencies_of(node) + node.respond_to?(:dependencies) ? node.dependencies : [] + end + end + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/literal.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/literal.rb new file mode 100644 index 0000000..b7d8003 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/literal.rb @@ -0,0 +1,20 @@ +module Dentaku + module AST + class Literal < Node + attr_reader :type + + def initialize(token) + @value = token.value + @type = token.category + end + + def value(*) + @value + end + + def dependencies(*) + [] + end + end + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/logical.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/logical.rb new file mode 100644 index 0000000..287cdf6 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/logical.rb @@ -0,0 +1,8 @@ +require_relative "./literal" + +module Dentaku + module AST + class Logical < Literal + end + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/negation.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/negation.rb new file mode 100644 index 0000000..bb281b2 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/negation.rb @@ -0,0 +1,40 @@ +module Dentaku + module AST + class Negation < Operation + def initialize(node) + @node = node + fail ParseError, "Negation requires numeric operand" unless valid_node?(node) + end + + def value(context={}) + @node.value(context) * -1 + end + + def type + :numeric + end + + def self.arity + 1 + end + + def self.right_associative? + true + end + + def self.precedence + 40 + end + + def dependencies(context={}) + @node.dependencies(context) + end + + private + + def valid_node?(node) + node && (node.dependencies.any? || node.type == :numeric) + end + end + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/nil.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/nil.rb new file mode 100644 index 0000000..15ccc0f --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/nil.rb @@ -0,0 +1,9 @@ +module Dentaku + module AST + class Nil < Node + def value(*) + nil + end + end + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/node.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/node.rb new file mode 100644 index 0000000..a26c201 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/node.rb @@ -0,0 +1,17 @@ +module Dentaku + module AST + class Node + def self.precedence + 0 + end + + def self.arity + nil + end + + def dependencies(context={}) + [] + end + end + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/numeric.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/numeric.rb new file mode 100644 index 0000000..8774cfb --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/numeric.rb @@ -0,0 +1,8 @@ +require_relative "./literal" + +module Dentaku + module AST + class Numeric < Literal + end + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/operation.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/operation.rb new file mode 100644 index 0000000..2f4c2cd --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/operation.rb @@ -0,0 +1,22 @@ +require_relative './node' + +module Dentaku + module AST + class Operation < Node + attr_reader :left, :right + + def initialize(left, right) + @left = left + @right = right + end + + def dependencies(context={}) + (left.dependencies(context) + right.dependencies(context)).uniq + end + + def self.right_associative? + false + end + end + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/string.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/string.rb new file mode 100644 index 0000000..1f833ad --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/string.rb @@ -0,0 +1,8 @@ +require_relative "./literal" + +module Dentaku + module AST + class String < Literal + end + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/bulk_expression_solver.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/bulk_expression_solver.rb new file mode 100644 index 0000000..aa8c7e4 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/bulk_expression_solver.rb @@ -0,0 +1,99 @@ +require 'dentaku/calculator' +require 'dentaku/dependency_resolver' +require 'dentaku/exceptions' +require 'dentaku/parser' +require 'dentaku/tokenizer' + +module Dentaku + class BulkExpressionSolver + def initialize(expression_hash, calculator) + self.expression_hash = expression_hash + self.calculator = calculator + end + + def solve! + solve(&raise_exception_handler) + end + + def solve(&block) + error_handler = block || return_undefined_handler + results = load_results(&error_handler) + + expression_hash.each_with_object({}) do |(k, _), r| + r[k] = results[k.to_s] + end + end + + private + + def self.dependency_cache + @dep_cache ||= {} + end + + attr_accessor :expression_hash, :calculator + + def return_undefined_handler + ->(*) { :undefined } + end + + def raise_exception_handler + ->(ex) { raise ex } + end + + def load_results(&block) + variables_in_resolve_order.each_with_object({}) do |var_name, r| + begin + value_from_memory = calculator.memory[var_name] + + if value_from_memory.nil? && + expressions[var_name].nil? && + !calculator.memory.has_key?(var_name) + next + end + + value = value_from_memory || + evaluate!(expressions[var_name], expressions.merge(r)) + + r[var_name] = value + rescue Dentaku::UnboundVariableError, ZeroDivisionError => ex + ex.recipient_variable = var_name + r[var_name] = block.call(ex) + end + end + end + + def expressions + @expressions ||= Hash[expression_hash.map { |k,v| [k.to_s, v] }] + end + + def expression_dependencies + Hash[expressions.map { |var, expr| [var, calculator.dependencies(expr)] }].tap do |d| + d.values.each do |deps| + unresolved = deps.reject { |ud| d.has_key?(ud) } + unresolved.each { |u| add_dependencies(d, u) } + end + end + end + + def add_dependencies(current_dependencies, variable) + node = calculator.memory[variable] + if node.respond_to?(:dependencies) + current_dependencies[variable] = node.dependencies + node.dependencies.each { |d| add_dependencies(current_dependencies, d) } + end + end + + def variables_in_resolve_order + cache_key = expressions.keys.map(&:to_s).sort.join("|") + @ordered_deps ||= self.class.dependency_cache.fetch(cache_key) { + DependencyResolver.find_resolve_order(expression_dependencies).tap do |d| + self.class.dependency_cache[cache_key] = d if Dentaku.cache_dependency_order? + end + } + end + + def evaluate!(expression, results) + calculator.evaluate!(expression, results) + end + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/calculator.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/calculator.rb new file mode 100644 index 0000000..26f8810 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/calculator.rb @@ -0,0 +1,124 @@ +require 'dentaku/bulk_expression_solver' +require 'dentaku/exceptions' +require 'dentaku/token' +require 'dentaku/dependency_resolver' +require 'dentaku/parser' + +module Dentaku + class Calculator + attr_reader :result, :memory, :tokenizer + + def initialize + clear + @tokenizer = Tokenizer.new + @ast_cache = {} + @disable_ast_cache = false + end + + def add_function(name, type, body) + Dentaku::AST::Function.register(name, type, body) + self + end + + def add_functions(fns) + fns.each { |(name, type, body)| add_function(name, type, body) } + self + end + + def disable_cache + @disable_ast_cache = true + yield(self) if block_given? + ensure + @disable_ast_cache = false + end + + def evaluate(expression, data={}) + evaluate!(expression, data) + rescue UnboundVariableError, ArgumentError + yield expression if block_given? + end + + def evaluate!(expression, data={}) + store(data) do + node = expression + node = ast(node) unless node.is_a?(AST::Node) + node.value(memory) + end + end + + def solve!(expression_hash) + BulkExpressionSolver.new(expression_hash, self).solve! + end + + def solve(expression_hash, &block) + BulkExpressionSolver.new(expression_hash, self).solve(&block) + end + + def dependencies(expression) + ast(expression).dependencies(memory) + end + + def ast(expression) + @ast_cache.fetch(expression) { + Parser.new(tokenizer.tokenize(expression)).parse.tap do |node| + @ast_cache[expression] = node if cache_ast? + end + } + end + + def clear_cache(pattern=:all) + case pattern + when :all + @ast_cache = {} + when String + @ast_cache.delete(pattern) + when Regexp + @ast_cache.delete_if { |k,_| k =~ pattern } + else + fail Dentaku::ArgumentError + end + end + + def store(key_or_hash, value=nil) + restore = Hash[memory] + + if value.nil? + key_or_hash.each do |key, val| + memory[key.to_s.downcase] = val + end + else + memory[key_or_hash.to_s.downcase] = value + end + + if block_given? + begin + result = yield + @memory = restore + return result + rescue => e + @memory = restore + raise e + end + end + + self + end + alias_method :bind, :store + + def store_formula(key, formula) + store(key, ast(formula)) + end + + def clear + @memory = {} + end + + def empty? + memory.empty? + end + + def cache_ast? + Dentaku.cache_ast? && !@disable_ast_cache + end + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/dependency_resolver.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/dependency_resolver.rb new file mode 100644 index 0000000..0d74b3c --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/dependency_resolver.rb @@ -0,0 +1,24 @@ +require 'tsort' + +module Dentaku + class DependencyResolver + include TSort + + def self.find_resolve_order(vars_to_dependencies_hash) + self.new(vars_to_dependencies_hash).tsort + end + + def initialize(vars_to_dependencies_hash) + # ensure variables are strings + @vars_to_deps = Hash[vars_to_dependencies_hash.map { |k, v| [k.to_s, v]}] + end + + def tsort_each_node(&block) + @vars_to_deps.each_key(&block) + end + + def tsort_each_child(node, &block) + @vars_to_deps.fetch(node.to_s, []).each(&block) + end + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/exceptions.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/exceptions.rb new file mode 100644 index 0000000..7deab2c --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/exceptions.rb @@ -0,0 +1,25 @@ +module Dentaku + class UnboundVariableError < StandardError + attr_accessor :recipient_variable + + attr_reader :unbound_variables + + def initialize(unbound_variables) + @unbound_variables = unbound_variables + super("no value provided for variables: #{ unbound_variables.join(', ') }") + end + end + + class ParseError < StandardError + end + + class TokenizerError < StandardError + end + + class ArgumentError < ::ArgumentError + end + + class ZeroDivisionError < ::ZeroDivisionError + attr_accessor :recipient_variable + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/parser.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/parser.rb new file mode 100644 index 0000000..bba4c41 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/parser.rb @@ -0,0 +1,222 @@ +require_relative './ast' + +module Dentaku + class Parser + attr_reader :input, :output, :operations, :arities + + def initialize(tokens, options={}) + @input = tokens.dup + @output = [] + @operations = options.fetch(:operations, []) + @arities = options.fetch(:arities, []) + end + + def get_args(count) + Array.new(count) { output.pop }.reverse + end + + def consume(count=2) + operator = operations.pop + output.push operator.new(*get_args(operator.arity || count)) + end + + def parse + return AST::Nil.new if input.empty? + + while token = input.shift + case token.category + when :numeric + output.push AST::Numeric.new(token) + + when :logical + output.push AST::Logical.new(token) + + when :string + output.push AST::String.new(token) + + when :identifier + output.push AST::Identifier.new(token) + + when :operator, :comparator, :combinator + op_class = operation(token) + + if op_class.right_associative? + while operations.last && operations.last < AST::Operation && op_class.precedence < operations.last.precedence + consume + end + + operations.push op_class + else + while operations.last && operations.last < AST::Operation && op_class.precedence <= operations.last.precedence + consume + end + + operations.push op_class + end + + when :null + output.push AST::Nil.new + + when :function + arities.push 0 + operations.push function(token) + + when :case + case token.value + when :open + # special handling for case nesting: strip out inner case + # statements and parse their AST segments recursively + if operations.include?(AST::Case) + last_case_close_index = nil + first_nested_case_close_index = nil + input.each_with_index do |token, index| + first_nested_case_close_index = last_case_close_index + if token.category == :case && token.value == :close + last_case_close_index = index + end + end + inner_case_inputs = input.slice!(0..first_nested_case_close_index) + subparser = Parser.new( + inner_case_inputs, + operations: [AST::Case], + arities: [0] + ) + subparser.parse + output.concat(subparser.output) + else + operations.push AST::Case + arities.push(0) + end + when :close + if operations[1] == AST::CaseThen + while operations.last != AST::Case + consume + end + + operations.push(AST::CaseConditional) + consume(2) + arities[-1] += 1 + elsif operations[1] == AST::CaseElse + while operations.last != AST::Case + consume + end + + arities[-1] += 1 + end + + unless operations.count == 1 && operations.last == AST::Case + fail ParseError, "Unprocessed token #{ token.value }" + end + consume(arities.pop.succ) + when :when + if operations[1] == AST::CaseThen + while ![AST::CaseWhen, AST::Case].include?(operations.last) + consume + end + operations.push(AST::CaseConditional) + consume(2) + arities[-1] += 1 + elsif operations.last == AST::Case + operations.push(AST::CaseSwitchVariable) + consume + end + + operations.push(AST::CaseWhen) + when :then + if operations[1] == AST::CaseWhen + while ![AST::CaseThen, AST::Case].include?(operations.last) + consume + end + end + operations.push(AST::CaseThen) + when :else + if operations[1] == AST::CaseThen + while operations.last != AST::Case + consume + end + + operations.push(AST::CaseConditional) + consume(2) + arities[-1] += 1 + end + + operations.push(AST::CaseElse) + else + fail ParseError, "Unknown case token #{ token.value }" + end + + when :grouping + case token.value + when :open + if input.first && input.first.value == :close + input.shift + consume(0) + else + operations.push AST::Grouping + end + + when :close + while operations.any? && operations.last != AST::Grouping + consume + end + + lparen = operations.pop + fail ParseError, "Unbalanced parenthesis" unless lparen == AST::Grouping + + if operations.last && operations.last < AST::Function + consume(arities.pop.succ) + end + + when :comma + arities[-1] += 1 + while operations.any? && operations.last != AST::Grouping + consume + end + + else + fail ParseError, "Unknown grouping token #{ token.value }" + end + + else + fail ParseError, "Not implemented for tokens of category #{ token.category }" + end + end + + while operations.any? + consume + end + + unless output.count == 1 + fail ParseError, "Invalid statement" + end + + output.first + end + + def operation(token) + { + add: AST::Addition, + subtract: AST::Subtraction, + multiply: AST::Multiplication, + divide: AST::Division, + pow: AST::Exponentiation, + negate: AST::Negation, + mod: AST::Modulo, + + lt: AST::LessThan, + gt: AST::GreaterThan, + le: AST::LessThanOrEqual, + ge: AST::GreaterThanOrEqual, + ne: AST::NotEqual, + eq: AST::Equal, + + and: AST::And, + or: AST::Or, + }.fetch(token.value) + end + + def function(token) + Dentaku::AST::Function.get(token.value) + end + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/token.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/token.rb new file mode 100644 index 0000000..093c46d --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/token.rb @@ -0,0 +1,32 @@ +module Dentaku + class Token + attr_reader :category, :raw_value, :value + + def initialize(category, value, raw_value=nil) + @category = category + @value = value + @raw_value = raw_value + end + + def to_s + raw_value || value + end + + def length + raw_value.to_s.length + end + + def grouping? + is?(:grouping) + end + + def is?(c) + category == c + end + + def ==(other) + (category.nil? || other.category.nil? || category == other.category) && + (value.nil? || other.value.nil? || value == other.value) + end + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/token_matcher.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/token_matcher.rb new file mode 100644 index 0000000..d58d52f --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/token_matcher.rb @@ -0,0 +1,137 @@ +require 'dentaku/token' + +module Dentaku + class TokenMatcher + attr_reader :children, :categories, :values + + def initialize(categories=nil, values=nil, children=[]) + # store categories and values as hash to optimize key lookup, h/t @jan-mangs + @categories = [categories].compact.flatten.each_with_object({}) { |c,h| h[c] = 1 } + @values = [values].compact.flatten.each_with_object({}) { |v,h| h[v] = 1 } + @children = children.compact + @invert = false + + @min = 1 + @max = 1 + @range = (@min..@max) + end + + def | (other_matcher) + self.class.new(:nomatch, :nomatch, leaf_matchers + other_matcher.leaf_matchers) + end + + def invert + @invert = ! @invert + self + end + + def ==(token) + leaf_matcher? ? matches_token?(token) : any_child_matches_token?(token) + end + + def match(token_stream, offset=0) + matched_tokens = [] + matched = false + + while self == token_stream[matched_tokens.length + offset] && matched_tokens.length < @max + matched_tokens << token_stream[matched_tokens.length + offset] + end + + if @range.cover?(matched_tokens.length) + matched = true + end + + [matched, matched_tokens] + end + + def caret + @caret = true + self + end + + def caret? + @caret + end + + def star + @min = 0 + @max = Float::INFINITY + @range = (@min..@max) + self + end + + def plus + @max = Float::INFINITY + @range = (@min..@max) + self + end + + def leaf_matcher? + children.empty? + end + + def leaf_matchers + leaf_matcher? ? [self] : children + end + + private + + def any_child_matches_token?(token) + children.any? { |child| child == token } + end + + def matches_token?(token) + return false if token.nil? + (category_match(token.category) && value_match(token.value)) ^ @invert + end + + def category_match(category) + @categories.empty? || @categories.key?(category) + end + + def value_match(value) + @values.empty? || @values.key?(value) + end + + def self.numeric; new(:numeric); end + def self.string; new(:string); end + def self.logical; new(:logical); end + def self.value + new(:numeric) | new(:string) | new(:logical) + end + + def self.addsub; new(:operator, [:add, :subtract]); end + def self.subtract; new(:operator, :subtract); end + def self.anchored_minus; new(:operator, :subtract).caret; end + def self.muldiv; new(:operator, [:multiply, :divide]); end + def self.pow; new(:operator, :pow); end + def self.mod; new(:operator, :mod); end + def self.combinator; new(:combinator); end + + def self.comparator; new(:comparator); end + def self.comp_gt; new(:comparator, [:gt, :ge]); end + def self.comp_lt; new(:comparator, [:lt, :le]); end + + def self.open; new(:grouping, :open); end + def self.close; new(:grouping, :close); end + def self.comma; new(:grouping, :comma); end + def self.non_group; new(:grouping).invert; end + def self.non_group_star; new(:grouping).invert.star; end + def self.non_close_plus; new(:grouping, :close).invert.plus; end + def self.arguments; (value | comma).plus; end + + def self.if; new(:function, :if); end + def self.round; new(:function, :round); end + def self.roundup; new(:function, :roundup); end + def self.rounddown; new(:function, :rounddown); end + def self.not; new(:function, :not); end + + def self.method_missing(name, *args, &block) + new(:function, name) + end + + def self.respond_to_missing?(name, include_priv) + true + end + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/token_matchers.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/token_matchers.rb new file mode 100644 index 0000000..be4db96 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/token_matchers.rb @@ -0,0 +1,29 @@ +module Dentaku + module TokenMatchers + def self.token_matchers(*symbols) + symbols.map { |s| matcher(s) } + end + + def self.function_token_matchers(function_name, *symbols) + token_matchers(:open, *symbols, :close).unshift( + TokenMatcher.send(function_name) + ) + end + + def self.matcher(symbol) + @matchers ||= [ + :numeric, :string, :addsub, :subtract, :muldiv, :pow, :mod, + :comparator, :comp_gt, :comp_lt, :open, :close, :comma, + :non_close_plus, :non_group, :non_group_star, :arguments, + :logical, :combinator, :if, :round, :roundup, :rounddown, :not, + :anchored_minus, :math_neg_pow, :math_neg_mul + ].each_with_object({}) do |name, matchers| + matchers[name] = TokenMatcher.send(name) + end + + @matchers.fetch(symbol) do + raise "Unknown token symbol #{ symbol }" + end + end + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/token_scanner.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/token_scanner.rb new file mode 100644 index 0000000..0c6774f --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/token_scanner.rb @@ -0,0 +1,142 @@ +require 'bigdecimal' +require 'dentaku/token' + +module Dentaku + class TokenScanner + def initialize(category, regexp, converter=nil, condition=nil) + @category = category + @regexp = %r{\A(#{ regexp })}i + @converter = converter + @condition = condition || ->(*) { true } + end + + def scan(string, last_token=nil) + if (m = @regexp.match(string)) && @condition.call(last_token) + value = raw = m.to_s + value = @converter.call(raw) if @converter + + return Array(value).map do |v| + Token === v ? v : Token.new(@category, v, raw) + end + end + + false + end + + class << self + def available_scanners + [ + :null, + :whitespace, + :numeric, + :double_quoted_string, + :single_quoted_string, + :negate, + :operator, + :grouping, + :case_statement, + :comparator, + :combinator, + :boolean, + :function, + :identifier + ] + end + + def register_default_scanners + register_scanners(available_scanners) + end + + def register_scanners(scanner_ids) + @scanners = scanner_ids.each_with_object({}) do |id, scanners| + scanners[id] = self.send(id) + end + end + + def register_scanner(id, scanner) + @scanners[id] = scanner + end + + def scanners=(scanner_ids) + @scanners.select! { |k,v| scanner_ids.include?(k) } + end + + def scanners + @scanners.values + end + + def whitespace + new(:whitespace, '\s+') + end + + def null + new(:null, 'null\b') + end + + def numeric + new(:numeric, '(\d+(\.\d+)?|\.\d+)\b', lambda { |raw| raw =~ /\./ ? BigDecimal.new(raw) : raw.to_i }) + end + + def double_quoted_string + new(:string, '"[^"]*"', lambda { |raw| raw.gsub(/^"|"$/, '') }) + end + + def single_quoted_string + new(:string, "'[^']*'", lambda { |raw| raw.gsub(/^'|'$/, '') }) + end + + def negate + new(:operator, '-', lambda { |raw| :negate }, lambda { |last_token| + last_token.nil? || + last_token.is?(:operator) || + last_token.is?(:comparator) || + last_token.is?(:combinator) || + last_token.value == :open || + last_token.value == :comma + }) + end + + def operator + names = { pow: '^', add: '+', subtract: '-', multiply: '*', divide: '/', mod: '%' }.invert + new(:operator, '\^|\+|-|\*|\/|%', lambda { |raw| names[raw] }) + end + + def grouping + names = { open: '(', close: ')', comma: ',' }.invert + new(:grouping, '\(|\)|,', lambda { |raw| names[raw] }) + end + + def case_statement + names = { open: 'case', close: 'end', then: 'then', when: 'when', else: 'else' }.invert + new(:case, '(case|end|then|when|else)\b', lambda { |raw| names[raw.downcase] }) + end + + def comparator + names = { le: '<=', ge: '>=', ne: '!=', lt: '<', gt: '>', eq: '=' }.invert + alternate = { ne: '<>', eq: '==' }.invert + new(:comparator, '<=|>=|!=|<>|<|>|==|=', lambda { |raw| names[raw] || alternate[raw] }) + end + + def combinator + new(:combinator, '(and|or)\b', lambda { |raw| raw.strip.downcase.to_sym }) + end + + def boolean + new(:logical, '(true|false)\b', lambda { |raw| raw.strip.downcase == 'true' }) + end + + def function + new(:function, '\w+\s*\(', lambda do |raw| + function_name = raw.gsub('(', '') + [Token.new(:function, function_name.strip.downcase.to_sym, function_name), Token.new(:grouping, :open, '(')] + end) + end + + def identifier + new(:identifier, '\w+\b', lambda { |raw| raw.strip.downcase }) + end + end + + register_default_scanners + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/tokenizer.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/tokenizer.rb new file mode 100644 index 0000000..60a17a0 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/tokenizer.rb @@ -0,0 +1,54 @@ +require 'dentaku/token' +require 'dentaku/token_matcher' +require 'dentaku/token_scanner' + +module Dentaku + class Tokenizer + LPAREN = TokenMatcher.new(:grouping, :open) + RPAREN = TokenMatcher.new(:grouping, :close) + + def tokenize(string) + @nesting = 0 + @tokens = [] + input = strip_comments(string.to_s.dup) + + until input.empty? + fail TokenizerError, "parse error at: '#{ input }'" unless TokenScanner.scanners.any? do |scanner| + scanned, input = scan(input, scanner) + scanned + end + end + + fail TokenizerError, "too many opening parentheses" if @nesting > 0 + + @tokens + end + + def last_token + @tokens.last + end + + def scan(string, scanner) + if tokens = scanner.scan(string, last_token) + tokens.each do |token| + fail TokenizerError, "unexpected zero-width match (:#{ token.category }) at '#{ string }'" if token.length == 0 + + @nesting += 1 if LPAREN == token + @nesting -= 1 if RPAREN == token + fail TokenizerError, "too many closing parentheses" if @nesting < 0 + + @tokens << token unless token.is?(:whitespace) + end + + match_length = tokens.map(&:length).reduce(:+) + [true, string[match_length..-1]] + else + [false, string] + end + end + + def strip_comments(input) + input.gsub(/\/\*[^*]*\*+(?:[^*\/][^*]*\*+)*\//, '') + end + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/version.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/version.rb new file mode 100644 index 0000000..e202ccb --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/version.rb @@ -0,0 +1,3 @@ +module Dentaku + VERSION = "2.0.9" +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/ast/addition_spec.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/ast/addition_spec.rb new file mode 100644 index 0000000..90e2b21 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/ast/addition_spec.rb @@ -0,0 +1,29 @@ +require 'spec_helper' +require 'dentaku/ast/arithmetic' + +require 'dentaku/token' + +describe Dentaku::AST::Addition do + let(:five) { Dentaku::AST::Logical.new Dentaku::Token.new(:numeric, 5) } + let(:six) { Dentaku::AST::Logical.new Dentaku::Token.new(:numeric, 6) } + + let(:t) { Dentaku::AST::Numeric.new Dentaku::Token.new(:logical, true) } + + it 'performs addition' do + node = described_class.new(five, six) + expect(node.value).to eq 11 + end + + it 'requires numeric operands' do + expect { + described_class.new(five, t) + }.to raise_error(Dentaku::ParseError, /requires numeric operands/) + + expression = Dentaku::AST::Multiplication.new(five, five) + group = Dentaku::AST::Grouping.new(expression) + + expect { + described_class.new(group, five) + }.not_to raise_error + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/ast/and_spec.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/ast/and_spec.rb new file mode 100644 index 0000000..75e2da0 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/ast/and_spec.rb @@ -0,0 +1,32 @@ +require 'spec_helper' +require 'dentaku/ast/combinators' + +require 'dentaku/token' + +describe Dentaku::AST::And do + let(:t) { Dentaku::AST::Logical.new Dentaku::Token.new(:logical, true) } + let(:f) { Dentaku::AST::Logical.new Dentaku::Token.new(:logical, false) } + + let(:five) { Dentaku::AST::Numeric.new Dentaku::Token.new(:numeric, 5) } + + it 'performs logical AND' do + node = described_class.new(t, f) + expect(node.value).to eq false + end + + it 'requires logical operands' do + expect { + described_class.new(t, five) + }.to raise_error(Dentaku::ParseError, /requires logical operands/) + + expression = Dentaku::AST::LessThanOrEqual.new(five, five) + expect { + described_class.new(t, expression) + }.not_to raise_error + + expression = Dentaku::AST::Or.new(t, f) + expect { + described_class.new(t, expression) + }.not_to raise_error + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/ast/case_spec.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/ast/case_spec.rb new file mode 100644 index 0000000..3f88ec8 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/ast/case_spec.rb @@ -0,0 +1,80 @@ +require 'spec_helper' +require 'dentaku/ast/operation' +require 'dentaku/ast/logical' +require 'dentaku/ast/identifier' +require 'dentaku/ast/arithmetic' +require 'dentaku/ast/case' + +require 'dentaku/token' + +describe Dentaku::AST::Case do + let!(:one) { Dentaku::AST::Logical.new Dentaku::Token.new(:numeric, 1) } + let!(:two) { Dentaku::AST::Logical.new Dentaku::Token.new(:numeric, 2) } + let!(:apple) do + Dentaku::AST::Logical.new Dentaku::Token.new(:string, 'apple') + end + let!(:banana) do + Dentaku::AST::Logical.new Dentaku::Token.new(:string, 'banana') + end + let!(:identifier) do + Dentaku::AST::Identifier.new(Dentaku::Token.new(:identifier, :fruit)) + end + let!(:switch) { Dentaku::AST::CaseSwitchVariable.new(identifier) } + + let!(:when1) { Dentaku::AST::CaseWhen.new(apple) } + let!(:then1) { Dentaku::AST::CaseThen.new(one) } + let!(:conditional1) { Dentaku::AST::CaseConditional.new(when1, then1) } + + let!(:when2) { Dentaku::AST::CaseWhen.new(banana) } + let!(:then2) { Dentaku::AST::CaseThen.new(two) } + let!(:conditional2) { Dentaku::AST::CaseConditional.new(when2, then2) } + + describe '#value' do + it 'raises an exception if there is no switch variable' do + expect { described_class.new(conditional1, conditional2) } + .to raise_error('Case missing switch variable') + end + + it 'raises an exception if a non-conditional is passed' do + expect { described_class.new(switch, conditional1, when2) } + .to raise_error(/is not a CaseConditional/) + end + + it 'tests each conditional against the switch variable' do + node = described_class.new(switch, conditional1, conditional2) + expect(node.value(fruit: 'banana')).to eq(2) + end + + it 'raises an exception if the conditional is not matched' do + node = described_class.new(switch, conditional1, conditional2) + expect { node.value(fruit: 'orange') } + .to raise_error("No block matched the switch value 'orange'") + end + + it 'uses the else value if provided and conditional is not matched' do + three = Dentaku::AST::Logical.new Dentaku::Token.new(:numeric, 3) + else_statement = Dentaku::AST::CaseElse.new(three) + node = described_class.new( + switch, + conditional1, + conditional2, + else_statement) + expect(node.value(fruit: 'orange')).to eq(3) + end + end + + describe '#dependencies' do + let!(:tax) do + Dentaku::AST::Identifier.new(Dentaku::Token.new(:identifier, :tax)) + end + let!(:addition) { Dentaku::AST::Addition.new(two, tax) } + let!(:when2) { Dentaku::AST::CaseWhen.new(banana) } + let!(:then2) { Dentaku::AST::CaseThen.new(addition) } + let!(:conditional2) { Dentaku::AST::CaseConditional.new(when2, then2) } + + it 'gathers dependencies from switch and conditionals' do + node = described_class.new(switch, conditional1, conditional2) + expect(node.dependencies).to eq([:fruit, :tax]) + end + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/ast/division_spec.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/ast/division_spec.rb new file mode 100644 index 0000000..2f532b0 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/ast/division_spec.rb @@ -0,0 +1,29 @@ +require 'spec_helper' +require 'dentaku/ast/arithmetic' + +require 'dentaku/token' + +describe Dentaku::AST::Division do + let(:five) { Dentaku::AST::Logical.new Dentaku::Token.new(:numeric, 5) } + let(:six) { Dentaku::AST::Logical.new Dentaku::Token.new(:numeric, 6) } + + let(:t) { Dentaku::AST::Numeric.new Dentaku::Token.new(:logical, true) } + + it 'performs division' do + node = described_class.new(five, six) + expect(node.value.round(4)).to eq 0.8333 + end + + it 'requires numeric operands' do + expect { + described_class.new(five, t) + }.to raise_error(Dentaku::ParseError, /requires numeric operands/) + + expression = Dentaku::AST::Multiplication.new(five, five) + group = Dentaku::AST::Grouping.new(expression) + + expect { + described_class.new(group, five) + }.not_to raise_error + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/ast/function_spec.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/ast/function_spec.rb new file mode 100644 index 0000000..0f10665 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/ast/function_spec.rb @@ -0,0 +1,21 @@ +require 'spec_helper' +require 'dentaku/ast/function' + +describe Dentaku::AST::Function do + it 'maintains a function registry' do + expect(described_class).to respond_to(:get) + end + + it 'raises an exception when trying to access an undefined function' do + expect { + described_class.get("flarble") + }.to raise_error(Dentaku::ParseError, /undefined function/i) + end + + it 'registers a custom function' do + described_class.register("flarble", :string, -> { "flarble" }) + expect { described_class.get("flarble") }.not_to raise_error + function = described_class.get("flarble").new + expect(function.value).to eq "flarble" + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/ast/node_spec.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/ast/node_spec.rb new file mode 100644 index 0000000..d596628 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/ast/node_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' +require 'dentaku/ast/node' +require 'dentaku/tokenizer' +require 'dentaku/parser' + +describe Dentaku::AST::Node do + it 'returns list of dependencies' do + node = make_node('x + 5') + expect(node.dependencies).to eq ['x'] + + node = make_node('5 < x') + expect(node.dependencies).to eq ['x'] + + node = make_node('5 < 7') + expect(node.dependencies).to eq [] + + node = make_node('(y * 7)') + expect(node.dependencies).to eq ['y'] + + node = make_node('if(x > 5, y, z)') + expect(node.dependencies).to eq ['x', 'y', 'z'] + + node = make_node('if(x > 5, y, z)') + expect(node.dependencies('x' => 7)).to eq ['y', 'z'] + + node = make_node('') + expect(node.dependencies).to eq [] + end + + it 'returns unique list of dependencies' do + node = make_node('x + x') + expect(node.dependencies).to eq ['x'] + end + + private + + def make_node(expression) + Dentaku::Parser.new(Dentaku::Tokenizer.new.tokenize(expression)).parse + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/ast/numeric_spec.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/ast/numeric_spec.rb new file mode 100644 index 0000000..c25e56e --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/ast/numeric_spec.rb @@ -0,0 +1,16 @@ +require 'spec_helper' +require 'dentaku/ast/numeric' + +require 'dentaku/token' + +describe Dentaku::AST::Numeric do + subject { described_class.new(Dentaku::Token.new(:numeric, 5)) } + + it 'has numeric type' do + expect(subject.type).to eq :numeric + end + + it 'has no dependencies' do + expect(subject.dependencies).to be_empty + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/ast/string_functions_spec.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/ast/string_functions_spec.rb new file mode 100644 index 0000000..ec2b25f --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/ast/string_functions_spec.rb @@ -0,0 +1,135 @@ +require 'spec_helper' +require 'dentaku/ast/functions/string_functions' + +describe Dentaku::AST::StringFunctions::Left do + let(:string) { identifier('string') } + let(:length) { identifier('length') } + + subject { described_class.new(string, length) } + + it 'returns the left N characters of the string' do + expect(subject.value('string' => 'ABCDEFG', 'length' => 4)).to eq 'ABCD' + end + + it 'works correctly with literals' do + left = literal('ABCD') + len = literal(2) + fn = described_class.new(left, len) + expect(fn.value).to eq 'AB' + end + + it 'handles an empty string correctly' do + expect(subject.value('string' => '', 'length' => 4)).to eq '' + end + + it 'handles size greater than input string length correctly' do + expect(subject.value('string' => 'abcdefg', 'length' => 40)).to eq 'abcdefg' + end +end + +describe Dentaku::AST::StringFunctions::Right do + it 'returns the right N characters of the string' do + subject = described_class.new(literal('ABCDEFG'), literal(4)) + expect(subject.value).to eq 'DEFG' + end + + it 'handles an empty string correctly' do + subject = described_class.new(literal(''), literal(4)) + expect(subject.value).to eq '' + end + + it 'handles size greater than input string length correctly' do + subject = described_class.new(literal('abcdefg'), literal(40)) + expect(subject.value).to eq 'abcdefg' + end +end + +describe Dentaku::AST::StringFunctions::Mid do + it 'returns a substring from the middle of the string' do + subject = described_class.new(literal('ABCDEFG'), literal(4), literal(2)) + expect(subject.value).to eq 'DE' + end + + it 'handles an empty string correctly' do + subject = described_class.new(literal(''), literal(4), literal(2)) + expect(subject.value).to eq '' + end + + it 'handles offset greater than input string length correctly' do + subject = described_class.new(literal('abcdefg'), literal(40), literal(4)) + expect(subject.value).to eq '' + end + + it 'handles size greater than input string length correctly' do + subject = described_class.new(literal('abcdefg'), literal(4), literal(40)) + expect(subject.value).to eq 'defg' + end +end + +describe Dentaku::AST::StringFunctions::Len do + it 'returns the length of a string' do + subject = described_class.new(literal('ABCDEFG')) + expect(subject.value).to eq 7 + end + + it 'handles an empty string correctly' do + subject = described_class.new(literal('')) + expect(subject.value).to eq 0 + end +end + +describe Dentaku::AST::StringFunctions::Find do + it 'returns the position of a substring within a string' do + subject = described_class.new(literal('DE'), literal('ABCDEFG')) + expect(subject.value).to eq 4 + end + + it 'handles an empty substring correctly' do + subject = described_class.new(literal(''), literal('ABCDEFG')) + expect(subject.value).to eq 1 + end + + it 'handles an empty string correctly' do + subject = described_class.new(literal('DE'), literal('')) + expect(subject.value).to be_nil + end +end + +describe Dentaku::AST::StringFunctions::Substitute do + it 'replaces a substring within a string' do + subject = described_class.new(literal('ABCDEFG'), literal('DE'), literal('xy')) + expect(subject.value).to eq 'ABCxyFG' + end + + it 'handles an empty search string correctly' do + subject = described_class.new(literal('ABCDEFG'), literal(''), literal('xy')) + expect(subject.value).to eq 'xyABCDEFG' + end + + it 'handles an empty replacement string correctly' do + subject = described_class.new(literal('ABCDEFG'), literal('DE'), literal('')) + expect(subject.value).to eq 'ABCFG' + end +end + +describe Dentaku::AST::StringFunctions::Concat do + it 'concatenates two strings' do + subject = described_class.new(literal('ABC'), literal('DEF')) + expect(subject.value).to eq 'ABCDEF' + end + + it 'concatenates a string onto an empty string' do + subject = described_class.new(literal(''), literal('ABC')) + expect(subject.value).to eq 'ABC' + end + + it 'concatenates an empty string onto a string' do + subject = described_class.new(literal('ABC'), literal('')) + expect(subject.value).to eq 'ABC' + end + + it 'concatenates two empty strings' do + subject = described_class.new(literal(''), literal('')) + expect(subject.value).to eq '' + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/benchmark.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/benchmark.rb new file mode 100644 index 0000000..2fbbe2d --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/benchmark.rb @@ -0,0 +1,70 @@ +#!/usr/bin/env ruby + +require 'dentaku' +require 'allocation_stats' +require 'benchmark' + +puts "Dentaku version #{Dentaku::VERSION}" +puts "Ruby version #{RUBY_VERSION}" + +with_duplicate_variables = [ + "R1+R2+R3+R4+R5+R6", + {"R1"=>100000, "R2"=>0, "R3"=>200000, "R4"=>0, "R5"=>500000, "R6"=>0, "r1"=>100000, "r2"=>0, "r3"=>200000, "r4"=>0, "r5"=>500000, "r6"=>0} +] + +without_duplicate_variables = [ + "R1+R2+R3+R4+R5+R6", + {"R1"=>100000, "R2"=>0, "R3"=>200000, "R4"=>0, "R5"=>500000, "R6"=>0} +] + +def test(args, custom_function: true) + calls = [ args ] * 100 + + 10.times do |i| + + stats = nil + bm = Benchmark.measure do + stats = AllocationStats.trace do + + calls.each do |formula, bound| + + calculator = Dentaku::Calculator.new + + if custom_function + calculator.add_function( + :sum, + :numeric, + ->(numbers) { numbers.inject(:+) } + ) + end + + calculator.evaluate(formula, bound) + end + end + end + + puts " run #{i}: #{bm.total}" + puts stats.allocations(alias_paths: true).group_by(:sourcefile, :class).to_text + end +end + +case ARGV[0] +when '1' + puts "with duplicate (downcased) variables, with a custom function:" + test(with_duplicate_variables, custom_function: true) + +when '2' + puts "with duplicate (downcased) variables, without a custom function:" + test(with_duplicate_variables, custom_function: false) + +when '3' + puts "without duplicate (downcased) variables, with a custom function:" + test(without_duplicate_variables, custom_function: true) + +when '4' + puts "with duplicate (downcased) variables, without a custom function:" + test(without_duplicate_variables, custom_function: false) + +else + puts "select a run option (1-4)" +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/bulk_expression_solver_spec.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/bulk_expression_solver_spec.rb new file mode 100644 index 0000000..0f5cd05 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/bulk_expression_solver_spec.rb @@ -0,0 +1,77 @@ +require 'spec_helper' +require 'dentaku/bulk_expression_solver' + +RSpec.describe Dentaku::BulkExpressionSolver do + let(:calculator) { Dentaku::Calculator.new } + + describe "#solve!" do + it "evaluates properly with variables, even if some in memory" do + expressions = { + weekly_fruit_budget: "weekly_apple_budget + pear * 4", + weekly_apple_budget: "apples * 7", + pear: "1" + } + solver = described_class.new(expressions, calculator.store(apples: 3)) + expect(solver.solve!) + .to eq(pear: 1, weekly_apple_budget: 21, weekly_fruit_budget: 25) + end + + it "lets you know if a variable is unbound" do + expressions = {more_apples: "apples + 1"} + expect { + described_class.new(expressions, calculator).solve! + }.to raise_error(Dentaku::UnboundVariableError) + end + + it "lets you know if the result is a div/0 error" do + expressions = {more_apples: "1/0"} + expect { + described_class.new(expressions, calculator).solve! + }.to raise_error(Dentaku::ZeroDivisionError) + end + + it "does not require keys to be parseable" do + expressions = { "the value of x, incremented" => "x + 1" } + solver = described_class.new(expressions, calculator.store("x" => 3)) + expect(solver.solve!).to eq({ "the value of x, incremented" => 4 }) + end + end + + describe "#solve" do + it "returns :undefined when variables are unbound" do + expressions = {more_apples: "apples + 1"} + expect(described_class.new(expressions, calculator).solve) + .to eq(more_apples: :undefined) + end + + it "allows passing in a custom value to an error handler when a variable is unbound" do + expressions = {more_apples: "apples + 1"} + expect(described_class.new(expressions, calculator).solve { :foo }) + .to eq(more_apples: :foo) + end + + it "allows passing in a custom value to an error handler when there is a div/0 error" do + expressions = {more_apples: "1/0"} + expect(described_class.new(expressions, calculator).solve { :foo }) + .to eq(more_apples: :foo) + end + + it 'stores the recipient variable on the exception when there is a div/0 error' do + expressions = {more_apples: "1/0"} + exception = nil + described_class.new(expressions, calculator).solve do |ex| + exception = ex + end + expect(exception.recipient_variable).to eq('more_apples') + end + + it 'stores the recipient variable on the exception when there is an unbound variable' do + expressions = {more_apples: "apples + 1"} + exception = nil + described_class.new(expressions, calculator).solve do |ex| + exception = ex + end + expect(exception.recipient_variable).to eq('more_apples') + end + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/calculator_spec.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/calculator_spec.rb new file mode 100644 index 0000000..041574c --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/calculator_spec.rb @@ -0,0 +1,450 @@ +require 'spec_helper' +require 'dentaku/calculator' + +describe Dentaku::Calculator do + let(:calculator) { described_class.new } + let(:with_memory) { described_class.new.store(apples: 3) } + + it 'evaluates an expression' do + expect(calculator.evaluate('7+3')).to eq(10) + expect(calculator.evaluate('2 -1')).to eq(1) + expect(calculator.evaluate('-1 + 2')).to eq(1) + expect(calculator.evaluate('1 - 2')).to eq(-1) + expect(calculator.evaluate('1 - - 2')).to eq(3) + expect(calculator.evaluate('-1 - - 2')).to eq(1) + expect(calculator.evaluate('1 - - - 2')).to eq(-1) + expect(calculator.evaluate('(-1 + 2)')).to eq(1) + expect(calculator.evaluate('-(1 + 2)')).to eq(-3) + expect(calculator.evaluate('2 ^ - 1')).to eq(0.5) + expect(calculator.evaluate('2 ^ -(3 - 2)')).to eq(0.5) + expect(calculator.evaluate('(2 + 3) - 1')).to eq(4) + expect(calculator.evaluate('(-2 + 3) - 1')).to eq(0) + expect(calculator.evaluate('(-2 - 3) - 1')).to eq(-6) + expect(calculator.evaluate('1 + -(2 ^ 2)')).to eq(-3) + expect(calculator.evaluate('3 + -num', num: 2)).to eq(1) + expect(calculator.evaluate('-num + 3', num: 2)).to eq(1) + expect(calculator.evaluate('10 ^ 2')).to eq(100) + expect(calculator.evaluate('0 * 10 ^ -5')).to eq(0) + expect(calculator.evaluate('3 + 0 * -3')).to eq(3) + expect(calculator.evaluate('3 + 0 / -3')).to eq(3) + expect(calculator.evaluate('15 % 8')).to eq(7) + expect(calculator.evaluate('(((695759/735000)^(1/(1981-1991)))-1)*1000').round(4)).to eq(5.5018) + expect(calculator.evaluate('0.253/0.253')).to eq(1) + expect(calculator.evaluate('0.253/d', d: 0.253)).to eq(1) + expect(calculator.evaluate('10 + x', x: 'abc')).to be_nil + end + + describe 'memory' do + it { expect(calculator).to be_empty } + it { expect(with_memory).not_to be_empty } + it { expect(with_memory.clear).to be_empty } + + it 'discards local values' do + expect(calculator.evaluate('pears * 2', pears: 5)).to eq(10) + expect(calculator).to be_empty + end + + it 'can store the value `false`' do + calculator.store('i_am_false', false) + expect(calculator.evaluate!('i_am_false')).to eq false + end + + it 'can store multiple values' do + calculator.store(first: 1, second: 2) + expect(calculator.evaluate!('first')).to eq 1 + expect(calculator.evaluate!('second')).to eq 2 + end + + it 'stores formulas' do + calculator.store_formula('area', 'length * width') + expect(calculator.evaluate!('area', length: 5, width: 5)).to eq 25 + end + end + + describe 'dependencies' do + it "finds dependencies in a generic statement" do + expect(calculator.dependencies("bob + dole / 3")).to eq(['bob', 'dole']) + end + + it "doesn't consider variables in memory as dependencies" do + expect(with_memory.dependencies("apples + oranges")).to eq(['oranges']) + end + end + + describe 'solve!' do + it "evaluates properly with variables, even if some in memory" do + expect(with_memory.solve!( + weekly_fruit_budget: "weekly_apple_budget + pear * 4", + weekly_apple_budget: "apples * 7", + pear: "1" + )).to eq(pear: 1, weekly_apple_budget: 21, weekly_fruit_budget: 25) + end + + it "preserves hash keys" do + expect(calculator.solve!( + 'meaning_of_life' => 'age + kids', + 'age' => 40, + 'kids' => 2 + )).to eq('age' => 40, 'kids' => 2, 'meaning_of_life' => 42) + end + + it "lets you know about a cycle if one occurs" do + expect do + calculator.solve!(health: "happiness", happiness: "health") + end.to raise_error(TSort::Cyclic) + end + + it 'is case-insensitive' do + result = with_memory.solve!(total_fruit: "Apples + pears", pears: 10) + expect(result[:total_fruit]).to eq 13 + end + + it "lets you know if a variable is unbound" do + expect { + calculator.solve!(more_apples: "apples + 1") + }.to raise_error(Dentaku::UnboundVariableError) + end + + it 'can reference stored formulas' do + calculator.store_formula("base_area", "length * width") + calculator.store_formula("volume", "base_area * height") + + result = calculator.solve!( + weight: "volume * 5.432", + height: "3", + length: "2", + width: "length * 2", + ) + + expect(result[:weight]).to eq 130.368 + end + end + + describe 'solve' do + it "returns :undefined when variables are unbound" do + expressions = {more_apples: "apples + 1"} + expect(calculator.solve(expressions)).to eq(more_apples: :undefined) + end + + it "allows passing in a custom value to an error handler" do + expressions = {more_apples: "apples + 1"} + expect(calculator.solve(expressions) { :foo }) + .to eq(more_apples: :foo) + end + + it "solves remainder of expressions with unbound variable" do + calculator.store(peaches: 1, oranges: 1) + expressions = { more_apples: "apples + 1", more_peaches: "peaches + 1" } + result = calculator.solve(expressions) + expect(calculator.memory).to eq("peaches" => 1, "oranges" => 1) + expect(result).to eq( + more_apples: :undefined, + more_peaches: 2 + ) + end + + it "solves remainder of expressions when one cannot be evaluated" do + result = calculator.solve( + conditional: "IF(d != 0, ratio, 0)", + ratio: "10/d", + d: 0, + ) + + expect(result).to eq( + conditional: 0, + ratio: :undefined, + d: 0, + ) + end + end + + it 'evaluates a statement with no variables' do + expect(calculator.evaluate('5+3')).to eq(8) + expect(calculator.evaluate('(1+1+1)/3*100')).to eq(100) + end + + it 'fails to evaluate unbound statements' do + unbound = 'foo * 1.5' + expect { calculator.evaluate!(unbound) }.to raise_error(Dentaku::UnboundVariableError) + expect { calculator.evaluate!(unbound) }.to raise_error do |error| + expect(error.unbound_variables).to eq ['foo'] + end + expect(calculator.evaluate(unbound)).to be_nil + expect(calculator.evaluate(unbound) { :bar }).to eq :bar + expect(calculator.evaluate(unbound) { |e| e }).to eq unbound + end + + it 'evaluates unbound statements given a binding in memory' do + expect(calculator.evaluate('foo * 1.5', foo: 2)).to eq(3) + expect(calculator.bind(monkeys: 3).evaluate('monkeys < 7')).to be_truthy + expect(calculator.evaluate('monkeys / 1.5')).to eq(2) + end + + it 'rebinds for each evaluation' do + expect(calculator.evaluate('foo * 2', foo: 2)).to eq(4) + expect(calculator.evaluate('foo * 2', foo: 4)).to eq(8) + end + + it 'accepts strings or symbols for binding keys' do + expect(calculator.evaluate('foo * 2', foo: 2)).to eq(4) + expect(calculator.evaluate('foo * 2', 'foo' => 4)).to eq(8) + end + + it 'accepts digits in identifiers' do + expect(calculator.evaluate('foo1 * 2', foo1: 2)).to eq(4) + expect(calculator.evaluate('foo1 * 2', 'foo1' => 4)).to eq(8) + expect(calculator.evaluate('1foo * 2', '1foo' => 2)).to eq(4) + expect(calculator.evaluate('fo1o * 2', fo1o: 4)).to eq(8) + end + + it 'compares string literals with string variables' do + expect(calculator.evaluate('fruit = "apple"', fruit: 'apple')).to be_truthy + expect(calculator.evaluate('fruit = "apple"', fruit: 'pear')).to be_falsey + end + + it 'performs case-sensitive comparison' do + expect(calculator.evaluate('fruit = "Apple"', fruit: 'apple')).to be_falsey + expect(calculator.evaluate('fruit = "Apple"', fruit: 'Apple')).to be_truthy + end + + it 'allows binding logical values' do + expect(calculator.evaluate('some_boolean AND 7 > 5', some_boolean: true)).to be_truthy + expect(calculator.evaluate('some_boolean AND 7 < 5', some_boolean: true)).to be_falsey + expect(calculator.evaluate('some_boolean AND 7 > 5', some_boolean: false)).to be_falsey + + expect(calculator.evaluate('some_boolean OR 7 > 5', some_boolean: true)).to be_truthy + expect(calculator.evaluate('some_boolean OR 7 < 5', some_boolean: true)).to be_truthy + expect(calculator.evaluate('some_boolean OR 7 < 5', some_boolean: false)).to be_falsey + end + + describe 'functions' do + it 'include IF' do + expect(calculator.evaluate('if(foo < 8, 10, 20)', foo: 2)).to eq(10) + expect(calculator.evaluate('if(foo < 8, 10, 20)', foo: 9)).to eq(20) + expect(calculator.evaluate('if (foo < 8, 10, 20)', foo: 2)).to eq(10) + expect(calculator.evaluate('if (foo < 8, 10, 20)', foo: 9)).to eq(20) + end + + it 'include ROUND' do + expect(calculator.evaluate('round(8.2)')).to eq(8) + expect(calculator.evaluate('round(8.8)')).to eq(9) + expect(calculator.evaluate('round(8.75, 1)')).to eq(BigDecimal.new('8.8')) + + expect(calculator.evaluate('ROUND(apples * 0.93)', { apples: 10 })).to eq(9) + end + + it 'include NOT' do + expect(calculator.evaluate('NOT(some_boolean)', some_boolean: true)).to be_falsey + expect(calculator.evaluate('NOT(some_boolean)', some_boolean: false)).to be_truthy + + expect(calculator.evaluate('NOT(some_boolean) AND 7 > 5', some_boolean: true)).to be_falsey + expect(calculator.evaluate('NOT(some_boolean) OR 7 < 5', some_boolean: false)).to be_truthy + end + + it 'evaluates functions with negative numbers' do + expect(calculator.evaluate('if (-1 < 5, -1, 5)')).to eq(-1) + expect(calculator.evaluate('if (-1 = -1, -1, 5)')).to eq(-1) + expect(calculator.evaluate('round(-1.23, 1)')).to eq(BigDecimal.new('-1.2')) + expect(calculator.evaluate('NOT(some_boolean) AND -1 > 3', some_boolean: true)).to be_falsey + end + + it 'evaluates functions with stored variables' do + calculator.store("multi_color" => true, "number_of_sheets" => 5000, "sheets_per_minute_black" => 2000, "sheets_per_minute_color" => 1000) + result = calculator.evaluate('number_of_sheets / if(multi_color, sheets_per_minute_color, sheets_per_minute_black)') + expect(result).to eq(5) + end + + describe 'roundup' do + it 'should work with one argument' do + expect(calculator.evaluate('roundup(1.234)')).to eq(2) + end + + it 'should accept second precision argument like in Office formula' do + expect(calculator.evaluate('roundup(1.234, 2)')).to eq(1.24) + end + end + + describe 'rounddown' do + it 'should work with one argument' do + expect(calculator.evaluate('rounddown(1.234)')).to eq(1) + end + + it 'should accept second precision argument like in Office formula' do + expect(calculator.evaluate('rounddown(1.234, 2)')).to eq(1.23) + end + end + end + + describe 'explicit NULL' do + it 'can be used in IF statements' do + expect(calculator.evaluate('IF(null, 1, 2)')).to eq(2) + end + + it 'can be used in IF statements when passed in' do + expect(calculator.evaluate('IF(foo, 1, 2)', foo: nil)).to eq(2) + end + + it 'nil values are carried across middle terms' do + results = calculator.solve!( + choice: 'IF(bar, 1, 2)', + bar: 'foo', + foo: nil) + expect(results).to eq( + choice: 2, + bar: nil, + foo: nil + ) + end + + it 'raises errors when used in arithmetic operation' do + expect { + calculator.solve!(more_apples: "apples + 1", apples: nil) + }.to raise_error(Dentaku::ArgumentError) + end + end + + describe 'case statements' do + it 'handles complex then statements' do + formula = <<-FORMULA + CASE fruit + WHEN 'apple' + THEN (1 * quantity) + WHEN 'banana' + THEN (2 * quantity) + END + FORMULA + expect(calculator.evaluate(formula, quantity: 3, fruit: 'apple')).to eq(3) + expect(calculator.evaluate(formula, quantity: 3, fruit: 'banana')).to eq(6) + end + + it 'handles complex when statements' do + formula = <<-FORMULA + CASE number + WHEN (2 * 2) + THEN 1 + WHEN (2 * 3) + THEN 2 + END + FORMULA + expect(calculator.evaluate(formula, number: 4)).to eq(1) + expect(calculator.evaluate(formula, number: 6)).to eq(2) + end + + it 'throws an exception when no match and there is no default value' do + formula = <<-FORMULA + CASE number + WHEN 42 + THEN 1 + END + FORMULA + expect { calculator.evaluate(formula, number: 2) } + .to raise_error("No block matched the switch value '2'") + end + + it 'handles a default else statement' do + formula = <<-FORMULA + CASE fruit + WHEN 'apple' + THEN 1 * quantity + WHEN 'banana' + THEN 2 * quantity + ELSE + 3 * quantity + END + FORMULA + expect(calculator.evaluate(formula, quantity: 1, fruit: 'banana')).to eq(2) + expect(calculator.evaluate(formula, quantity: 1, fruit: 'orange')).to eq(3) + end + + it 'handles nested case statements' do + formula = <<-FORMULA + CASE fruit + WHEN 'apple' + THEN 1 * quantity + WHEN 'banana' + THEN + CASE quantity + WHEN 1 THEN 2 + WHEN 10 THEN + CASE type + WHEN 'organic' THEN 5 + END + END + END + FORMULA + value = calculator.evaluate( + formula, + type: 'organic', + quantity: 10, + fruit: 'banana') + expect(value).to eq(5) + end + end + + describe 'math functions' do + Math.methods(false).each do |method| + it method do + if Math.method(method).arity == 2 + expect(calculator.evaluate("#{method}(1,2)")).to eq Math.send(method, 1, 2) + else + expect(calculator.evaluate("#{method}(1)")).to eq Math.send(method, 1) + end + end + end + end + + describe 'disable_cache' do + before do + allow(Dentaku).to receive(:cache_ast?) { true } + end + + it 'disables the AST cache' do + expect(calculator.disable_cache{ |c| c.cache_ast? }).to be false + end + + it 'calculates normally' do + expect(calculator.disable_cache{ |c| c.evaluate("2 + 2") }).to eq(4) + end + end + + describe 'clear_cache' do + before do + allow(Dentaku).to receive(:cache_ast?) { true } + + calculator.ast("1+1") + calculator.ast("pineapples * 5") + calculator.ast("pi * radius ^ 2") + + def calculator.ast_cache + @ast_cache + end + end + + it 'clears all items from cache' do + expect(calculator.ast_cache.length).to eq 3 + calculator.clear_cache + expect(calculator.ast_cache.keys).to be_empty + end + + it 'clears one item from cache' do + calculator.clear_cache("1+1") + expect(calculator.ast_cache.keys.sort).to eq([ + 'pi * radius ^ 2', + 'pineapples * 5', + ]) + end + + it 'clears items matching regex from cache' do + calculator.clear_cache(/^pi/) + expect(calculator.ast_cache.keys.sort).to eq(['1+1']) + end + end + + describe 'string functions' do + it 'concatenates two strings' do + expect( + calculator.evaluate('CONCAT(s1, s2)', 's1' => 'abc', 's2' => 'def') + ).to eq 'abcdef' + end + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/dentaku_spec.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/dentaku_spec.rb new file mode 100644 index 0000000..3704a7b --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/dentaku_spec.rb @@ -0,0 +1,22 @@ +require 'dentaku' + +describe Dentaku do + it 'evaulates an expression' do + expect(Dentaku('5+3')).to eql(8) + end + + it 'binds values to variables' do + expect(Dentaku('oranges > 7', oranges: 10)).to be_truthy + end + + it 'evaulates a nested function' do + expect(Dentaku('roundup(roundup(3 * cherries) + raspberries)', cherries: 1.5, raspberries: 0.9)).to eql(6) + end + + it 'treats variables as case-insensitive' do + expect(Dentaku('40 + N', 'n' => 2)).to eql(42) + expect(Dentaku('40 + N', 'N' => 2)).to eql(42) + expect(Dentaku('40 + n', 'N' => 2)).to eql(42) + expect(Dentaku('40 + n', 'n' => 2)).to eql(42) + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/exceptions_spec.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/exceptions_spec.rb new file mode 100644 index 0000000..4af3d4a --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/exceptions_spec.rb @@ -0,0 +1,9 @@ +require 'spec_helper' +require 'dentaku/exceptions' + +describe Dentaku::UnboundVariableError do + it 'includes variable name(s) in message' do + exception = described_class.new(['length']) + expect(exception.message).to match /length/ + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/external_function_spec.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/external_function_spec.rb new file mode 100644 index 0000000..3b8797d --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/external_function_spec.rb @@ -0,0 +1,56 @@ +require 'spec_helper' +require 'dentaku/calculator' + +describe Dentaku::Calculator do + describe 'functions' do + describe 'external functions' do + + let(:with_external_funcs) do + c = described_class.new + + c.add_function(:now, :string, -> { Time.now.to_s }) + + fns = [ + [:pow, :numeric, ->(mantissa, exponent) { mantissa ** exponent }], + [:biggest, :numeric, ->(*args) { args.max }], + [:smallest, :numeric, ->(*args) { args.min }], + ] + + c.add_functions(fns) + end + + it 'includes NOW' do + now = with_external_funcs.evaluate('NOW()') + expect(now).not_to be_nil + expect(now).not_to be_empty + end + + it 'includes POW' do + expect(with_external_funcs.evaluate('POW(2,3)')).to eq(8) + expect(with_external_funcs.evaluate('POW(3,2)')).to eq(9) + expect(with_external_funcs.evaluate('POW(mantissa,exponent)', mantissa: 2, exponent: 4)).to eq(16) + end + + it 'includes BIGGEST' do + expect(with_external_funcs.evaluate('BIGGEST(8,6,7,5,3,0,9)')).to eq(9) + end + + it 'includes SMALLEST' do + expect(with_external_funcs.evaluate('SMALLEST(8,6,7,5,3,0,9)')).to eq(0) + end + + it 'supports array parameters' do + calculator = described_class.new + calculator.add_function( + :includes, + :logical, + ->(haystack, needle) { + haystack.include?(needle) + } + ) + + expect(calculator.evaluate("INCLUDES(list, 2)", list: [1,2,3])).to eq(true) + end + end + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/parser_spec.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/parser_spec.rb new file mode 100644 index 0000000..fc567d6 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/parser_spec.rb @@ -0,0 +1,150 @@ +require 'spec_helper' +require 'dentaku/token' +require 'dentaku/parser' + +describe Dentaku::Parser do + it 'is constructed from a token' do + token = Dentaku::Token.new(:numeric, 5) + node = described_class.new([token]).parse + expect(node.value).to eq 5 + end + + it 'performs simple addition' do + five = Dentaku::Token.new(:numeric, 5) + plus = Dentaku::Token.new(:operator, :add) + four = Dentaku::Token.new(:numeric, 4) + + node = described_class.new([five, plus, four]).parse + expect(node.value).to eq 9 + end + + it 'compares two numbers' do + five = Dentaku::Token.new(:numeric, 5) + lt = Dentaku::Token.new(:comparator, :lt) + four = Dentaku::Token.new(:numeric, 4) + + node = described_class.new([five, lt, four]).parse + expect(node.value).to eq false + end + + it 'calculates unary percentage' do + five = Dentaku::Token.new(:numeric, 5) + mod = Dentaku::Token.new(:operator, :mod) + + node = described_class.new([five, mod]).parse + expect(node.value).to eq 0.05 + end + + it 'performs multiple operations in one stream' do + five = Dentaku::Token.new(:numeric, 5) + plus = Dentaku::Token.new(:operator, :add) + four = Dentaku::Token.new(:numeric, 4) + times = Dentaku::Token.new(:operator, :multiply) + three = Dentaku::Token.new(:numeric, 3) + + node = described_class.new([five, plus, four, times, three]).parse + expect(node.value).to eq 17 + end + + it 'respects order of operations' do + five = Dentaku::Token.new(:numeric, 5) + times = Dentaku::Token.new(:operator, :multiply) + four = Dentaku::Token.new(:numeric, 4) + plus = Dentaku::Token.new(:operator, :add) + three = Dentaku::Token.new(:numeric, 3) + + node = described_class.new([five, times, four, plus, three]).parse + expect(node.value).to eq 23 + end + + it 'respects grouping by parenthesis' do + lpar = Dentaku::Token.new(:grouping, :open) + five = Dentaku::Token.new(:numeric, 5) + plus = Dentaku::Token.new(:operator, :add) + four = Dentaku::Token.new(:numeric, 4) + rpar = Dentaku::Token.new(:grouping, :close) + times = Dentaku::Token.new(:operator, :multiply) + three = Dentaku::Token.new(:numeric, 3) + + node = described_class.new([lpar, five, plus, four, rpar, times, three]).parse + expect(node.value).to eq 27 + end + + it 'evaluates functions' do + fn = Dentaku::Token.new(:function, :if) + fopen = Dentaku::Token.new(:grouping, :open) + five = Dentaku::Token.new(:numeric, 5) + lt = Dentaku::Token.new(:comparator, :lt) + four = Dentaku::Token.new(:numeric, 4) + comma = Dentaku::Token.new(:grouping, :comma) + three = Dentaku::Token.new(:numeric, 3) + two = Dentaku::Token.new(:numeric, 2) + rpar = Dentaku::Token.new(:grouping, :close) + + node = described_class.new([fn, fopen, five, lt, four, comma, three, comma, two, rpar]).parse + expect(node.value).to eq 2 + end + + it 'represents formulas with variables' do + five = Dentaku::Token.new(:numeric, 5) + times = Dentaku::Token.new(:operator, :multiply) + x = Dentaku::Token.new(:identifier, :x) + + node = described_class.new([five, times, x]).parse + expect { node.value }.to raise_error(Dentaku::UnboundVariableError) + expect(node.value(x: 3)).to eq 15 + end + + it 'evaluates boolean expressions' do + d_true = Dentaku::Token.new(:logical, true) + d_and = Dentaku::Token.new(:combinator, :and) + d_false = Dentaku::Token.new(:logical, false) + + node = described_class.new([d_true, d_and, d_false]).parse + expect(node.value).to eq false + end + + it 'evaluates a case statement' do + case_start = Dentaku::Token.new(:case, :open) + x = Dentaku::Token.new(:identifier, :x) + case_when1 = Dentaku::Token.new(:case, :when) + one = Dentaku::Token.new(:numeric, 1) + case_then1 = Dentaku::Token.new(:case, :then) + two = Dentaku::Token.new(:numeric, 2) + case_when2 = Dentaku::Token.new(:case, :when) + three = Dentaku::Token.new(:numeric, 3) + case_then2 = Dentaku::Token.new(:case, :then) + four = Dentaku::Token.new(:numeric, 4) + case_close = Dentaku::Token.new(:case, :close) + + node = described_class.new( + [case_start, + x, + case_when1, + one, + case_then1, + two, + case_when2, + three, + case_then2, + four, + case_close]).parse + expect(node.value(x: 3)).to eq(4) + end + + it 'raises an error on parse failure' do + five = Dentaku::Token.new(:numeric, 5) + times = Dentaku::Token.new(:operator, :multiply) + minus = Dentaku::Token.new(:operator, :subtract) + + expect { + described_class.new([five, times, minus]).parse + }.to raise_error(Dentaku::ParseError) + end + + it "evaluates explicit 'NULL' as a Nil" do + null = Dentaku::Token.new(:null, nil) + node = described_class.new([null]).parse + expect(node.value).to eq(nil) + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/spec_helper.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/spec_helper.rb new file mode 100644 index 0000000..90f8f0a --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/spec_helper.rb @@ -0,0 +1,41 @@ +require 'pry' + +# automatically create a token stream from bare values +def token_stream(*args) + args.map do |value| + type = type_for(value) + Dentaku::Token.new(type, value) + end +end + +# make a (hopefully intelligent) guess about type +def type_for(value) + case value + when Numeric + :numeric + when String + :string + when true, false + :logical + when :add, :subtract, :multiply, :divide, :mod, :pow + :operator + when :open, :close, :comma + :grouping + when :le, :ge, :ne, :ne, :lt, :gt, :eq + :comparator + when :and, :or + :combinator + when :if, :round, :roundup, :rounddown, :not + :function + else + :identifier + end +end + +def identifier(name) + Dentaku::AST::Identifier.new(Dentaku::Token.new(:identifier, name)) +end + +def literal(value) + Dentaku::AST::Literal.new(Dentaku::Token.new(type_for(value), value)) +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/token_matcher_spec.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/token_matcher_spec.rb new file mode 100644 index 0000000..cf9f9b6 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/token_matcher_spec.rb @@ -0,0 +1,135 @@ +require 'spec_helper' +require 'dentaku/token_matcher' + +describe Dentaku::TokenMatcher do + it 'with single category matches token category' do + matcher = described_class.new(:numeric) + token = Dentaku::Token.new(:numeric, 5) + + expect(matcher).to eq(token) + end + + it 'with multiple categories matches any included token category' do + matcher = described_class.new([:comparator, :operator]) + numeric = Dentaku::Token.new(:numeric, 5) + comparator = Dentaku::Token.new(:comparator, :lt) + operator = Dentaku::Token.new(:operator, :add) + + expect(matcher).to eq(comparator) + expect(matcher).to eq(operator) + expect(matcher).not_to eq(numeric) + end + + it 'with single category and value matches token category and value' do + matcher = described_class.new(:operator, :add) + addition = Dentaku::Token.new(:operator, :add) + subtraction = Dentaku::Token.new(:operator, :subtract) + + expect(matcher).to eq(addition) + expect(matcher).not_to eq(subtraction) + end + + it 'with multiple values matches any included token value' do + matcher = described_class.new(:operator, [:add, :subtract]) + add = Dentaku::Token.new(:operator, :add) + sub = Dentaku::Token.new(:operator, :subtract) + mul = Dentaku::Token.new(:operator, :multiply) + div = Dentaku::Token.new(:operator, :divide) + + expect(matcher).to eq(add) + expect(matcher).to eq(sub) + expect(matcher).not_to eq(mul) + expect(matcher).not_to eq(div) + end + + it 'is invertible' do + matcher = described_class.new(:operator, [:add, :subtract]).invert + add = Dentaku::Token.new(:operator, :add) + mul = Dentaku::Token.new(:operator, :multiply) + cmp = Dentaku::Token.new(:comparator, :lt) + + expect(matcher).not_to eq(add) + expect(matcher).to eq(mul) + expect(matcher).to eq(cmp) + end + + describe 'combining multiple tokens' do + let(:numeric) { described_class.new(:numeric) } + let(:string) { described_class.new(:string) } + + it 'matches either' do + either = numeric | string + expect(either).to eq(Dentaku::Token.new(:numeric, 5)) + expect(either).to eq(Dentaku::Token.new(:string, 'rhubarb')) + end + + it 'matches any value' do + value = described_class.value + expect(value).to eq(Dentaku::Token.new(:numeric, 8)) + expect(value).to eq(Dentaku::Token.new(:string, 'apricot')) + expect(value).to eq(Dentaku::Token.new(:logical, false)) + expect(value).not_to eq(Dentaku::Token.new(:function, :round)) + expect(value).not_to eq(Dentaku::Token.new(:identifier, :hello)) + end + end + + describe 'stream matching' do + let(:stream) { token_stream(5, 11, 9, 24, :hello, 8) } + + describe 'standard' do + let(:standard) { described_class.new(:numeric) } + + it 'matches zero or more occurrences in a token stream' do + matched, substream = standard.match(stream) + expect(matched).to be_truthy + expect(substream.length).to eq 1 + expect(substream.map(&:value)).to eq [5] + + matched, substream = standard.match(stream, 4) + expect(substream).to be_empty + expect(matched).not_to be_truthy + end + end + + describe 'star' do + let(:star) { described_class.new(:numeric).star } + + it 'matches zero or more occurrences in a token stream' do + matched, substream = star.match(stream) + expect(matched).to be_truthy + expect(substream.length).to eq 4 + expect(substream.map(&:value)).to eq [5, 11, 9, 24] + + matched, substream = star.match(stream, 4) + expect(substream).to be_empty + expect(matched).to be_truthy + end + end + + describe 'plus' do + let(:plus) { described_class.new(:numeric).plus } + + it 'matches one or more occurrences in a token stream' do + matched, substream = plus.match(stream) + expect(matched).to be_truthy + expect(substream.length).to eq 4 + expect(substream.map(&:value)).to eq [5, 11, 9, 24] + + matched, substream = plus.match(stream, 4) + expect(substream).to be_empty + expect(matched).not_to be_truthy + end + end + + describe 'arguments' do + it 'matches comma-separated values' do + stream = token_stream(1, :comma, 2, :comma, true, :comma, 'olive', :comma, :'(') + matched, substream = described_class.arguments.match(stream) + expect(matched).to be_truthy + expect(substream.length).to eq 8 + expect(substream.map(&:value)).to eq [1, :comma, 2, :comma, true, :comma, 'olive', :comma] + end + end + end +end + diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/token_scanner_spec.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/token_scanner_spec.rb new file mode 100644 index 0000000..27b51db --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/token_scanner_spec.rb @@ -0,0 +1,53 @@ +require 'dentaku/token_scanner' + +describe Dentaku::TokenScanner do + let(:whitespace) { described_class.new(:whitespace, '\s') } + let(:numeric) { described_class.new(:numeric, '(\d+(\.\d+)?|\.\d+)', + ->(raw) { raw =~ /\./ ? BigDecimal.new(raw) : raw.to_i }) + } + let(:custom) { described_class.new(:identifier, '#\w+\b', + ->(raw) { raw.gsub('#', '').to_sym }) + } + + after { described_class.register_default_scanners } + + it 'returns a token for a matching string' do + token = whitespace.scan(' ').first + expect(token.category).to eq(:whitespace) + expect(token.value).to eq(' ') + end + + it 'returns falsy for a non-matching string' do + expect(whitespace.scan('A')).not_to be + end + + it 'performs raw value conversion' do + token = numeric.scan('5').first + expect(token.category).to eq(:numeric) + expect(token.value).to eq(5) + end + + it 'returns a list of all configured scanners' do + expect(described_class.scanners.length).to eq 14 + end + + it 'allows customizing available scanners' do + described_class.scanners = [:whitespace, :numeric] + expect(described_class.scanners.length).to eq 2 + end + + it 'ignores invalid scanners' do + described_class.scanners = [:whitespace, :numeric, :fake] + expect(described_class.scanners.length).to eq 2 + end + + it 'uses a custom scanner' do + described_class.scanners = [:whitespace, :numeric] + described_class.register_scanner(:custom, custom) + expect(described_class.scanners.length).to eq 3 + + token = custom.scan('#apple + #pear').first + expect(token.category).to eq(:identifier) + expect(token.value).to eq(:apple) + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/token_spec.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/token_spec.rb new file mode 100644 index 0000000..01e385c --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/token_spec.rb @@ -0,0 +1,10 @@ +require 'dentaku/token' + +describe Dentaku::Token do + it 'has a category and a value' do + token = Dentaku::Token.new(:numeric, 5) + expect(token.category).to eq(:numeric) + expect(token.value).to eq(5) + expect(token.is?(:numeric)).to be_truthy + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/tokenizer_spec.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/tokenizer_spec.rb new file mode 100644 index 0000000..315bbc1 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/tokenizer_spec.rb @@ -0,0 +1,212 @@ +require 'dentaku/tokenizer' + +describe Dentaku::Tokenizer do + let(:tokenizer) { described_class.new } + + it 'handles an empty expression' do + expect(tokenizer.tokenize('')).to be_empty + end + + it 'tokenizes addition' do + tokens = tokenizer.tokenize('1+1') + expect(tokens.map(&:category)).to eq([:numeric, :operator, :numeric]) + expect(tokens.map(&:value)).to eq([1, :add, 1]) + end + + it 'tokenizes unary minus' do + tokens = tokenizer.tokenize('-5') + expect(tokens.map(&:category)).to eq([:operator, :numeric]) + expect(tokens.map(&:value)).to eq([:negate, 5]) + + tokens = tokenizer.tokenize('(-5)') + expect(tokens.map(&:category)).to eq([:grouping, :operator, :numeric, :grouping]) + expect(tokens.map(&:value)).to eq([:open, :negate, 5, :close]) + + tokens = tokenizer.tokenize('if(-5 > x, -7, -8) - 9') + expect(tokens.map(&:category)).to eq([ + :function, :grouping, # if( + :operator, :numeric, :comparator, :identifier, :grouping, # -5 > x, + :operator, :numeric, :grouping, # -7, + :operator, :numeric, :grouping, # -8) + :operator, :numeric # - 9 + ]) + expect(tokens.map(&:value)).to eq([ + :if, :open, # if( + :negate, 5, :gt, 'x', :comma, # -5 > x, + :negate, 7, :comma, # -7, + :negate, 8, :close, # -8) + :subtract, 9 # - 9 + ]) + end + + it 'tokenizes comparison with =' do + tokens = tokenizer.tokenize('number = 5') + expect(tokens.map(&:category)).to eq([:identifier, :comparator, :numeric]) + expect(tokens.map(&:value)).to eq(['number', :eq, 5]) + end + + it 'tokenizes comparison with =' do + tokens = tokenizer.tokenize('number = 5') + expect(tokens.map(&:category)).to eq([:identifier, :comparator, :numeric]) + expect(tokens.map(&:value)).to eq(['number', :eq, 5]) + end + + it 'tokenizes comparison with alternate ==' do + tokens = tokenizer.tokenize('number == 5') + expect(tokens.map(&:category)).to eq([:identifier, :comparator, :numeric]) + expect(tokens.map(&:value)).to eq(['number', :eq, 5]) + end + + it 'ignores whitespace' do + tokens = tokenizer.tokenize('1 / 1 ') + expect(tokens.map(&:category)).to eq([:numeric, :operator, :numeric]) + expect(tokens.map(&:value)).to eq([1, :divide, 1]) + end + + it 'tokenizes power operations' do + tokens = tokenizer.tokenize('10 ^ 2') + expect(tokens.map(&:category)).to eq([:numeric, :operator, :numeric]) + expect(tokens.map(&:value)).to eq([10, :pow, 2]) + end + + it 'tokenizes power operations' do + tokens = tokenizer.tokenize('0 * 10 ^ -5') + expect(tokens.map(&:category)).to eq([:numeric, :operator, :numeric, :operator, :operator, :numeric]) + expect(tokens.map(&:value)).to eq([0, :multiply, 10, :pow, :negate, 5]) + end + + it 'handles floating point' do + tokens = tokenizer.tokenize('1.5 * 3.7') + expect(tokens.map(&:category)).to eq([:numeric, :operator, :numeric]) + expect(tokens.map(&:value)).to eq([1.5, :multiply, 3.7]) + end + + it 'does not require leading zero' do + tokens = tokenizer.tokenize('.5 * 3.7') + expect(tokens.map(&:category)).to eq([:numeric, :operator, :numeric]) + expect(tokens.map(&:value)).to eq([0.5, :multiply, 3.7]) + end + + it 'accepts arbitrary identifiers' do + tokens = tokenizer.tokenize('sea_monkeys > 1500') + expect(tokens.map(&:category)).to eq([:identifier, :comparator, :numeric]) + expect(tokens.map(&:value)).to eq(['sea_monkeys', :gt, 1500]) + end + + it 'recognizes double-quoted strings' do + tokens = tokenizer.tokenize('animal = "giraffe"') + expect(tokens.map(&:category)).to eq([:identifier, :comparator, :string]) + expect(tokens.map(&:value)).to eq(['animal', :eq, 'giraffe']) + end + + it 'recognizes single-quoted strings' do + tokens = tokenizer.tokenize("animal = 'giraffe'") + expect(tokens.map(&:category)).to eq([:identifier, :comparator, :string]) + expect(tokens.map(&:value)).to eq(['animal', :eq, 'giraffe']) + end + + it 'recognizes binary minus operator' do + tokens = tokenizer.tokenize('2 - 3') + expect(tokens.map(&:category)).to eq([:numeric, :operator, :numeric]) + expect(tokens.map(&:value)).to eq([2, :subtract, 3]) + end + + it 'recognizes unary minus operator' do + tokens = tokenizer.tokenize('-2 + 3') + expect(tokens.map(&:category)).to eq([:operator, :numeric, :operator, :numeric]) + expect(tokens.map(&:value)).to eq([:negate, 2, :add, 3]) + end + + it 'recognizes unary minus operator' do + tokens = tokenizer.tokenize('2 - -3') + expect(tokens.map(&:category)).to eq([:numeric, :operator, :operator, :numeric]) + expect(tokens.map(&:value)).to eq([2, :subtract, :negate, 3]) + end + + it 'matches "<=" before "<"' do + tokens = tokenizer.tokenize('perimeter <= 7500') + expect(tokens.map(&:category)).to eq([:identifier, :comparator, :numeric]) + expect(tokens.map(&:value)).to eq(['perimeter', :le, 7500]) + end + + it 'matches "and" for logical expressions' do + tokens = tokenizer.tokenize('octopi <= 7500 AND sharks > 1500') + expect(tokens.map(&:category)).to eq([:identifier, :comparator, :numeric, :combinator, :identifier, :comparator, :numeric]) + expect(tokens.map(&:value)).to eq(['octopi', :le, 7500, :and, 'sharks', :gt, 1500]) + end + + it 'matches "or" for logical expressions' do + tokens = tokenizer.tokenize('size < 3 or admin = 1') + expect(tokens.map(&:category)).to eq([:identifier, :comparator, :numeric, :combinator, :identifier, :comparator, :numeric]) + expect(tokens.map(&:value)).to eq(['size', :lt, 3, :or, 'admin', :eq, 1]) + end + + it 'detects unbalanced parentheses' do + expect { tokenizer.tokenize('(5+3') }.to raise_error(Dentaku::TokenizerError, /too many opening parentheses/) + expect { tokenizer.tokenize(')') }.to raise_error(Dentaku::TokenizerError, /too many closing parentheses/) + end + + it 'recognizes identifiers that share initial substrings with combinators' do + tokens = tokenizer.tokenize('andover < 10') + expect(tokens.length).to eq(3) + expect(tokens.map(&:category)).to eq([:identifier, :comparator, :numeric]) + expect(tokens.map(&:value)).to eq(['andover', :lt, 10]) + end + + it 'tokenizes TRUE and FALSE literals' do + tokens = tokenizer.tokenize('true and false') + expect(tokens.length).to eq(3) + expect(tokens.map(&:category)).to eq([:logical, :combinator, :logical]) + expect(tokens.map(&:value)).to eq([true, :and, false]) + + tokens = tokenizer.tokenize('true_lies and falsehoods') + expect(tokens.length).to eq(3) + expect(tokens.map(&:category)).to eq([:identifier, :combinator, :identifier]) + expect(tokens.map(&:value)).to eq(['true_lies', :and, 'falsehoods']) + end + + describe 'functions' do + it 'include IF' do + tokens = tokenizer.tokenize('if(x < 10, y, z)') + expect(tokens.length).to eq(10) + expect(tokens.map(&:category)).to eq([:function, :grouping, :identifier, :comparator, :numeric, :grouping, :identifier, :grouping, :identifier, :grouping]) + expect(tokens.map(&:value)).to eq([:if, :open, 'x', :lt, 10, :comma, 'y', :comma, 'z', :close]) + end + + it 'include ROUND/UP/DOWN' do + tokens = tokenizer.tokenize('round(8.2)') + expect(tokens.length).to eq(4) + expect(tokens.map(&:category)).to eq([:function, :grouping, :numeric, :grouping]) + expect(tokens.map(&:value)).to eq([:round, :open, BigDecimal.new('8.2'), :close]) + + tokens = tokenizer.tokenize('round(8.75, 1)') + expect(tokens.length).to eq(6) + expect(tokens.map(&:category)).to eq([:function, :grouping, :numeric, :grouping, :numeric, :grouping]) + expect(tokens.map(&:value)).to eq([:round, :open, BigDecimal.new('8.75'), :comma, 1, :close]) + + tokens = tokenizer.tokenize('ROUNDUP(8.2)') + expect(tokens.length).to eq(4) + expect(tokens.map(&:category)).to eq([:function, :grouping, :numeric, :grouping]) + expect(tokens.map(&:value)).to eq([:roundup, :open, BigDecimal.new('8.2'), :close]) + + tokens = tokenizer.tokenize('RoundDown(8.2)') + expect(tokens.length).to eq(4) + expect(tokens.map(&:category)).to eq([:function, :grouping, :numeric, :grouping]) + expect(tokens.map(&:value)).to eq([:rounddown, :open, BigDecimal.new('8.2'), :close]) + end + + it 'include NOT' do + tokens = tokenizer.tokenize('not(8 < 5)') + expect(tokens.length).to eq(6) + expect(tokens.map(&:category)).to eq([:function, :grouping, :numeric, :comparator, :numeric, :grouping]) + expect(tokens.map(&:value)).to eq([:not, :open, 8, :lt, 5, :close]) + end + + it 'handles whitespace after function name' do + tokens = tokenizer.tokenize('not (8 < 5)') + expect(tokens.length).to eq(6) + expect(tokens.map(&:category)).to eq([:function, :grouping, :numeric, :comparator, :numeric, :grouping]) + expect(tokens.map(&:value)).to eq([:not, :open, 8, :lt, 5, :close]) + end + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/.gitignore b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/.gitignore new file mode 100644 index 0000000..864ca44 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/.gitignore @@ -0,0 +1,23 @@ +*.gem +*.rbc +.bundle +.config +coverage +InstalledFiles +lib/bundler/man +pkg +rdoc +spec/reports +test/tmp +test/version_tmp +tmp +Gemfile.lock +.rvmrc +.ruby-version +.ruby-gemset + +# YARD artifacts +.yardoc +_yardoc +doc/ +*.local diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/.rubocop.yml b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/.rubocop.yml new file mode 100644 index 0000000..f808b97 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/.rubocop.yml @@ -0,0 +1,35 @@ +AllCops: + Include: + - 'Rakefile' + - '*.gemspec' + - 'lib/**/*.rb' + - 'spec/**/*.rb' + Exclude: + - 'bin/**/*' + - 'smoke/**/*' + DisplayCopNames: true + StyleGuideCopsOnly: false + +Rails: + Enabled: false + +Style/FrozenStringLiteralComment: + Enabled: false + +Style/NumericPredicate: + Enabled: false + +Style/StringLiterals: + Enabled: false + +Style/RescueModifier: + Enabled: false + +Metrics/LineLength: + Max: 100 + Exclude: + - 'spec/**/*.rb' + +Metrics/ModuleLength: + CountComments: false # count full line comments? + Max: 120 diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/.travis.yml b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/.travis.yml new file mode 100644 index 0000000..ca87afc --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/.travis.yml @@ -0,0 +1,52 @@ +sudo: required +dist: trusty +language: ruby +before_install: + - gem install bundler + - gem update bundler + - smoke/provision.sh +rvm: + - 1.9.3 + - 2.0.0 + - 2.1.10 + - 2.2.4 + - 2.3.1 + - ruby-head +env: + - TEST_TASK=spec + +matrix: + allow_failures: + - rvm: jruby-head + - rvm: ruby-head + - rvm: jruby-9.0.5.0 + - rvm: 2.3.1 + env: TEST_TASK=smoke influx_version=nightly channel=nightlies + include: + - rvm: 2.3.1 + env: TEST_TASK=rubocop + - rvm: jruby-9.0.5.0 + env: JRUBY_OPTS='--client -J-XX:+TieredCompilation -J-XX:TieredStopAtLevel=1 -J-Xss2m -J-Xmx256M' + - rvm: jruby-head + env: JRUBY_OPTS='--client -J-XX:+TieredCompilation -J-XX:TieredStopAtLevel=1 -J-Xss2m -J-Xmx256M' + - rvm: 2.3.1 + env: TEST_TASK=smoke influx_version=0.10.3-1 pkghash=96244557d9bb7485ddc9d084ff7ce783 + - rvm: 2.3.1 + env: TEST_TASK=smoke influx_version=0.11.1-1 pkghash=f4cf8363125038dff038ced6b16bcafd + - rvm: 2.3.1 + env: TEST_TASK=smoke influx_version=0.12.2-1 pkghash=f28bb1c57d52dc1593dca45b86be5913 + - rvm: 2.3.1 + env: TEST_TASK=smoke influx_version=0.13.0 pkghash=4f0aa76fee22cf4c18e2a0779ba4f462 + - rvm: 2.3.1 + env: TEST_TASK=smoke influx_version=1.0.2 pkghash=3e4c349cb57507913d9abda1459bdbed + - rvm: 2.3.1 + env: TEST_TASK=smoke influx_version=1.1.0 pkghash=682904c350ecfc2a60ec9c6c08453ef2 + - rvm: 2.3.1 + env: TEST_TASK=smoke influx_version=nightly channel=nightlies + fail_fast: true +addons: + apt: + packages: + - haveged + - libgmp-dev +script: bundle exec rake $TEST_TASK diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/CHANGELOG.md b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/CHANGELOG.md new file mode 100644 index 0000000..7714956 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/CHANGELOG.md @@ -0,0 +1,125 @@ +# Changelog + +For the full commit log, [see here](https://github.com/influxdata/influxdb-ruby/commits/master). + +## Unreleased changes + +- None. + +## v0.3.13, released 2016-11-23 + +- You can now `InfluxDB::Client#query`, `#write_points`, `#write_point` and + `#write` now accept an additional parameter to override the database on + invokation time (#173, #176, @jfragoulis). + + +## v0.3.12, released 2016-11-15 + +- Bugfix for broken Unicode support (regression introduced in #169). + Please note, this is only properly tested on Ruby 2.1+ (#171). + +## v0.3.11, released 2016-10-12 + +- Bugfix/Enhancement in `PointValue#escape`. Input strings are now scrubbed + of invalid UTF byte sequences (#169, @ton31337). + +## v0.3.10, released 2016-10-03 + +- Bugfix in `Query::Builder#quote` (#168, @cthulhu666). + +## v0.3.9, released 2016-09-20 + +- Changed retry behaviour slightly. When the server responds with an incomplete + response, we now assume a major server-side problem (insufficient resources, + e.g. out-of-memory) and cancel any retry attempts (#165, #166). + +## v0.3.8, released 2016-08-31 + +- Added support for named and positional query parameters (#160, @retorquere). + +## v0.3.7, released 2016-08-14 + +- Fixed `prefix` handling for `#ping` and `#version` (#157, @dimiii). + +## v0.3.6, released 2016-07-24 + +- Added feature for JSON streaming response, via `"chunk_size"` parameter + (#155, @mhodson-qxbranch). + +## v0.3.5, released 2016-06-09 + +- Reintroduced full dependency on "cause" (for Ruby 1.9 compat). +- Extended `Client#create_database` and `#delete_database` to fallback on `config.database` (#153, #154, @anthonator). + +## v0.3.4, released 2016-06-07 + +- Added resample options to `Client#create_continuous_query` (#149). +- Fixed resample options to be Ruby 1.9 compatible (#150, @SebastianCoetzee). +- Mentioned in README, that 0.3.x series is the last one to support Ruby 1.9. + +## v0.3.3, released 2016-06-06 (yanked) + +- Added resample options to `Client#create_continuous_query` (#149). + +## v0.3.2, released 2016-06-02 + +- Added config option to authenticate without credentials (#146, @pmenglund). + +## v0.3.1, released 2016-05-26 + +- Fixed #130 (again). Integer values are now really written as Integers to InfluxDB. + +## v0.3.0, released 2016-04-24 + +- Write queries are now checked against 204 No Content responses, in accordance with the official documentation (#128). +- Async options are now configurabe (#107). + +## v0.2.6, released 2016-04-14 + +- Empty tag keys/values are now omitted (#124). + +## v0.2.5, released 2016-04-14 + +- Async writer now behaves when stopping the client (#73). +- Update development dependencies and started enforcing Rubocop styles. + +## v0.2.4, released 2016-04-12 + +- Added `InfluxDB::Client#version`, returning the server version (#117). +- Fixed escaping issues (#119, #121, #135). +- Integer values are now written as Integer, not as Float value (#131). +- Return all result series when querying multiple selects (#134). +- Made host cycling thread safe (#136). + +## v0.2.3, released 2015-10-27 + +- Added `epoch` option to client constructor and write methods (#104). +- Added `#list_user_grants` (#111), `#grant_user_admin_privileges` (#112) and `#alter_retention_policy` (#114) methods. + +## v0.2.2, released 2015-07-29 + +- Fixed issues with Async client (#101) +- Avoid usage of `gsub!` (#102) + +## v0.2.1, released 2015-07-25 + +- Fix double quote tags escaping (#98) + +## v0.2.0, released 2015-07-20 + +- Large library refactoring (#88, #90) + - Extract config from client + - Extract HTTP functionality to separate module + - Extract InfluxDB management functions to separate modules + - Add writer concept + - Refactor specs (add cases) + - Add 'denormalize' option to config + - Recognize SeriesNotFound error + - Update README + - Add Rubocop config + - Break support for Ruby < 2 +- Added support for InfluxDB 0.9+ (#92) + +## v0.1.9, released 2015-07-04 + +- last version to support InfluxDB 0.8.x diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/Gemfile b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/Gemfile new file mode 100644 index 0000000..8ec2bb9 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/Gemfile @@ -0,0 +1,14 @@ +source "https://rubygems.org" + +if RUBY_ENGINE != "jruby" && RUBY_VERSION < "2.0" + gem "json", "~> 1.8.3" + gem "public_suffix", "< 1.5" +end + +gemspec + +local_gemfile = 'Gemfile.local' + +if File.exist?(local_gemfile) + eval(File.read(local_gemfile)) # rubocop:disable Lint/Eval +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/LICENSE.txt b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/LICENSE.txt new file mode 100644 index 0000000..7c471a7 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/LICENSE.txt @@ -0,0 +1,22 @@ +Copyright (c) 2013 Todd Persen + +MIT License + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/README.md b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/README.md new file mode 100644 index 0000000..9ed858f --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/README.md @@ -0,0 +1,687 @@ +# influxdb-ruby + +[![Build Status](https://travis-ci.org/influxdata/influxdb-ruby.svg?branch=master)](https://travis-ci.org/influxdata/influxdb-ruby) + +The official Ruby client library for [InfluxDB](https://influxdata.com/time-series-platform/influxdb/). +Maintained by [@toddboom](https://github.com/toddboom) and [@dmke](https://github.com/dmke). + +## Contents + +- [Platform support](#platform-support) +- [Ruby support](#ruby-support) +- [Installation](#installation) +- [Usage](#usage) + - [Creating a client](#creating-a-client) + - [Administrative tasks](#administrative-tasks) + - [Continuous queries](#continuous-queries) + - [Retention policies](#retention-policies) + - [Writing data](#writing-data) + - [Reading data](#reading-data) + - [Querying](#querying) + - [De-normalization](#de--normalization) + - [Streaming response](#streaming-response) + - [Retry](#retry) + - [Testing](#testing) + - [Contributing](#contributing) + +## Platform support + +> **Support for InfluxDB v0.8.x is now deprecated**. The final version of this +> library that will support the older InfluxDB interface is `v0.1.9`, which is +> available as a gem and tagged on this repository. +> +> If you're reading this message, then you should only expect support for +> InfluxDB v0.9.1 and higher. + +## Ruby support + +This gem should work with Ruby 1.9+, but starting with v0.4, we'll likely drop +Ruby 1.9 support. + +Please note that for Ruby 1.9, you'll need to install the JSON gem in version +1.8.x yourself, for example by pinning the version in your `Gemfile` (i.e. +`gem "json", "~> 1.8.3"`). + +## Installation + +``` +$ [sudo] gem install influxdb +``` + +Or add it to your `Gemfile`, and run `bundle install`. + +## Usage + +### Creating a client + +Connecting to a single host: + +``` ruby +require 'influxdb' + +influxdb = InfluxDB::Client.new host: "influxdb.domain.com" +# or +influxdb = InfluxDB::Client.new # no host given defaults connecting to localhost +``` + +Connecting to multiple hosts (with built-in load balancing and failover): + +``` ruby +require 'influxdb' + +influxdb = InfluxDB::Client.new hosts: ["influxdb1.domain.com", "influxdb2.domain.com"] +``` + +### Administrative tasks + +Create a database: + +``` ruby +database = 'site_development' + +influxdb.create_database(database) +``` + +Delete a database: + +``` ruby +database = 'site_development' + +influxdb.delete_database(database) +``` + +List databases: + +``` ruby +influxdb.list_databases +``` + +Create a user for a database: + +``` ruby +database = 'site_development' +new_username = 'foo' +new_password = 'bar' +permission = :write + +# with all permissions +influxdb.create_database_user(database, new_username, new_password) + +# with specified permission - options are: :read, :write, :all +influxdb.create_database_user(database, new_username, new_password, permissions: permission) +``` + +Update a user password: + +``` ruby +username = 'foo' +new_password = 'bar' + +influxdb.update_user_password(username, new_password) +``` + +Grant user privileges on database: + +``` ruby +username = 'foobar' +database = 'foo' +permission = :read # options are :read, :write, :all + +influxdb.grant_user_privileges(username, database, permission) +``` + +Revoke user privileges from database: + +``` ruby +username = 'foobar' +database = 'foo' +permission = :write # options are :read, :write, :all + +influxdb.revoke_user_privileges(username, database, permission) +``` +Delete a user: + +``` ruby +username = 'foobar' + +influxdb.delete_user(username) +``` + +List users: + +``` ruby +influxdb.list_users +``` + +Create cluster admin: + +``` ruby +username = 'foobar' +password = 'pwd' + +influxdb.create_cluster_admin(username, password) +``` + +List cluster admins: + +``` ruby +influxdb.list_cluster_admins +``` + +Revoke cluster admin privileges from user: + +``` ruby +username = 'foobar' + +influxdb.revoke_cluster_admin_privileges(username) +``` + +### Continuous Queries + +List continuous queries of a database: + +``` ruby +database = 'foo' + +influxdb.list_continuous_queries(database) +``` + +Create a continuous query for a database: + +``` ruby +database = 'foo' +name = 'clicks_count' +query = 'SELECT COUNT(name) INTO clicksCount_1h FROM clicks GROUP BY time(1h)' + +influxdb.create_continuous_query(name, database, query) +``` + +Additionally, you can specify the resample interval and the time range over +which the CQ runs: + +``` ruby +influxdb.create_continuous_query(name, database, query, resample_every: "10m", resample_for: "65m") +``` + +Delete a continuous query from a database: + +``` ruby +database = 'foo' +name = 'clicks_count' + +influxdb.delete_continuous_query(name, database) +``` + +### Retention Policies + +List retention policies of a database: + +``` ruby +database = 'foo' + +influxdb.list_retention_policies(database) +``` + +Create a retention policy for a database: + +``` ruby +database = 'foo' +name = '1h.cpu' +duration = '10m' +replication = 2 + +influxdb.create_retention_policy(name, database, duration, replication) +``` + +Delete a retention policy from a database: + +``` ruby +database = 'foo' +name = '1h.cpu' + +influxdb.delete_retention_policy(name, database) +``` + +Alter a retention policy for a database: + +``` ruby +database = 'foo' +name = '1h.cpu' +duration = '10m' +replication = 2 + +influxdb.alter_retention_policy(name, database, duration, replication) +``` + +### Writing data + +Write some data: + +``` ruby +username = 'foo' +password = 'bar' +database = 'site_development' +name = 'foobar' + +influxdb = InfluxDB::Client.new database, username: username, password: password + +# Enumerator that emits a sine wave +Value = (0..360).to_a.map {|i| Math.send(:sin, i / 10.0) * 10 }.each + +loop do + data = { + values: { value: Value.next }, + tags: { wave: 'sine' } # tags are optional + } + + influxdb.write_point(name, data) + + sleep 1 +end +``` + +Write data with time precision (precision can be set in 2 ways): + +``` ruby +require 'influxdb' + +username = 'foo' +password = 'bar' +database = 'site_development' +name = 'foobar' +time_precision = 's' + +# either in the client initialization: +influxdb = InfluxDB::Client.new database, + username: username, + password: password, + time_precision: time_precision + +data = { + values: { value: 0 }, + timestamp: Time.now.to_i # timestamp is optional, if not provided point will be saved with current time +} + +influxdb.write_point(name, data) + +# or in a method call: +influxdb.write_point(name, data, time_precision) + +``` + +Write data with a specific retention policy: + +``` ruby +require 'influxdb' + +username = 'foo' +password = 'bar' +database = 'site_development' +name = 'foobar' +precision = 's' +retention = '1h.cpu' + +influxdb = InfluxDB::Client.new database, + username: username, + password: password + +data = { + values: { value: 0 }, + tags: { foo: 'bar', bar: 'baz' } + timestamp: Time.now.to_i +} + +influxdb.write_point(name, data, precision, retention) +``` + +Write data while choosing the database: + +``` ruby +require 'influxdb' + +username = 'foo' +password = 'bar' +database = 'site_development' +name = 'foobar' +precision = 's' +retention = '1h.cpu' + +influxdb = InfluxDB::Client.new { + username: username, + password: password +} + +data = { + values: { value: 0 }, + tags: { foo: 'bar', bar: 'baz' } + timestamp: Time.now.to_i +} + +influxdb.write_point(name, data, precision, retention, database) +``` + +Write multiple points in a batch (performance boost): + +``` ruby + +data = [ + { + series: 'cpu', + tags: { host: 'server_1', region: 'us' }, + values: { internal: 5, external: 0.453345 } + }, + { + series: 'gpu', + values: { value: 0.9999 }, + } +] + +influxdb.write_points(data) + +# you can also specify precision in method call + +precision = 'm' +influxdb.write_points(data, precision) +``` + +Write multiple points in a batch with a specific retention policy: + +``` ruby +data = [ + { + series: 'cpu', + tags: { host: 'server_1', region: 'us' }, + values: { internal: 5, external: 0.453345 } + }, + { + series: 'gpu', + values: { value: 0.9999 }, + } +] + +precision = 'm' +retention = '1h.cpu' +influxdb.write_points(data, precision, retention) + +``` + +Write asynchronously (note that a retention policy cannot be specified for asynchronous writes): + +``` ruby +require 'influxdb' + +username = 'foo' +password = 'bar' +database = 'site_development' +name = 'foobar' + +influxdb = InfluxDB::Client.new database, + username: username, + password: password, + async: true + +data = { + values: { value: 0 }, + tags: { foo: 'bar', bar: 'baz' }, + timestamp: Time.now.to_i +} + +influxdb.write_point(name, data) +``` + +Using `async: true` is a shortcut for the following: + +``` ruby +async_options = { + # number of points to write to the server at once + max_post_points: 1000, + # queue capacity + max_queue_size: 10_000, + # number of threads + num_worker_threads: 3, + # max. time (in seconds) a thread sleeps before + # checking if there are new jobs in the queue + sleep_interval: 5 +} + +influxdb = InfluxDB::Client.new database, + username: username, + password: password, + async: async_options +``` + + +Write data via UDP (note that a retention policy cannot be specified for UDP writes): + +``` ruby +require 'influxdb' +host = '127.0.0.1' +port = 4444 + +influxdb = InfluxDB::Client.new udp: { host: host, port: port } + +name = 'hitchhiker' + +data = { + values: { value: 666 }, + tags: { foo: 'bar', bar: 'baz' } +} + +influxdb.write_point(name, data) +``` + +### Reading data + +#### Querying + +``` ruby +username = 'foo' +password = 'bar' +database = 'site_development' + +influxdb = InfluxDB::Client.new database, + username: username, + password: password + +# without a block: +influxdb.query 'select * from time_series_1 group by region' + +# results are grouped by name, but also their tags: +# +# [ +# { +# "name"=>"time_series_1", +# "tags"=>{"region"=>"uk"}, +# "values"=>[ +# {"time"=>"2015-07-09T09:03:31Z", "count"=>32, "value"=>0.9673}, +# {"time"=>"2015-07-09T09:03:49Z", "count"=>122, "value"=>0.4444} +# ] +# }, +# { +# "name"=>"time_series_1", +# "tags"=>{"region"=>"us"}, +# "values"=>[ +# {"time"=>"2015-07-09T09:02:54Z", "count"=>55, "value"=>0.4343} +# ] +# } +# ] + +# with a block: +influxdb.query 'select * from time_series_1 group by region' do |name, tags, points| + puts "#{name} [ #{tags.inspect} ]" + points.each do |pt| + puts " -> #{pt.inspect}" + end +end + +# result: +# time_series_1 [ {"region"=>"uk"} ] +# -> {"time"=>"2015-07-09T09:03:31Z", "count"=>32, "value"=>0.9673} +# -> {"time"=>"2015-07-09T09:03:49Z", "count"=>122, "value"=>0.4444}] +# time_series_1 [ {"region"=>"us"} ] +# -> {"time"=>"2015-07-09T09:02:54Z", "count"=>55, "value"=>0.4343} +``` + +If you would rather receive points with integer timestamp, it's possible to set +`epoch` parameter: + +``` ruby +# globally, on client initialization: +influxdb = InfluxDB::Client.new database, epoch: 's' + +influxdb.query 'select * from time_series group by region' +# [ +# { +# "name"=>"time_series", +# "tags"=>{"region"=>"uk"}, +# "values"=>[ +# {"time"=>1438411376, "count"=>32, "value"=>0.9673} +# ] +# } +# ] + +# or for a specific query call: +influxdb.query 'select * from time_series group by region', epoch: 'ms' +# [ +# { +# "name"=>"time_series", +# "tags"=>{"region"=>"uk"}, +# "values"=>[ +# {"time"=>1438411376000, "count"=>32, "value"=>0.9673} +# ] +# } +# ] +``` + +Working with parameterized query strings works as expected: + +``` ruby +influxdb = InfluxDB::Client.new database + +named_parameter_query = "select * from time_series_0 where time > %{min_time}" +influxdb.query named_parameter_query, params: { min_time: 0 } +# compiles to: +# select * from time_series_0 where time > 0 + +positional_params_query = "select * from time_series_0 where f = %{1} and i < %{2}" +influxdb.query positional_params_query, params: ["foobar", 42] +# compiles to (note the automatic escaping): +# select * from time_series_0 where f = 'foobar' and i < 42 +``` + + +#### (De-) Normalization + +By default, InfluxDB::Client will denormalize points (received from InfluxDB as +columns and rows). If you want to get *raw* data add `denormalize: false` to +the initialization options or to query itself: + +``` ruby +influxdb.query 'select * from time_series_1 group by region', denormalize: false + +# [ +# { +# "name"=>"time_series_1", +# "tags"=>{"region"=>"uk"}, +# "columns"=>["time", "count", "value"], +# "values"=>[ +# ["2015-07-09T09:03:31Z", 32, 0.9673], +# ["2015-07-09T09:03:49Z", 122, 0.4444] +# ] +# }, +# { +# "name"=>"time_series_1", +# "tags"=>{"region"=>"us"}, +# "columns"=>["time", "count", "value"], +# "values"=>[ +# ["2015-07-09T09:02:54Z", 55, 0.4343] +# ] +# } +# ] + + +influxdb.query 'select * from time_series_1 group by region', denormalize: false do |name, tags, points| + puts "#{name} [ #{tags.inspect} ]" + points.each do |key, values| + puts " #{key.inspect} -> #{values.inspect}" + end +end + + +# time_series_1 [ {"region"=>"uk"} ] +# columns -> ["time", "count", "value"] +# values -> [["2015-07-09T09:03:31Z", 32, 0.9673], ["2015-07-09T09:03:49Z", 122, 0.4444]]} +# time_series_1 [ {"region"=>"us"} ] +# columns -> ["time", "count", "value"] +# values -> [["2015-07-09T09:02:54Z", 55, 0.4343]]} +``` + +You can also pick the database to query from: + +``` +influxdb.query 'select * from time_series_1', database: 'database' +``` + +#### Streaming response + +If you expect large quantities of data in a response, you may want to enable +JSON streaming by setting a `chunk_size`: + +``` ruby +influxdb = InfluxDB::Client.new database, + username: username, + password: password, + chunk_size: 10000 +``` + +See the [official documentation](http://docs.influxdata.com/influxdb/v0.13/guides/querying_data/#chunking) +for more details. + + +#### Retry + +By default, InfluxDB::Client will keep trying (with exponential fall-off) to +connect to the database until it gets a connection. If you want to retry only +a finite number of times (or disable retries altogether), you can pass the +`:retry` option. + +`:retry` can be either `true`, `false` or an `Integer` to retry infinite times, +disable retries or retry a finite number of times, respectively. Passing `0` is +equivalent to `false` and `-1` is equivalent to `true`. + +``` +$ irb -r influxdb +> influxdb = InfluxDB::Client.new 'database', retry: 8 +=> # + +> influxdb.query 'select * from serie limit 1' +E, [2016-08-31T23:55:18.287947 #23476] ERROR -- InfluxDB: Failed to contact host localhost: # - retrying in 0.01s. +E, [2016-08-31T23:55:18.298455 #23476] ERROR -- InfluxDB: Failed to contact host localhost: # - retrying in 0.02s. +E, [2016-08-31T23:55:18.319122 #23476] ERROR -- InfluxDB: Failed to contact host localhost: # - retrying in 0.04s. +E, [2016-08-31T23:55:18.359785 #23476] ERROR -- InfluxDB: Failed to contact host localhost: # - retrying in 0.08s. +E, [2016-08-31T23:55:18.440422 #23476] ERROR -- InfluxDB: Failed to contact host localhost: # - retrying in 0.16s. +E, [2016-08-31T23:55:18.600936 #23476] ERROR -- InfluxDB: Failed to contact host localhost: # - retrying in 0.32s. +E, [2016-08-31T23:55:18.921740 #23476] ERROR -- InfluxDB: Failed to contact host localhost: # - retrying in 0.64s. +E, [2016-08-31T23:55:19.562428 #23476] ERROR -- InfluxDB: Failed to contact host localhost: # - retrying in 1.28s. +InfluxDB::ConnectionError: Tried 8 times to reconnect but failed. +``` + +## Testing + +``` +git clone git@github.com:influxdata/influxdb-ruby.git +cd influxdb-ruby +bundle +bundle exec rake +``` + +## Contributing + +- Fork this repository on GitHub. +- Make your changes. + - Add tests. + - Add an entry in the `CHANGELOG.md` in the "unreleased" section on top. +- Run the tests: `bundle exec rake`. +- Send a pull request. + - Please rebase against the master branch. +- If your changes look good, we'll merge them. diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/Rakefile b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/Rakefile new file mode 100644 index 0000000..712881f --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/Rakefile @@ -0,0 +1,51 @@ +require "rake/testtask" +require "bundler/gem_tasks" +require "rubocop/rake_task" + +RuboCop::RakeTask.new + +targeted_files = ARGV.drop(1) +file_pattern = targeted_files.empty? ? "spec/**/*_spec.rb" : targeted_files + +require "rspec/core" +require "rspec/core/rake_task" + +RSpec::Core::RakeTask.new(:spec) do |t| + t.pattern = FileList[file_pattern] +end + +Rake::TestTask.new(:smoke) do |t| + t.test_files = FileList["smoke/*.rb"] +end + +task default: [:spec, :rubocop] + +task :console do + lib = File.expand_path("../lib", __FILE__) + $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) + require "influxdb" + + begin + require "pry-byebug" + Pry.start + rescue LoadError + puts <<-TEXT.gsub(/^\s{6}([^ ])/, "\1"), "" + Could not load pry-byebug. Create a file Gemfile.local with + the following line, if you want to get rid of this message: + + \tgem "pry-byebug" + + (don't forget to run bundle afterwards). Falling back to IRB. + TEXT + + require "irb" + ARGV.clear + IRB.start + end +end + +if !ENV.key?("influx_version") || ENV["influx_version"] == "" + task default: :spec +elsif ENV["TRAVIS"] == "true" + task default: :smoke +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/influxdb.gemspec b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/influxdb.gemspec new file mode 100644 index 0000000..13bde9f --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/influxdb.gemspec @@ -0,0 +1,30 @@ +# coding: utf-8 +lib = File.expand_path('../lib', __FILE__) +$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) +require 'influxdb/version' + +# rubocop:disable Style/SpecialGlobalVars +Gem::Specification.new do |spec| + spec.name = "influxdb" + spec.version = InfluxDB::VERSION + spec.authors = ["Todd Persen"] + spec.email = ["influxdb@googlegroups.com"] + spec.description = "This is the official Ruby library for InfluxDB." + spec.summary = "Ruby library for InfluxDB." + spec.homepage = "http://influxdb.org" + spec.license = "MIT" + + spec.files = `git ls-files`.split($/) + spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } + spec.test_files = spec.files.grep(%r{^(test|spec|features|smoke)/}) + spec.require_paths = ["lib"] + + spec.add_runtime_dependency "json" + spec.add_runtime_dependency "cause" + + spec.add_development_dependency "rake" + spec.add_development_dependency "bundler", "~> 1.3" + spec.add_development_dependency "rspec", "~> 3.5.0" + spec.add_development_dependency "webmock", "~> 2.1.0" + spec.add_development_dependency "rubocop", "~> 0.41.2" +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb.rb new file mode 100644 index 0000000..f2594f0 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb.rb @@ -0,0 +1,19 @@ +require "influxdb/version" +require "influxdb/errors" +require "influxdb/logging" +require "influxdb/max_queue" +require "influxdb/point_value" +require "influxdb/config" + +require "influxdb/writer/async" +require "influxdb/writer/udp" + +require "influxdb/query/core" +require "influxdb/query/cluster" +require "influxdb/query/database" +require "influxdb/query/user" +require "influxdb/query/continuous_query" +require "influxdb/query/retention_policy" + +require "influxdb/client/http" +require "influxdb/client" diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/client.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/client.rb new file mode 100644 index 0000000..1a4eff0 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/client.rb @@ -0,0 +1,82 @@ +require 'json' +require 'cause' unless Exception.instance_methods.include?(:cause) +require 'thread' + +module InfluxDB + # InfluxDB client class + class Client + attr_reader :config, :writer + + include InfluxDB::Logging + include InfluxDB::HTTP + include InfluxDB::Query::Core + include InfluxDB::Query::Cluster + include InfluxDB::Query::Database + include InfluxDB::Query::User + include InfluxDB::Query::ContinuousQuery + include InfluxDB::Query::RetentionPolicy + + # Initializes a new InfluxDB client + # + # === Examples: + # + # # connect to localhost using root/root + # # as the credentials and doesn't connect to a db + # + # InfluxDB::Client.new + # + # # connect to localhost using root/root + # # as the credentials and 'db' as the db name + # + # InfluxDB::Client.new 'db' + # + # # override username, other defaults remain unchanged + # + # InfluxDB::Client.new username: 'username' + # + # # override username, use 'db' as the db name + # Influxdb::Client.new 'db', username: 'username' + # + # === Valid options in hash + # + # +:host+:: the hostname to connect to + # +:port+:: the port to connect to + # +:prefix+:: the specified path prefix when building the url e.g.: /prefix/db/dbname... + # +:username+:: the username to use when executing commands + # +:password+:: the password associated with the username + # +:use_ssl+:: use ssl to connect + # +:verify_ssl+:: verify ssl server certificate? + # +:ssl_ca_cert+:: ssl CA certificate, chainfile or CA path. + # The system CA path is automatically included + def initialize(*args) + opts = args.last.is_a?(Hash) ? args.last : {} + opts[:database] = args.first if args.first.is_a? String + @config = InfluxDB::Config.new(opts) + @stopped = false + @writer = find_writer + + at_exit { stop! } if config.retry > 0 + end + + def stop! + writer.worker.stop! if config.async? + @stopped = true + end + + def stopped? + @stopped + end + + private + + def find_writer + if config.async? + InfluxDB::Writer::Async.new(self, config.async) + elsif config.udp? + InfluxDB::Writer::UDP.new(self, config.udp) + else + self + end + end + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/client/http.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/client/http.rb new file mode 100644 index 0000000..bbf0f56 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/client/http.rb @@ -0,0 +1,134 @@ +require 'uri' +require 'cgi' +require 'net/http' +require 'net/https' + +module InfluxDB + # rubocop:disable Metrics/MethodLength + # rubocop:disable Metrics/AbcSize + module HTTP # :nodoc: + def get(url, options = {}) + connect_with_retry do |http| + response = do_request http, Net::HTTP::Get.new(url) + case response + when Net::HTTPSuccess + handle_successful_response(response, options) + when Net::HTTPUnauthorized + raise InfluxDB::AuthenticationError, response.body + else + resolve_error(response.body) + end + end + end + + def post(url, data) + headers = { "Content-Type" => "application/octet-stream" } + connect_with_retry do |http| + response = do_request http, Net::HTTP::Post.new(url, headers), data + + case response + when Net::HTTPNoContent + return response + when Net::HTTPUnauthorized + raise InfluxDB::AuthenticationError, response.body + else + resolve_error(response.body) + end + end + end + + private + + def connect_with_retry + host = config.next_host + delay = config.initial_delay + retry_count = 0 + + begin + http = Net::HTTP.new(host, config.port) + http.open_timeout = config.open_timeout + http.read_timeout = config.read_timeout + + http = setup_ssl(http) + yield http + + rescue *InfluxDB::NON_RECOVERABLE_EXCEPTIONS => e + raise InfluxDB::ConnectionError, InfluxDB::NON_RECOVERABLE_MESSAGE + rescue Timeout::Error, *InfluxDB::RECOVERABLE_EXCEPTIONS => e + retry_count += 1 + unless (config.retry == -1 || retry_count <= config.retry) && !stopped? + raise InfluxDB::ConnectionError, "Tried #{retry_count - 1} times to reconnect but failed." + end + log :error, "Failed to contact host #{host}: #{e.inspect} - retrying in #{delay}s." + sleep delay + delay = [config.max_delay, delay * 2].min + retry + ensure + http.finish if http.started? + end + end + + def do_request(http, req, data = nil) + req.basic_auth config.username, config.password if basic_auth? + req.body = data if data + http.request(req) + end + + def basic_auth? + config.auth_method == 'basic_auth' + end + + def resolve_error(response) + if response =~ /Couldn\'t find series/ + raise InfluxDB::SeriesNotFound, response + end + raise InfluxDB::Error, response + end + + def handle_successful_response(response, options) + if options.fetch(:json_streaming, false) + parsed_response = response.body.each_line.with_object({}) do |line, parsed| + parsed.merge!(JSON.parse(line)) { |_key, oldval, newval| oldval + newval } + end + elsif response.body + parsed_response = JSON.parse(response.body) + end + + errors = errors_from_response(parsed_response) + + raise InfluxDB::QueryError, errors if errors + options.fetch(:parse, false) ? parsed_response : response + end + + def errors_from_response(parsed_resp) + return unless parsed_resp.is_a?(Hash) + parsed_resp + .fetch('results', []) + .fetch(0, {}) + .fetch('error', nil) + end + + def setup_ssl(http) + http.use_ssl = config.use_ssl + http.verify_mode = OpenSSL::SSL::VERIFY_NONE unless config.verify_ssl + + return http unless config.use_ssl + + http.cert_store = generate_cert_store + http + end + + def generate_cert_store + store = OpenSSL::X509::Store.new + store.set_default_paths + if config.ssl_ca_cert + if File.directory?(config.ssl_ca_cert) + store.add_path(config.ssl_ca_cert) + else + store.add_file(config.ssl_ca_cert) + end + end + store + end + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/config.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/config.rb new file mode 100644 index 0000000..b40a629 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/config.rb @@ -0,0 +1,120 @@ +require 'thread' + +module InfluxDB + # InfluxDB client configuration + class Config + AUTH_METHODS = ["params".freeze, "basic_auth".freeze, "none".freeze].freeze + + attr_accessor :port, + :username, + :password, + :database, + :time_precision, + :use_ssl, + :verify_ssl, + :ssl_ca_cert, + :auth_method, + :initial_delay, + :max_delay, + :open_timeout, + :read_timeout, + :retry, + :prefix, + :chunk_size, + :denormalize, + :epoch + + attr_reader :async, :udp + + def initialize(opts = {}) + extract_http_options!(opts) + extract_ssl_options!(opts) + extract_database_options!(opts) + extract_writer_options!(opts) + extract_query_options!(opts) + + configure_retry! opts.fetch(:retry, nil) + configure_hosts! opts[:hosts] || opts[:host] || "localhost".freeze + end + + def udp? + udp != false + end + + def async? + async != false + end + + def next_host + host = @hosts_queue.pop + @hosts_queue.push(host) + host + end + + def hosts + Array.new(@hosts_queue.length) do + host = @hosts_queue.pop + @hosts_queue.push(host) + host + end + end + + private + + # rubocop:disable Metrics/AbcSize + def extract_http_options!(opts) + @port = opts.fetch :port, 8086 + @prefix = opts.fetch :prefix, "".freeze + @username = opts.fetch :username, "root".freeze + @password = opts.fetch :password, "root".freeze + @open_timeout = opts.fetch :write_timeout, 5 + @read_timeout = opts.fetch :read_timeout, 300 + @max_delay = opts.fetch :max_delay, 30 + @initial_delay = opts.fetch :initial_delay, 0.01 + auth = opts[:auth_method] + @auth_method = AUTH_METHODS.include?(auth) ? auth : "params".freeze + end + + def extract_ssl_options!(opts) + @use_ssl = opts.fetch :use_ssl, false + @verify_ssl = opts.fetch :verify_ssl, true + @ssl_ca_cert = opts.fetch :ssl_ca_cert, false + end + + # normalize retry option + def configure_retry!(value) + case value + when Integer + @retry = value + when true, nil + @retry = -1 + when false + @retry = 0 + end + end + + # load the hosts into a Queue for thread safety + def configure_hosts!(hosts) + @hosts_queue = Queue.new + Array(hosts).each do |host| + @hosts_queue.push(host) + end + end + + def extract_database_options!(opts) + @database = opts[:database] + @time_precision = opts.fetch :time_precision, "s".freeze + @denormalize = opts.fetch :denormalize, true + @epoch = opts.fetch :epoch, false + end + + def extract_writer_options!(opts) + @async = opts.fetch :async, false + @udp = opts.fetch :udp, false + end + + def extract_query_options!(opts) + @chunk_size = opts.fetch :chunk_size, nil + end + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/errors.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/errors.rb new file mode 100644 index 0000000..a5f95bb --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/errors.rb @@ -0,0 +1,52 @@ +require "net/http" +require "zlib" + +module InfluxDB # :nodoc: + class Error < StandardError + end + + class AuthenticationError < Error + end + + class ConnectionError < Error + end + + class SeriesNotFound < Error + end + + class JSONParserError < Error + end + + class QueryError < Error + end + + # When executing queries via HTTP, some errors can more or less safely + # be ignored and we can retry the query again. This following + # exception classes shall be deemed as "safe". + # + # Taken from: https://github.com/lostisland/faraday/blob/master/lib/faraday/adapter/net_http.rb + RECOVERABLE_EXCEPTIONS = [ + Errno::ECONNABORTED, + Errno::ECONNREFUSED, + Errno::ECONNRESET, + Errno::EHOSTUNREACH, + Errno::EINVAL, + Errno::ENETUNREACH, + Net::HTTPBadResponse, + Net::HTTPHeaderSyntaxError, + Net::ProtocolError, + SocketError, + (OpenSSL::SSL::SSLError if defined?(OpenSSL)) + ].compact.freeze + + # Exception classes which hint to a larger problem on the server side, + # like insuffient resources. If we encouter on of the following, wo + # _don't_ retry a query but escalate it upwards. + NON_RECOVERABLE_EXCEPTIONS = [ + EOFError, + Zlib::Error + ].freeze + + NON_RECOVERABLE_MESSAGE = "The server has sent incomplete data" \ + " (insufficient resources are a possible cause).".freeze +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/logging.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/logging.rb new file mode 100644 index 0000000..7ac1767 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/logging.rb @@ -0,0 +1,23 @@ +require 'logger' + +module InfluxDB + module Logging # :nodoc: + PREFIX = "InfluxDB".freeze + + class << self + attr_writer :logger + end + + def self.logger + return false if @logger == false + @logger ||= ::Logger.new(STDERR).tap { |logger| logger.level = Logger::INFO } + end + + private + + def log(level, message) + return unless InfluxDB::Logging.logger + InfluxDB::Logging.logger.send(level.to_sym, PREFIX) { message } + end + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/max_queue.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/max_queue.rb new file mode 100644 index 0000000..bbc33ec --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/max_queue.rb @@ -0,0 +1,18 @@ +require "thread" + +module InfluxDB + # Queue with max length limit + class MaxQueue < Queue + attr_reader :max + + def initialize(max = 10_000) + raise ArgumentError, "queue size must be positive" if max <= 0 + @max = max + super() + end + + def push(obj) + super if length < @max + end + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/point_value.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/point_value.rb new file mode 100644 index 0000000..08d3bf3 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/point_value.rb @@ -0,0 +1,77 @@ +module InfluxDB + # Convert data point to string using Line protocol + class PointValue + attr_reader :series, :values, :tags, :timestamp + + def initialize(data) + @series = escape data[:series], :measurement + @values = escape_values data[:values] + @tags = escape_tags data[:tags] + + @timestamp = data[:timestamp] + end + + def dump + dump = @series.dup + dump << ",#{@tags}" if @tags + dump << " #{@values}" + dump << " #{@timestamp}" if @timestamp + dump + end + + private + + ESCAPES = { + measurement: [' '.freeze, ','.freeze], + tag_key: ['='.freeze, ' '.freeze, ','.freeze], + tag_value: ['='.freeze, ' '.freeze, ','.freeze], + field_key: ['='.freeze, ' '.freeze, ','.freeze, '"'.freeze], + field_value: ['"'.freeze] + }.freeze + + def escape(s, type) + # rubocop:disable Style/AlignParameters + s = s.encode "UTF-8".freeze, "UTF-8".freeze, + invalid: :replace, + undef: :replace, + replace: "".freeze + + ESCAPES[type].each do |ch| + s = s.gsub(ch) { "\\#{ch}" } + end + s + end + + def escape_values(values) + return if values.nil? + values.map do |k, v| + key = escape(k.to_s, :field_key) + val = escape_value(v) + "#{key}=#{val}" + end.join(",") + end + + def escape_value(value) + if value.is_a?(String) + '"' + escape(value, :field_value) + '"' + elsif value.is_a?(Integer) + "#{value}i" + else + value.to_s + end + end + + def escape_tags(tags) + return if tags.nil? + + tags = tags.map do |k, v| + key = escape(k.to_s, :tag_key) + val = escape(v.to_s, :tag_value) + + "#{key}=#{val}" unless key == "" || val == "" + end.compact + + tags.join(",") unless tags.empty? + end + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/query/builder.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/query/builder.rb new file mode 100644 index 0000000..36dd550 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/query/builder.rb @@ -0,0 +1,44 @@ +module InfluxDB + module Query # :nodoc: all + class Builder + def build(query, params) + case params + when Array then params = params_from_array(params) + when Hash then params = params_from_hash(params) + when NilClass then params = {} + else raise ArgumentError, "Unsupported #{params.class} params" + end + + query % params + + rescue KeyError => e + raise ArgumentError, e.message + end + + def quote(param) + case param + when String, Symbol + "'" + param.to_s.gsub(/['"\\\x0]/, '\\\\\0') + "'" + when Integer, Float, TrueClass, FalseClass + param.to_s + else + raise ArgumentError, "Unexpected parameter type #{param.class} (#{param.inspect})" + end + end + + private + + def params_from_hash(params) + params.each_with_object({}) do |(k, v), hash| + hash[k.to_sym] = quote(v) + end + end + + def params_from_array(params) + params.each_with_object({}).with_index do |(param, hash), i| + hash[(i + 1).to_s.to_sym] = quote(param) + end + end + end + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/query/cluster.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/query/cluster.rb new file mode 100644 index 0000000..e230a15 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/query/cluster.rb @@ -0,0 +1,17 @@ +module InfluxDB + module Query + module Cluster # :nodoc: + def create_cluster_admin(username, password) + execute("CREATE USER #{username} WITH PASSWORD '#{password}' WITH ALL PRIVILEGES") + end + + def list_cluster_admins + list_users.select { |u| u['admin'] }.map { |u| u['username'] } + end + + def revoke_cluster_admin_privileges(username) + execute("REVOKE ALL PRIVILEGES FROM #{username}") + end + end + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/query/continuous_query.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/query/continuous_query.rb new file mode 100644 index 0000000..ae6e1fb --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/query/continuous_query.rb @@ -0,0 +1,31 @@ +module InfluxDB + module Query + module ContinuousQuery # :nodoc: + def list_continuous_queries(database) + resp = execute("SHOW CONTINUOUS QUERIES", parse: true) + fetch_series(resp) + .select { |v| v['name'] == database } + .fetch(0, {}) + .fetch('values', []) + .map { |v| { 'name' => v.first, 'query' => v.last } } + end + + def create_continuous_query(name, database, query, options = {}) + clause = ["CREATE CONTINUOUS QUERY", name, "ON", database] + + if options[:resample_every] || options[:resample_for] + clause << "RESAMPLE" + clause << "EVERY #{options[:resample_every]}" if options[:resample_every] + clause << "FOR #{options[:resample_for]}" if options[:resample_for] + end + + clause = clause.join(" ") << " BEGIN\n" << query << "\nEND" + execute(clause) + end + + def delete_continuous_query(name, database) + execute("DROP CONTINUOUS QUERY #{name} ON #{database}") + end + end + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/query/core.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/query/core.rb new file mode 100644 index 0000000..37cc29a --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/query/core.rb @@ -0,0 +1,149 @@ +require_relative 'builder' + +module InfluxDB + module Query # :nodoc: all + # rubocop:disable Metrics/AbcSize + module Core + def builder + @builder ||= Builder.new + end + + def ping + url = URI::Generic.build(path: File.join(config.prefix, '/ping')).to_s + get url + end + + def version + ping.header['x-influxdb-version'] + end + + # rubocop:disable Metrics/MethodLength + def query(query, opts = {}) + query = builder.build(query, opts[:params]) + denormalize = opts.fetch(:denormalize, config.denormalize) + json_streaming = !opts.fetch(:chunk_size, config.chunk_size).nil? + + params = query_params(query, opts) + url = full_url("/query".freeze, params) + series = fetch_series(get(url, parse: true, json_streaming: json_streaming)) + + if block_given? + series.each do |s| + values = denormalize ? denormalize_series(s) : raw_values(s) + yield s['name'.freeze], s['tags'.freeze], values + end + else + denormalize ? denormalized_series_list(series) : series + end + end + # rubocop:enable Metrics/MethodLength + + # Example: + # write_points([ + # { + # series: 'cpu', + # tags: { host: 'server_nl', regios: 'us' }, + # values: {internal: 5, external: 6}, + # timestamp: 1422568543702900257 + # }, + # { + # series: 'gpu', + # values: {value: 0.9999}, + # } + # ]) + def write_points(data, precision = nil, retention_policy = nil, database = nil) + data = data.is_a?(Array) ? data : [data] + payload = generate_payload(data) + writer.write(payload, precision, retention_policy, database) + end + + # Example: + # write_point('cpu', tags: {region: 'us'}, values: {internal: 60}) + def write_point(series, data, precision = nil, retention_policy = nil, database = nil) + write_points(data.merge(series: series), precision, retention_policy, database) + end + + def write(data, precision, retention_policy = nil, database = nil) + params = { + db: database || config.database, + precision: precision || config.time_precision + } + + params[:rp] = retention_policy if retention_policy + url = full_url("/write", params) + post(url, data) + end + + private + + # rubocop:disable Metrics/MethodLength + def query_params(query, opts) + precision = opts.fetch(:precision, config.time_precision) + epoch = opts.fetch(:epoch, config.epoch) + chunk_size = opts.fetch(:chunk_size, config.chunk_size) + database = opts.fetch(:database, config.database) + + params = { q: query, db: database, precision: precision } + params[:epoch] = epoch if epoch + + if chunk_size + params[:chunked] = 'true' + params[:chunk_size] = chunk_size + end + + params + end + # rubocop:enable Metrics/MethodLength + + def denormalized_series_list(series) + series.map do |s| + { + "name" => s["name".freeze], + "tags" => s["tags".freeze], + "values" => denormalize_series(s) + } + end + end + + def fetch_series(response) + response.fetch('results'.freeze, []).flat_map do |result| + result.fetch('series'.freeze, []) + end + end + + def generate_payload(data) + data.map do |point| + InfluxDB::PointValue.new(point).dump + end.join("\n".freeze) + end + + def execute(query, options = {}) + url = full_url("/query", q: query) + get(url, options) + end + + def denormalize_series(series) + Array(series["values".freeze]).map do |values| + Hash[series["columns".freeze].zip(values)] + end + end + + def raw_values(series) + series.select { |k, _| %w(columns values).include?(k) } + end + + def full_url(path, params = {}) + if config.auth_method == "params".freeze + params[:u] = config.username + params[:p] = config.password + end + + query = params.map do |k, v| + [CGI.escape(k.to_s), "=".freeze, CGI.escape(v.to_s)].join + end.join("&".freeze) + + URI::Generic.build(path: File.join(config.prefix, path), query: query).to_s + end + end + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/query/database.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/query/database.rb new file mode 100644 index 0000000..284d7a5 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/query/database.rb @@ -0,0 +1,22 @@ +module InfluxDB + module Query + module Database # :nodoc: + def create_database(name = nil) + execute("CREATE DATABASE #{name || config.database}") + end + + def delete_database(name = nil) + execute("DROP DATABASE #{name || config.database}") + end + + def list_databases + resp = execute("SHOW DATABASES".freeze, parse: true) + fetch_series(resp) + .fetch(0, {}) + .fetch('values', []) + .flatten + .map { |v| { 'name' => v } } + end + end + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/query/retention_policy.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/query/retention_policy.rb new file mode 100644 index 0000000..37e3845 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/query/retention_policy.rb @@ -0,0 +1,34 @@ +module InfluxDB + module Query + module RetentionPolicy # :nodoc: + def create_retention_policy(name, database, duration, replication, default = false) + execute( + "CREATE RETENTION POLICY \"#{name}\" ON #{database} " \ + "DURATION #{duration} REPLICATION #{replication}#{default ? ' DEFAULT' : ''}" + ) + end + + def list_retention_policies(database) + resp = execute("SHOW RETENTION POLICIES ON \"#{database}\"", parse: true) + data = fetch_series(resp).fetch(0) + + data['values'.freeze].map do |policy| + policy.each.with_index.inject({}) do |hash, (value, index)| + hash.tap { |h| h[data['columns'.freeze][index]] = value } + end + end + end + + def delete_retention_policy(name, database) + execute("DROP RETENTION POLICY \"#{name}\" ON #{database}") + end + + def alter_retention_policy(name, database, duration, replication, default = false) + execute( + "ALTER RETENTION POLICY \"#{name}\" ON #{database} " \ + "DURATION #{duration} REPLICATION #{replication}#{default ? ' DEFAULT' : ''}" + ) + end + end + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/query/user.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/query/user.rb new file mode 100644 index 0000000..ced54a5 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/query/user.rb @@ -0,0 +1,51 @@ +module InfluxDB + module Query + module User # :nodoc: + # create_database_user('testdb', 'user', 'pass') - grants all privileges by default + # create_database_user('testdb', 'user', 'pass', permissions: :read) - use [:read|:write|:all] + def create_database_user(database, username, password, options = {}) + permissions = options.fetch(:permissions, :all) + execute( + "CREATE user #{username} WITH PASSWORD '#{password}'; "\ + "GRANT #{permissions.to_s.upcase} ON #{database} TO #{username}" + ) + end + + def update_user_password(username, password) + execute("SET PASSWORD FOR #{username} = '#{password}'") + end + + # permission => [:all] + def grant_user_admin_privileges(username) + execute("GRANT ALL PRIVILEGES TO #{username}") + end + + # permission => [:read|:write|:all] + def grant_user_privileges(username, database, permission) + execute("GRANT #{permission.to_s.upcase} ON #{database} TO #{username}") + end + + def list_user_grants(username) + execute("SHOW GRANTS FOR #{username}") + end + + # permission => [:read|:write|:all] + def revoke_user_privileges(username, database, permission) + execute("REVOKE #{permission.to_s.upcase} ON #{database} FROM #{username}") + end + + def delete_user(username) + execute("DROP USER #{username}") + end + + # => [{"username"=>"usr", "admin"=>true}, {"username"=>"justauser", "admin"=>false}] + def list_users + resp = execute("SHOW USERS".freeze, parse: true) + fetch_series(resp) + .fetch(0, {}) + .fetch('values'.freeze, []) + .map { |v| { 'username' => v.first, 'admin' => v.last } } + end + end + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/version.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/version.rb new file mode 100644 index 0000000..d4770b5 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/version.rb @@ -0,0 +1,3 @@ +module InfluxDB # :nodoc: + VERSION = "0.3.13".freeze +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/writer/async.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/writer/async.rb new file mode 100644 index 0000000..3edaa10 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/writer/async.rb @@ -0,0 +1,127 @@ +require 'thread' +require "net/http" +require "uri" + +module InfluxDB + module Writer # :nodoc: all + class Async + attr_reader :config, :client + + def initialize(client, config) + @client = client + @config = config + end + + def write(data, _precision = nil, _retention_policy = nil, _database = nil) + data = data.is_a?(Array) ? data : [data] + data.map { |p| worker.push(p) } + end + + WORKER_MUTEX = Mutex.new + def worker + return @worker if @worker + WORKER_MUTEX.synchronize do + # this return is necessary because the previous mutex holder + # might have already assigned the @worker + return @worker if @worker + @worker = Worker.new(client, config) + end + end + + class Worker + attr_reader :client, + :queue, + :threads, + :max_post_points, + :max_queue_size, + :num_worker_threads, + :sleep_interval + + include InfluxDB::Logging + + MAX_POST_POINTS = 1000 + MAX_QUEUE_SIZE = 10_000 + NUM_WORKER_THREADS = 3 + SLEEP_INTERVAL = 5 + + def initialize(client, config) + @client = client + config = config.is_a?(Hash) ? config : {} + + @max_post_points = config.fetch(:max_post_points, MAX_POST_POINTS) + @max_queue_size = config.fetch(:max_queue_size, MAX_QUEUE_SIZE) + @num_worker_threads = config.fetch(:num_worker_threads, NUM_WORKER_THREADS) + @sleep_interval = config.fetch(:sleep_interval, SLEEP_INTERVAL) + + @queue = InfluxDB::MaxQueue.new max_queue_size + + spawn_threads! + end + + def push(payload) + queue.push(payload) + end + + def current_threads + Thread.list.select { |t| t[:influxdb] == object_id } + end + + def current_thread_count + Thread.list.count { |t| t[:influxdb] == object_id } + end + + # rubocop:disable Metrics/CyclomaticComplexity + # rubocop:disable Metrics/MethodLength + # rubocop:disable Metrics/AbcSize + + def spawn_threads! + @threads = [] + num_worker_threads.times do |thread_num| + log :debug, "Spawning background worker thread #{thread_num}." + + @threads << Thread.new do + Thread.current[:influxdb] = object_id + + until client.stopped? + check_background_queue(thread_num) + sleep rand(sleep_interval) + end + + log :debug, "Exit background worker thread #{thread_num}." + end + end + end + + def check_background_queue(thread_num = 0) + log :debug, + "Checking background queue on thread #{thread_num} (#{current_thread_count} active)" + + loop do + data = [] + + while data.size < max_post_points && !queue.empty? + p = queue.pop(true) rescue next + data.push p + end + + return if data.empty? + + begin + log :debug, "Found data in the queue! (#{data.length} points)" + client.write(data.join("\n"), nil) + rescue => e + puts "Cannot write data: #{e.inspect}" + end + + break if queue.length > max_post_points + end + end + + def stop! + log :debug, "Thread exiting, flushing queue." + check_background_queue until queue.empty? + end + end + end + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/writer/udp.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/writer/udp.rb new file mode 100644 index 0000000..5ee9277 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/writer/udp.rb @@ -0,0 +1,21 @@ +module InfluxDB + module Writer + # Writes data to InfluxDB through UDP + class UDP + attr_accessor :socket + attr_reader :host, :port + def initialize(client, config) + @client = client + config = config.is_a?(Hash) ? config : {} + @host = config.fetch(:host, "localhost".freeze) + @port = config.fetch(:port, 4444) + self.socket = UDPSocket.new + socket.connect(host, port) + end + + def write(payload, _precision = nil, _retention_policy = nil, _database = nil) + socket.send(payload, 0) + end + end + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/smoke/connect-and-get-version.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/smoke/connect-and-get-version.rb new file mode 100644 index 0000000..27398c7 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/smoke/connect-and-get-version.rb @@ -0,0 +1,18 @@ +require "influxdb" + +puts __FILE__ +puts "\tThis file contains some sanity checks." +puts + +client = InfluxDB::Client.new \ + username: "test_user", + password: "resu_tset", + retry: 4 + +version = client.version + +if version + puts "Got version: #{version}" +else + raise "version is empty" +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/smoke/noaa-sample-data.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/smoke/noaa-sample-data.rb new file mode 100644 index 0000000..d3366d4 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/smoke/noaa-sample-data.rb @@ -0,0 +1,79 @@ +require "influxdb" + +puts __FILE__ +puts "\tThis is basically a test whether the examples in documented on" +puts "\thttp://docs.influxdata.com/influxdb/v0.13/sample_data/data_download/" +puts "\twork with the Ruby client." +puts + +client = InfluxDB::Client.new \ + database: "NOAA_water_database", + username: "test_user", + password: "resu_tset", + retry: 4 + +TestFailure = Class.new StandardError +TestAllowedFailure = Class.new StandardError + +def test_case(name) + print name + yield + puts " [ OK ]" + +rescue TestAllowedFailure + puts " [WARN]" + puts $!.message + +rescue TestFailure + puts " [FAIL]" + puts $!.message + exit 1 +end + +test_case "See all five measurements?" do + result = client.query "show measurements" + expected = %w[ average_temperature h2o_feet h2o_pH h2o_quality h2o_temperature ] + actual = result[0]["values"].map{|v| v["name"] } + unexpected = actual - expected + if unexpected.any? + raise TestFailure, "unexpected measurements: #{unexpected.join(", ")}" + end +end + +test_case "Count the number of non-null values of water_level in h2o_feet" do + result = client.query "select count(water_level) from h2o_feet" + expected = 15258 + actual = result[0]["values"][0]["count"] + if expected != actual + raise TestFailure, "expected to find #{expected} points, got #{actual}" + end +end + +test_case "Select the first five observations in the measurement h2o_feet" do + result = client.query("select * from h2o_feet limit 5").first["values"] + expected = 5 + actual = result.size + if expected != actual + raise TestFailure, "expected #{expected} observations, got #{actual}" + end + + expected = { + "time" => "2015-08-18T00:00:00Z", + "level description" => "between 6 and 9 feet", + "location" => "coyote_creek", + "water_level" => 8.12 + } + if expected != result[0] + raise TestAllowedFailure, "unexpected first result, got #{result[0]}" + end + + expected = { + "time" => "2015-08-18T00:12:00Z", + "level description" => "between 6 and 9 feet", + "location" => "coyote_creek", + "water_level" => 7.887 + } + if expected != result[-1] + raise TestAllowedFailure, "unexpected last result, got #{result[-1]}" + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/smoke/provision.sh b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/smoke/provision.sh new file mode 100755 index 0000000..8c58a30 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/smoke/provision.sh @@ -0,0 +1,92 @@ +#!/bin/sh -e + +if [ -z "$influx_version" ]; then + echo "== Provisioning InfluxDB: Skipping, influx_version is empty" + exit 0 +else + echo "== Provisioning InfluxDB ${influx_version}" +fi + +package_name="influxdb_${influx_version}_amd64.deb" +[ -z "${channel}" ] && channel="releases" +download_url="https://dl.influxdata.com/influxdb/${channel}/${package_name}" + + +echo "== Downloading package" + +if which curl 2>&1 >/dev/null; then + curl "${download_url}" > "${HOME}/${package_name}" +else + echo >&2 "E: Could not find curl" + exit 1 +fi + +echo "== Download verification" +hash_sum=$(md5sum "${HOME}/${package_name}" | awk '{ print $1 }') + +if [ -z "${pkghash}" ]; then + echo "-- Skipping, pkghash is empty" +else + if [ "${hash_sum}" != "${pkghash}" ]; then + echo >&2 "E: Hash sum mismatch (got ${hash_sum}, expected ${pkghash})" + exit 1 + fi +fi +echo "-- Download has MD5 hash: ${hash_sum}" + + +echo "== Installing" + +sudo dpkg -i "${HOME}/${package_name}" +sudo /etc/init.d/influxdb start + +echo "-- waiting for daemon to start" +while ! curl --head --fail --silent http://localhost:8086/ping; do + echo -n "." + sleep 1 +done + + +echo "== Configuring" + +echo "-- create admin user" +/usr/bin/influx -execute "CREATE USER root WITH PASSWORD 'toor' WITH ALL PRIVILEGES" + +echo "-- create non-admin user" +/usr/bin/influx -execute "CREATE USER test_user WITH PASSWORD 'resu_tset'" + +echo "-- create databases" +/usr/bin/influx -execute "CREATE DATABASE db_one" +/usr/bin/influx -execute "CREATE DATABASE db_two" + +echo "-- grant access" +/usr/bin/influx -execute "GRANT ALL ON db_two TO test_user" + + +echo "== Download and import NOAA sample data" + +curl https://s3-us-west-1.amazonaws.com/noaa.water.database.0.9/NOAA_data.txt > noaa.txt +/usr/bin/influx -import -path noaa.txt -precision s + +echo "-- grant access" +/usr/bin/influx -execute "GRANT ALL ON NOAA_water_database TO test_user" + + +echo "== Enable authentication" + +if [ ! -f /etc/influxdb/influxdb.conf ]; then + echo >&2 "E: config file not found" + exit 1 +fi + +sudo sed -i 's/auth-enabled = false/auth-enabled = true/' /etc/influxdb/influxdb.conf +sudo /etc/init.d/influxdb restart + +echo "-- waiting for daemon to restart" +while ! curl --head --fail --silent http://localhost:8086/ping; do + echo -n "." + sleep 1 +done + + +echo "== Done" diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/async_client_spec.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/async_client_spec.rb new file mode 100644 index 0000000..3ff3b16 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/async_client_spec.rb @@ -0,0 +1,58 @@ +require "spec_helper" +require "timeout" + +describe InfluxDB::Client do + let(:async_options) { true } + let(:client) { described_class.new(async: async_options) } + let(:subject) { client } + let(:stub_url) { "http://localhost:8086/write?db=&p=root&precision=s&u=root" } + let(:worker) { client.writer.worker } + + specify { expect(subject.writer).to be_a(InfluxDB::Writer::Async) } + + describe "#write_point" do + it "sends writes to client" do + post_request = stub_request(:post, stub_url).to_return(status: 204) + + (worker.max_post_points + 100).times do + subject.write_point('a', {}) + end + + # The timout code is fragile, and heavily dependent on system load + # (and scheduler decisions). On the CI, the system is less + # responsive and needs a bit more time. + timeout_stretch = ENV["TRAVIS"] == "true" ? 10 : 3 + + Timeout.timeout(timeout_stretch * worker.sleep_interval) do + subject.stop! + end + + worker.threads.each do |t| + expect(t.stop?).to be true + end + + # exact times can be 2 or 3 (because we have 3 worker threads), + # but cannot be less than 2 due to MAX_POST_POINTS limit + expect(post_request).to have_been_requested.at_least_times(2) + end + end + + describe "async options" do + let(:async_options) do + { + max_post_points: 10, + max_queue_size: 100, + num_worker_threads: 1, + sleep_interval: 0.5 + } + end + + subject { worker } + before { worker.stop! } + + specify { expect(subject.max_post_points).to be 10 } + specify { expect(subject.max_queue_size).to be 100 } + specify { expect(subject.num_worker_threads).to be 1 } + specify { expect(subject.sleep_interval).to be_within(0.0001).of(0.5) } + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/query_cluster_spec.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/query_cluster_spec.rb new file mode 100644 index 0000000..2e47f09 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/query_cluster_spec.rb @@ -0,0 +1,81 @@ +require "spec_helper" +require "json" + +describe InfluxDB::Client do + let(:subject) do + described_class.new( + "database", + { + host: "influxdb.test", + port: 9999, + username: "username", + password: "password", + time_precision: "s" + }.merge(args) + ) + end + + let(:args) { {} } + + describe "#create_cluster_admin" do + let(:user) { 'adminadmin' } + let(:pass) { 'passpass' } + let(:query) { "CREATE USER #{user} WITH PASSWORD '#{pass}' WITH ALL PRIVILEGES" } + + context 'with existing admin user' do + before do + stub_request(:get, "http://influxdb.test:9999/query").with( + query: { u: "username", p: "password", q: query } + ) + end + + it "should GET to create a new cluster admin" do + expect(subject.create_cluster_admin(user, pass)).to be_a(Net::HTTPOK) + end + end + + context 'with no admin user' do + let(:args) { { auth_method: 'none' } } + + before do + stub_request(:get, "http://influxdb.test:9999/query").with( + query: { q: query } + ) + end + + it "should GET to create a new cluster admin" do + expect(subject.create_cluster_admin(user, pass)).to be_a(Net::HTTPOK) + end + end + end + + describe "#list_cluster_admins" do + let(:response) { { "results" => [{ "series" => [{ "columns" => %w(user admin), "values" => [["dbadmin", true], ["foobar", false]] }] }] } } + let(:expected_result) { ["dbadmin"] } + + before do + stub_request(:get, "http://influxdb.test:9999/query").with( + query: { u: "username", p: "password", q: "SHOW USERS" } + ).to_return(body: JSON.generate(response, status: 200)) + end + + it "should GET a list of cluster admins" do + expect(subject.list_cluster_admins).to eq(expected_result) + end + end + + describe "#revoke_cluster_admin_privileges" do + let(:user) { 'useruser' } + let(:query) { "REVOKE ALL PRIVILEGES FROM #{user}" } + + before do + stub_request(:get, "http://influxdb.test:9999/query").with( + query: { u: "username", p: "password", q: query } + ) + end + + it "should GET to revoke cluster admin privileges from a user" do + expect(subject.revoke_cluster_admin_privileges(user)).to be_a(Net::HTTPOK) + end + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/query_continuous_query_spec.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/query_continuous_query_spec.rb new file mode 100644 index 0000000..27197c8 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/query_continuous_query_spec.rb @@ -0,0 +1,120 @@ +require "spec_helper" +require "json" + +describe InfluxDB::Client do + let(:subject) do + described_class.new( + "database", + { + host: "influxdb.test", + port: 9999, + username: "username", + password: "password", + time_precision: "s" + }.merge(args) + ) + end + + let(:args) { {} } + + describe "#list_continuous_queries" do + let(:query) { "SHOW CONTINUOUS QUERIES" } + let(:database) { "testdb" } + let(:response) do + { "results" => [{ "series" => [{ "name" => "otherdb", "columns" => %w(name query), + "values" => [["clicks_per_hour", "CREATE CONTINUOUS QUERY clicks_per_hour ON otherdb BEGIN SELECT count(name) INTO \"otherdb\".\"default\".clicksCount_1h FROM \"otherdb\".\"default\".clicks GROUP BY time(1h) END"]] }, + { "name" => "testdb", "columns" => %w(name query), + "values" => [["event_counts", "CREATE CONTINUOUS QUERY event_counts ON testdb BEGIN SELECT count(type) INTO \"testdb\".\"default\".typeCount_10m_byType FROM \"testdb\".\"default\".events GROUP BY time(10m), type END"]] }] }] } + end + + let(:expected_result) do + [{ "name" => "event_counts", "query" => "CREATE CONTINUOUS QUERY event_counts ON testdb BEGIN SELECT count(type) INTO \"testdb\".\"default\".typeCount_10m_byType FROM \"testdb\".\"default\".events GROUP BY time(10m), type END" }] + end + + before do + stub_request(:get, "http://influxdb.test:9999/query").with( + query: { u: "username", p: "password", q: query } + ).to_return(body: JSON.generate(response), status: 200) + end + + it "should GET a list of continuous queries for specified db only" do + expect(subject.list_continuous_queries(database)).to eq(expected_result) + end + end + + describe "#create_continuous_query" do + let(:name) { "event_counts_per_10m_by_type" } + let(:database) { "testdb" } + let(:query) { "SELECT COUNT(type) INTO typeCount_10m_byType FROM events GROUP BY time(10m), type" } + let(:every_interval) { nil } + let(:for_interval) { nil } + + let(:clause) do + c = "CREATE CONTINUOUS QUERY #{name} ON #{database}" + + if every_interval && for_interval + c << " RESAMPLE EVERY #{every_interval} FOR #{for_interval}" + elsif every_interval + c << " RESAMPLE EVERY #{every_interval}" + elsif for_interval + c << " RESAMPLE FOR #{for_interval}" + end + + c << " BEGIN\n#{query}\nEND" + end + + before do + stub_request(:get, "http://influxdb.test:9999/query").with( + query: { u: "username", p: "password", q: clause } + ) + end + + context "without resampling" do + it "should GET to create a new continuous query" do + expect(subject.create_continuous_query(name, database, query)).to be_a(Net::HTTPOK) + end + end + + context "with resampling" do + context "EVERY " do + let(:every_interval) { "10m" } + + it "should GET to create a new continuous query" do + expect(subject.create_continuous_query(name, database, query, resample_every: every_interval)).to be_a(Net::HTTPOK) + end + end + + context "FOR " do + let(:for_interval) { "7d" } + + it "should GET to create a new continuous query" do + expect(subject.create_continuous_query(name, database, query, resample_for: for_interval)).to be_a(Net::HTTPOK) + end + end + + context "EVERY FOR " do + let(:every_interval) { "5m" } + let(:for_interval) { "3w" } + + it "should GET to create a new continuous query" do + expect(subject.create_continuous_query(name, database, query, resample_for: for_interval, resample_every: every_interval)).to be_a(Net::HTTPOK) + end + end + end + end + + describe "#delete_continuous_query" do + let(:name) { "event_counts_per_10m_by_type" } + let(:database) { "testdb" } + let(:query) { "DROP CONTINUOUS QUERY #{name} ON #{database}" } + before do + stub_request(:get, "http://influxdb.test:9999/query").with( + query: { u: "username", p: "password", q: query } + ) + end + + it "should GET to remove continuous query" do + expect(subject.delete_continuous_query(name, database)).to be_a(Net::HTTPOK) + end + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/query_core_spec.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/query_core_spec.rb new file mode 100644 index 0000000..b3c61e4 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/query_core_spec.rb @@ -0,0 +1,36 @@ +require "spec_helper" + +describe InfluxDB::Client do + let(:subject) do + described_class.new "database", { + host: "influxdb.test", + port: 9999, + username: "username", + password: "password", + time_precision: "s" + }.merge(args) + end + + let(:args) { {} } + + describe "#query" do + let(:query) { "SELECT value FROM requests_per_minute WHERE time > 1437019900" } + let(:response) do + { "results" => [{ "series" => [{ "name" => "requests_per_minute", + "columns" => %w(time value) }] }] } + end + + before do + stub_request(:get, "http://influxdb.test:9999/query") + .with(query: { db: "database", precision: "s", u: "username", p: "password", q: query }) + .to_return(body: JSON.generate(response), status: 200) + end + + it "should handle responses with no values" do + # Some requests (such as trying to retrieve values from the future) + # return a result with no "values" key set. + expected_result = [{ "name" => "requests_per_minute", "tags" => nil, "values" => [] }] + expect(subject.query(query)).to eq(expected_result) + end + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/query_database_spec.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/query_database_spec.rb new file mode 100644 index 0000000..5c13517 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/query_database_spec.rb @@ -0,0 +1,73 @@ +require "spec_helper" +require "json" + +describe InfluxDB::Client do + let(:subject) do + described_class.new( + "database", + { + host: "influxdb.test", + port: 9999, + username: "username", + password: "password", + time_precision: "s" + }.merge(args) + ) + end + + let(:args) { {} } + let(:query) { nil } + let(:response) { { "results" => [] } } + + before do + stub_request(:get, "http://influxdb.test:9999/query").with( + query: { u: "username", p: "password", q: query } + ).to_return(body: JSON.generate(response)) + end + + describe "#create_database" do + describe "from param" do + let(:query) { "CREATE DATABASE foo" } + + it "should GET to create a new database" do + expect(subject.create_database("foo")).to be_a(Net::HTTPOK) + end + end + + describe "from config" do + let(:query) { "CREATE DATABASE database" } + + it "should GET to create a new database using database name from config" do + expect(subject.create_database).to be_a(Net::HTTPOK) + end + end + end + + describe "#delete_database" do + describe "from param" do + let(:query) { "DROP DATABASE foo" } + + it "should GET to remove a database" do + expect(subject.delete_database("foo")).to be_a(Net::HTTPOK) + end + end + + describe "from config" do + let(:query) { "DROP DATABASE database" } + + it "should GET to remove a database using database name from config" do + expect(subject.delete_database).to be_a(Net::HTTPOK) + end + end + end + + describe "#list_databases" do + let(:query) { "SHOW DATABASES" } + let(:response) { { "results" => [{ "series" => [{ "name" => "databases", "columns" => ["name"], "values" => [["foobar"]] }] }] } } + let(:expected_result) { [{ "name" => "foobar" }] } + + it "should GET a list of databases" do + expect(subject.list_databases).to eq(expected_result) + end + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/query_retention_policy_spec.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/query_retention_policy_spec.rb new file mode 100644 index 0000000..27b5dbc --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/query_retention_policy_spec.rb @@ -0,0 +1,81 @@ +require "spec_helper" +require "json" + +describe InfluxDB::Client do + let(:subject) do + described_class.new( + "database", + { + host: "influxdb.test", + port: 9999, + username: "username", + password: "password", + time_precision: "s" + }.merge(args) + ) + end + + let(:args) { {} } + let(:query) { nil } + let(:response) { { "results" => [] } } + + before do + stub_request(:get, "http://influxdb.test:9999/query").with( + query: { u: "username", p: "password", q: query } + ).to_return(body: JSON.generate(response)) + end + + describe "#list_retention_policies" do + let(:response) { { "results" => [{ "series" => [{ "columns" => %w(name duration replicaN default), "values" => [["default", "0", 1, true], ["another", "1", 2, false]] }] }] } } + let(:query) { "SHOW RETENTION POLICIES ON \"database\"" } + let(:expected_result) { [{ "name" => "default", "duration" => "0", "replicaN" => 1, "default" => true }, { "name" => "another", "duration" => "1", "replicaN" => 2, "default" => false }] } + + it "should GET a list of retention policies" do + expect(subject.list_retention_policies('database')).to eq(expected_result) + end + end + + describe "#create_retention_policy" do + context "default" do + let(:query) { "CREATE RETENTION POLICY \"1h.cpu\" ON foo DURATION 1h REPLICATION 2 DEFAULT" } + + it "should GET to create a new database" do + expect(subject.create_retention_policy('1h.cpu', 'foo', '1h', 2, true)).to be_a(Net::HTTPOK) + end + end + + context "non-default" do + let(:query) { "CREATE RETENTION POLICY \"1h.cpu\" ON foo DURATION 1h REPLICATION 2" } + + it "should GET to create a new database" do + expect(subject.create_retention_policy('1h.cpu', 'foo', '1h', 2)).to be_a(Net::HTTPOK) + end + end + end + + describe "#delete_retention_policy" do + let(:query) { "DROP RETENTION POLICY \"1h.cpu\" ON foo" } + + it "should GET to remove a database" do + expect(subject.delete_retention_policy('1h.cpu', 'foo')).to be_a(Net::HTTPOK) + end + end + + describe "#alter_retention_policy" do + context "default" do + let(:query) { "ALTER RETENTION POLICY \"1h.cpu\" ON foo DURATION 1h REPLICATION 2 DEFAULT" } + + it "should GET to alter a new database" do + expect(subject.alter_retention_policy('1h.cpu', 'foo', '1h', 2, true)).to be_a(Net::HTTPOK) + end + end + + context "non-default" do + let(:query) { "ALTER RETENTION POLICY \"1h.cpu\" ON foo DURATION 1h REPLICATION 2" } + + it "should GET to alter a new database" do + expect(subject.alter_retention_policy('1h.cpu', 'foo', '1h', 2)).to be_a(Net::HTTPOK) + end + end + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/query_series_spec.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/query_series_spec.rb new file mode 100644 index 0000000..b737ca0 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/query_series_spec.rb @@ -0,0 +1,50 @@ +require "spec_helper" +require "json" + +describe InfluxDB::Client do + let(:subject) do + described_class.new( + "database", + { + host: "influxdb.test", + port: 9999, + username: "username", + password: "password", + time_precision: "s" + }.merge(args) + ) + end + + let(:args) { {} } + + ### TODO ### + + # describe "DELETE #delete_series" do + # it "removes a series" do + # stub_request(:delete, "http://influxdb.test:9999/db/database/series/foo").with( + # query: { u: "username", p: "password" } + # ) + + # expect(subject.delete_series("foo")).to be_a(Net::HTTPOK) + # end + # end + + # describe "GET #list_series" do + # it "returns a list of all series names" do + # data = [ + # { "name" => "list_series_result", + # "columns" => %w(time name), + # "points" => [[0, 'a'], [0, 'b']] + # } + # ] + + # stub_request(:get, "http://influxdb.test:9999/db/database/series").with( + # query: { u: "username", p: "password", q: "list series", time_precision: "s" } + # ).to_return( + # body: JSON.generate(data) + # ) + + # expect(subject.list_series).to eq %w(a b) + # end + # end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/query_shard_space_spec.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/query_shard_space_spec.rb new file mode 100644 index 0000000..e241aa2 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/query_shard_space_spec.rb @@ -0,0 +1,105 @@ +# TODO: support 0.9.x + +# require "spec_helper" +# require "json" + +# describe InfluxDB::Client do +# let(:subject) do +# described_class.new( +# "database", +# { +# host: "influxdb.test", +# port: 9999, +# username: "username", +# password: "password", +# time_precision: "s" +# }.merge(args) +# ) +# end + +# let(:args) { {} } + +# let(:url) { "http://influxdb.test:9999/cluster/shard_spaces" } +# let(:req_query) { { u: "username", p: "password" } } +# let(:req_body) { nil } +# let(:request_params) { { query: req_query, body: req_body } } +# let(:response) { { body: JSON.generate(shard_spaces), status: 200 } } +# let(:shard_spaces) { [subject.default_shard_space_options.merge("database" => "foo")] } + +# context "GET methods" do +# before { stub_request(:get, url).with(request_params).to_return(response) } + +# describe "GET #list_shard_spaces" do +# it 'returns OK' do +# expect(subject.list_shard_spaces).to eq shard_spaces +# end +# end + +# describe "GET #shard_space_info" do +# context "non-empty list" do +# it "returns shard space info" do +# expect(subject.shard_space_info('foo', 'default')).to eq shard_spaces.first +# end +# end + +# context "returns an empty list" do +# let(:shard_spaces) { [] } + +# it "returns no shard space" do +# expect(subject.shard_space_info('foo', 'default')).to be_nil +# end +# end +# end +# end + +# describe "POST #create_shard_space" do +# let(:url) { "http://influxdb.test:9999/cluster/shard_spaces/foo" } +# let(:req_body) { subject.default_shard_space_options } +# let(:response) { { status: 200 } } + +# before { stub_request(:post, url).with(request_params).to_return(response) } + +# it 'returns OK' do +# expect(subject.create_shard_space("foo", subject.default_shard_space_options)) +# .to be_a(Net::HTTPOK) +# end +# end + +# describe "DELETE #delete_shard_space" do +# let(:url) { "http://influxdb.test:9999/cluster/shard_spaces/foo/default" } +# let(:response) { { status: 200 } } +# before { stub_request(:delete, url).with(request_params).to_return(response) } + +# it 'returns OK' do +# expect(subject.delete_shard_space("foo", "default")).to be_a(Net::HTTPOK) +# end +# end + +# describe "#update_shard_space" do +# let(:post_url) { "http://influxdb.test:9999/cluster/shard_spaces/foo/default" } +# let(:post_request_params) do +# { +# query: req_query, +# body: subject.default_shard_space_options.merge("shardDuration" => "30d") +# } +# end + +# it 'gets the shard space and updates the shard space' do +# stub_request(:get, url).with(request_params).to_return(response) +# stub_request(:post, post_url).with(post_request_params) + +# expect(subject.update_shard_space("foo", "default", "shardDuration" => "30d")).to be_a(Net::HTTPOK) +# end +# end + +# describe "POST #configure_database" do +# let(:url) { "http://influxdb.test:9999/cluster/database_configs/foo" } +# let(:req_body) { subject.default_database_configuration } + +# before { stub_request(:post, url).with(request_params) } + +# it "returns OK" do +# expect(subject.configure_database("foo")).to be_a(Net::HTTPOK) +# end +# end +# end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/query_shard_spec.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/query_shard_spec.rb new file mode 100644 index 0000000..25af761 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/query_shard_spec.rb @@ -0,0 +1,43 @@ +require "spec_helper" +require "json" + +describe InfluxDB::Client do + let(:subject) do + described_class.new( + "database", + { + host: "influxdb.test", + port: 9999, + username: "username", + password: "password", + time_precision: "s" + }.merge(args) + ) + end + + let(:args) { {} } + + ### TODO ### + + # describe "GET #list_shards" do + # it "returns a list of shards" do + # shard_list = { "longTerm" => [], "shortTerm" => [] } + # stub_request(:get, "http://influxdb.test:9999/cluster/shards").with( + # query: { u: "username", p: "password" } + # ).to_return(body: JSON.generate(shard_list, status: 200)) + + # expect(subject.list_shards).to eq shard_list + # end + # end + + # describe "DELETE #delete_shard" do + # it "removes shard by id" do + # shard_id = 1 + # stub_request(:delete, "http://influxdb.test:9999/cluster/shards/#{shard_id}").with( + # query: { u: "username", p: "password" } + # ) + + # expect(subject.delete_shard(shard_id, [1, 2])).to be_a(Net::HTTPOK) + # end + # end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/query_user_spec.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/query_user_spec.rb new file mode 100644 index 0000000..fbd38b3 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/query_user_spec.rb @@ -0,0 +1,124 @@ +require "spec_helper" +require "json" + +describe InfluxDB::Client do + let(:subject) do + described_class.new( + "database", + { + host: "influxdb.test", + port: 9999, + username: "username", + password: "password", + time_precision: "s" + }.merge(args) + ) + end + + let(:args) { {} } + let(:query) { nil } + let(:response) { { "results" => [] } } + + before do + stub_request(:get, "http://influxdb.test:9999/query").with( + query: { u: "username", p: "password", q: query } + ).to_return(body: JSON.generate(response)) + end + + describe "#update user password" do + let(:user) { 'useruser' } + let(:pass) { 'passpass' } + let(:query) { "SET PASSWORD FOR #{user} = '#{pass}'" } + + it "should GET to update user password" do + expect(subject.update_user_password(user, pass)).to be_a(Net::HTTPOK) + end + end + + describe "#grant_user_privileges" do + let(:user) { 'useruser' } + let(:perm) { :write } + let(:db) { 'foo' } + let(:query) { "GRANT #{perm.to_s.upcase} ON #{db} TO #{user}" } + + it "should GET to grant privileges for a user on a database" do + expect(subject.grant_user_privileges(user, db, perm)).to be_a(Net::HTTPOK) + end + end + + describe "#grant_user_admin_privileges" do + let(:user) { 'useruser' } + let(:query) { "GRANT ALL PRIVILEGES TO #{user}" } + + it "should GET to grant privileges for a user on a database" do + expect(subject.grant_user_admin_privileges(user)).to be_a(Net::HTTPOK) + end + end + + describe "#revoke_user_privileges" do + let(:user) { 'useruser' } + let(:perm) { :write } + let(:db) { 'foo' } + let(:query) { "REVOKE #{perm.to_s.upcase} ON #{db} FROM #{user}" } + + it "should GET to revoke privileges from a user on a database" do + expect(subject.revoke_user_privileges(user, db, perm)).to be_a(Net::HTTPOK) + end + end + + describe "#create_database_user" do + let(:user) { 'useruser' } + let(:pass) { 'passpass' } + let(:db) { 'foo' } + let(:query) { "CREATE user #{user} WITH PASSWORD '#{pass}'; GRANT ALL ON #{db} TO #{user}" } + + context "without specifying permissions" do + it "should GET to create a new database user with all permissions" do + expect(subject.create_database_user(db, user, pass)).to be_a(Net::HTTPOK) + end + end + + context "with passing permission as argument" do + let(:permission) { :read } + let(:query) { "CREATE user #{user} WITH PASSWORD '#{pass}'; GRANT #{permission.to_s.upcase} ON #{db} TO #{user}" } + + it "should GET to create a new database user with permission set" do + expect(subject.create_database_user(db, user, pass, permissions: permission)).to be_a(Net::HTTPOK) + end + end + end + + describe "#delete_user" do + let(:user) { 'useruser' } + let(:query) { "DROP USER #{user}" } + + it "should GET to delete a user" do + expect(subject.delete_user(user)).to be_a(Net::HTTPOK) + end + end + + describe "#list_users" do + let(:response) { { "results" => [{ "series" => [{ "columns" => %w(user admin), "values" => [["dbadmin", true], ["foobar", false]] }] }] } } + let(:query) { "SHOW USERS" } + let(:expected_result) { [{ "username" => "dbadmin", "admin" => true }, { "username" => "foobar", "admin" => false }] } + + it "should GET a list of database users" do + expect(subject.list_users).to eq(expected_result) + end + end + + describe "#list_user_grants" do + let(:user) { 'useruser' } + let(:list_query) { "SHOW GRANTS FOR #{user}" } + + before do + stub_request(:get, "http://influxdb.test:9999/query") + .with(query: { u: "username", p: "password", q: list_query }) + .to_return(status: 200, body: "", headers: {}) + end + + it "should GET for a user" do + expect(subject.list_user_grants(user)).to be_a(Net::HTTPOK) + end + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/query_with_params_spec.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/query_with_params_spec.rb new file mode 100644 index 0000000..c449f6e --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/query_with_params_spec.rb @@ -0,0 +1,69 @@ +require "spec_helper" + +describe InfluxDB::Client do + let(:subject) do + described_class.new "database", { + host: "influxdb.test", + port: 9999, + username: "username", + password: "password", + time_precision: "s" + }.merge(args) + end + + let(:args) { {} } + + describe "#query with parameters" do + let(:query) { "SELECT value FROM requests_per_minute WHERE time > %{start}" } + let(:query_params) { { start: 1_437_019_900 } } + let(:query_compiled) { "SELECT value FROM requests_per_minute WHERE time > 1437019900" } + + let(:response) do + { "results" => [{ "series" => [{ "name" => "requests_per_minute", + "columns" => %w(time value) }] }] } + end + + before do + stub_request(:get, "http://influxdb.test:9999/query") + .with(query: { db: "database", precision: "s", u: "username", p: "password", q: query_compiled }) + .to_return(body: JSON.generate(response), status: 200) + end + + it "should handle responses with no values" do + # Some requests (such as trying to retrieve values from the future) + # return a result with no "values" key set. + expected_result = [{ "name" => "requests_per_minute", "tags" => nil, "values" => [] }] + expect(subject.query(query, params: query_params)).to eq(expected_result) + end + end + + describe "#query_with_params" do + let(:query) { "select * from foo where bar > %{param}" } + let(:compiled_query) { subject.builder.build(query, query_params) } + + context "with empty params hash" do + let(:query_params) { {} } + it { expect { compiled_query }.to raise_error ArgumentError } + end + + context "with empty params array" do + let(:query_params) { [] } + it { expect { compiled_query }.to raise_error ArgumentError } + end + + context "with empty params" do + let(:query_params) { nil } + it { expect { compiled_query }.to raise_error ArgumentError } + end + + context "with simple params" do + let(:query_params) { { param: 42 } } + it { expect(compiled_query).to eq "select * from foo where bar > 42" } + end + + context "string escaping" do + let(:query_params) { { param: "string" } } + it { expect(compiled_query).to eq "select * from foo where bar > 'string'" } + end + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/querying_issue_7000_spec.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/querying_issue_7000_spec.rb new file mode 100644 index 0000000..884a67a --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/querying_issue_7000_spec.rb @@ -0,0 +1,89 @@ +# This test spec addresses closed issue https://github.com/influxdata/influxdb/issues/7000 where +# it was confirmed that when chunking is enabled, the InfluxDB REST API returns multi-line JSON. + +require "spec_helper" +require "json" + +describe InfluxDB::Client do + let(:subject) do + described_class.new "database", { + host: "influxdb.test", + port: 9999, + username: "username", + password: "password", + time_precision: "s" + }.merge(args) + end + + let(:args) { {} } + let(:database) { subject.config.database } + let(:extra_params) { {} } + let(:response) { "" } + + before do + stub_request(:get, "http://influxdb.test:9999/query") + .with(query: { q: query, u: "username", p: "password", precision: 's', db: database }.merge(extra_params)) + .to_return(body: response) + end + + describe "#query" do + context "with series with different tags (multi-line)" do + let(:args) { { chunk_size: 100 } } + let(:extra_params) { { chunked: "true", chunk_size: "100" } } + + let(:response_line_1) do + { "results" => [{ "series" => [{ "name" => "cpu", "tags" => { "region" => "pl" }, "columns" => %w(time temp value), "values" => [["2015-07-07T15:13:04Z", 34, 0.343443]] }] }] } + end + let(:response_line_2) do + { "results" => [{ "series" => [{ "name" => "cpu", "tags" => { "region" => "us" }, "columns" => %w(time temp value), "values" => [["2015-07-07T14:58:37Z", 92, 0.3445], ["2015-07-07T14:59:09Z", 68, 0.8787]] }] }] } + end + let(:response) do + JSON.generate(response_line_1) + "\n" + JSON.generate(response_line_2) + end + let(:expected_result) do + [{ "name" => "cpu", "tags" => { "region" => "pl" }, + "values" => [{ "time" => "2015-07-07T15:13:04Z", "temp" => 34, "value" => 0.343443 }] }, + { "name" => "cpu", "tags" => { "region" => "us" }, + "values" => [{ "time" => "2015-07-07T14:58:37Z", "temp" => 92, "value" => 0.3445 }, + { "time" => "2015-07-07T14:59:09Z", "temp" => 68, "value" => 0.8787 }] }] + end + let(:query) { 'SELECT * FROM cpu' } + + it "should return array with 2 elements grouped by tags" do + expect(subject.query(query)).to eq(expected_result) + end + end + + context "with multiple series with different tags" do + let(:args) { { chunk_size: 100 } } + let(:extra_params) { { chunked: "true", chunk_size: "100" } } + + let(:response_line_1) do + { "results" => [{ "series" => [{ "name" => "access_times.service_1", "tags" => { "code" => "200", "result" => "failure", "status" => "OK" }, "columns" => %w(time value), "values" => [["2015-07-08T07:15:22Z", 327]] }] }] } + end + let(:response_line_2) do + { "results" => [{ "series" => [{ "name" => "access_times.service_1", "tags" => { "code" => "500", "result" => "failure", "status" => "Internal Server Error" }, "columns" => %w(time value), "values" => [["2015-07-08T06:15:22Z", 873]] }] }] } + end + let(:response_line_3) do + { "results" => [{ "series" => [{ "name" => "access_times.service_2", "tags" => { "code" => "200", "result" => "failure", "status" => "OK" }, "columns" => %w(time value), "values" => [["2015-07-08T07:15:22Z", 943]] }] }] } + end + let(:response_line_4) do + { "results" => [{ "series" => [{ "name" => "access_times.service_2", "tags" => { "code" => "500", "result" => "failure", "status" => "Internal Server Error" }, "columns" => %w(time value), "values" => [["2015-07-08T06:15:22Z", 606]] }] }] } + end + let(:response) do + JSON.generate(response_line_1) + "\n" + JSON.generate(response_line_2) + "\n" + JSON.generate(response_line_3) + "\n" + JSON.generate(response_line_4) + end + let(:expected_result) do + [{ "name" => "access_times.service_1", "tags" => { "code" => "200", "result" => "failure", "status" => "OK" }, "values" => [{ "time" => "2015-07-08T07:15:22Z", "value" => 327 }] }, + { "name" => "access_times.service_1", "tags" => { "code" => "500", "result" => "failure", "status" => "Internal Server Error" }, "values" => [{ "time" => "2015-07-08T06:15:22Z", "value" => 873 }] }, + { "name" => "access_times.service_2", "tags" => { "code" => "200", "result" => "failure", "status" => "OK" }, "values" => [{ "time" => "2015-07-08T07:15:22Z", "value" => 943 }] }, + { "name" => "access_times.service_2", "tags" => { "code" => "500", "result" => "failure", "status" => "Internal Server Error" }, "values" => [{ "time" => "2015-07-08T06:15:22Z", "value" => 606 }] }] + end + let(:query) { "SELECT * FROM /access_times.*/" } + + it "should return array with 4 elements grouped by name and tags" do + expect(subject.query(query)).to eq(expected_result) + end + end + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/querying_spec.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/querying_spec.rb new file mode 100644 index 0000000..bcccbaf --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/querying_spec.rb @@ -0,0 +1,265 @@ +require "spec_helper" +require "json" + +describe InfluxDB::Client do + let(:subject) do + described_class.new "database", { + host: "influxdb.test", + port: 9999, + username: "username", + password: "password", + time_precision: "s" + }.merge(args) + end + + let(:args) { {} } + let(:database) { subject.config.database } + let(:extra_params) { {} } + let(:response) {} + + before do + stub_request(:get, "http://influxdb.test:9999/query") + .with(query: { q: query, u: "username", p: "password", precision: 's', db: database }.merge(extra_params)) + .to_return(body: JSON.generate(response)) + end + + describe "#query" do + context "with single series with multiple points" do + let(:response) do + { "results" => [{ "series" => [{ "name" => "cpu", "tags" => { "region" => "us" }, + "columns" => %w(time temp value), + "values" => [["2015-07-07T14:58:37Z", 92, 0.3445], ["2015-07-07T14:59:09Z", 68, 0.8787]] }] }] } + end + let(:expected_result) do + [{ "name" => "cpu", "tags" => { "region" => "us" }, + "values" => [{ "time" => "2015-07-07T14:58:37Z", "temp" => 92, "value" => 0.3445 }, + { "time" => "2015-07-07T14:59:09Z", "temp" => 68, "value" => 0.8787 }] }] + end + let(:query) { 'SELECT * FROM cpu' } + + it "should return array with single hash containing multiple values" do + expect(subject.query(query)).to eq(expected_result) + end + end + + context "with series with different tags" do + let(:response) do + { "results" => [{ "series" => [{ "name" => "cpu", "tags" => { "region" => "pl" }, "columns" => %w(time temp value), "values" => [["2015-07-07T15:13:04Z", 34, 0.343443]] }, + { "name" => "cpu", "tags" => { "region" => "us" }, "columns" => %w(time temp value), "values" => [["2015-07-07T14:58:37Z", 92, 0.3445], ["2015-07-07T14:59:09Z", 68, 0.8787]] }] }] } + end + let(:expected_result) do + [{ "name" => "cpu", "tags" => { "region" => "pl" }, + "values" => [{ "time" => "2015-07-07T15:13:04Z", "temp" => 34, "value" => 0.343443 }] }, + { "name" => "cpu", "tags" => { "region" => "us" }, + "values" => [{ "time" => "2015-07-07T14:58:37Z", "temp" => 92, "value" => 0.3445 }, + { "time" => "2015-07-07T14:59:09Z", "temp" => 68, "value" => 0.8787 }] }] + end + let(:query) { 'SELECT * FROM cpu' } + + it "should return array with 2 elements grouped by tags" do + expect(subject.query(query)).to eq(expected_result) + end + end + + context "with multiple series with different tags" do + let(:response) do + { "results" => [{ "series" => [{ "name" => "access_times.service_1", "tags" => { "code" => "200", "result" => "failure", "status" => "OK" }, "columns" => %w(time value), "values" => [["2015-07-08T07:15:22Z", 327]] }, + { "name" => "access_times.service_1", "tags" => { "code" => "500", "result" => "failure", "status" => "Internal Server Error" }, "columns" => %w(time value), "values" => [["2015-07-08T06:15:22Z", 873]] }, + { "name" => "access_times.service_2", "tags" => { "code" => "200", "result" => "failure", "status" => "OK" }, "columns" => %w(time value), "values" => [["2015-07-08T07:15:22Z", 943]] }, + { "name" => "access_times.service_2", "tags" => { "code" => "500", "result" => "failure", "status" => "Internal Server Error" }, "columns" => %w(time value), "values" => [["2015-07-08T06:15:22Z", 606]] }] }] } + end + let(:expected_result) do + [{ "name" => "access_times.service_1", "tags" => { "code" => "200", "result" => "failure", "status" => "OK" }, "values" => [{ "time" => "2015-07-08T07:15:22Z", "value" => 327 }] }, + { "name" => "access_times.service_1", "tags" => { "code" => "500", "result" => "failure", "status" => "Internal Server Error" }, "values" => [{ "time" => "2015-07-08T06:15:22Z", "value" => 873 }] }, + { "name" => "access_times.service_2", "tags" => { "code" => "200", "result" => "failure", "status" => "OK" }, "values" => [{ "time" => "2015-07-08T07:15:22Z", "value" => 943 }] }, + { "name" => "access_times.service_2", "tags" => { "code" => "500", "result" => "failure", "status" => "Internal Server Error" }, "values" => [{ "time" => "2015-07-08T06:15:22Z", "value" => 606 }] }] + end + let(:query) { "SELECT * FROM /access_times.*/" } + + it "should return array with 4 elements grouped by name and tags" do + expect(subject.query(query)).to eq(expected_result) + end + end + + context "with multiple series for explicit value only" do + let(:response) do + { "results" => [{ "series" => [{ "name" => "access_times.service_1", "columns" => %w(time value), "values" => [["2015-07-08T06:15:22Z", 873], ["2015-07-08T07:15:22Z", 327]] }, + { "name" => "access_times.service_2", "columns" => %w(time value), "values" => [["2015-07-08T06:15:22Z", 606], ["2015-07-08T07:15:22Z", 943]] }] }] } + end + let(:expected_result) do + [{ "name" => "access_times.service_1", "tags" => nil, "values" => [{ "time" => "2015-07-08T06:15:22Z", "value" => 873 }, { "time" => "2015-07-08T07:15:22Z", "value" => 327 }] }, + { "name" => "access_times.service_2", "tags" => nil, "values" => [{ "time" => "2015-07-08T06:15:22Z", "value" => 606 }, { "time" => "2015-07-08T07:15:22Z", "value" => 943 }] }] + end + let(:query) { "SELECT value FROM /access_times.*/" } + + it "should return array with 2 elements grouped by name only and no tags" do + expect(subject.query(query)).to eq(expected_result) + end + end + + context "with a block" do + let(:response) do + { "results" => [{ "series" => [{ "name" => "cpu", "tags" => { "region" => "pl" }, "columns" => %w(time temp value), "values" => [["2015-07-07T15:13:04Z", 34, 0.343443]] }, + { "name" => "cpu", "tags" => { "region" => "us" }, "columns" => %w(time temp value), "values" => [["2015-07-07T14:58:37Z", 92, 0.3445], ["2015-07-07T14:59:09Z", 68, 0.8787]] }] }] } + end + + let(:expected_result) do + [{ "name" => "cpu", "tags" => { "region" => "pl" }, + "values" => [{ "time" => "2015-07-07T15:13:04Z", "temp" => 34, "value" => 0.343443 }] }, + { "name" => "cpu", "tags" => { "region" => "us" }, + "values" => [{ "time" => "2015-07-07T14:58:37Z", "temp" => 92, "value" => 0.3445 }, + { "time" => "2015-07-07T14:59:09Z", "temp" => 68, "value" => 0.8787 }] }] + end + let(:query) { 'SELECT * FROM cpu' } + + it "should accept a block and yield name, tags and points" do + results = [] + subject.query(query) do |name, tags, points| + results << { 'name' => name, 'tags' => tags, 'values' => points } + end + expect(results).to eq(expected_result) + end + end + + context "with epoch set to seconds" do + let(:args) { { epoch: 's' } } + let(:extra_params) { { epoch: 's' } } + + let(:response) do + { "results" => [{ "series" => [{ "name" => "cpu", "tags" => { "region" => "pl" }, "columns" => %w(time temp value), "values" => [[1_438_580_576, 34, 0.343443]] }, + { "name" => "cpu", "tags" => { "region" => "us" }, "columns" => %w(time temp value), "values" => [[1_438_612_976, 92, 0.3445], [1_438_612_989, 68, 0.8787]] }] }] } + end + let(:expected_result) do + [{ "name" => "cpu", "tags" => { "region" => "pl" }, + "values" => [{ "time" => 1_438_580_576, "temp" => 34, "value" => 0.343443 }] }, + { "name" => "cpu", "tags" => { "region" => "us" }, + "values" => [{ "time" => 1_438_612_976, "temp" => 92, "value" => 0.3445 }, + { "time" => 1_438_612_989, "temp" => 68, "value" => 0.8787 }] }] + end + let(:query) { 'SELECT * FROM cpu' } + + it "should return results with integer timestamp" do + expect(subject.query(query)).to eq(expected_result) + end + end + + context "with chunk_size set to 100" do + let(:args) { { chunk_size: 100 } } + let(:extra_params) { { chunked: "true", chunk_size: "100" } } + + let(:response) do + { "results" => [{ "series" => [{ "name" => "cpu", "tags" => { "region" => "pl" }, "columns" => %w(time temp value), "values" => [[1_438_580_576, 34, 0.343443]] }] }] } + end + let(:expected_result) do + [{ "name" => "cpu", "tags" => { "region" => "pl" }, "values" => [{ "time" => 1_438_580_576, "temp" => 34, "value" => 0.343443 }] }] + end + let(:query) { 'SELECT * FROM cpu' } + + it "should set 'chunked' and 'chunk_size' parameters" do + expect(subject.query(query)).to eq(expected_result) + end + end + + context "with database" do + let(:extra_params) { { db: 'overriden_db' } } + let(:response) do + { "results" => [{ "series" => [{ "name" => "cpu", "tags" => { "region" => "us" }, + "columns" => %w(time temp value), + "values" => [["2015-07-07T14:58:37Z", 92, 0.3445], ["2015-07-07T14:59:09Z", 68, 0.8787]] }] }] } + end + let(:expected_result) do + [{ "name" => "cpu", "tags" => { "region" => "us" }, + "values" => [{ "time" => "2015-07-07T14:58:37Z", "temp" => 92, "value" => 0.3445 }, + { "time" => "2015-07-07T14:59:09Z", "temp" => 68, "value" => 0.8787 }] }] + end + let(:query) { 'SELECT * FROM cpu' } + + it "should return array with single hash containing multiple values" do + expect(subject.query(query, database: 'overriden_db')).to eq(expected_result) + end + end + end + + describe "multiple select queries" do + context "with single series with multiple points" do + let(:response) do + { "results" => [{ "series" => [{ "name" => "cpu", "tags" => { "region" => "us" }, + "columns" => %w(time temp value), + "values" => [["2015-07-07T14:58:37Z", 92, 0.3445], ["2015-07-07T14:59:09Z", 68, 0.8787]] }] }, + { "series" => [{ "name" => "memory", "tags" => { "region" => "us" }, + "columns" => %w(time free total), + "values" => [["2015-07-07T14:58:37Z", 96_468_992, 134_217_728], ["2015-07-07T14:59:09Z", 71_303_168, 134_217_728]] }] }] } + end + let(:expected_result) do + [{ "name" => "cpu", "tags" => { "region" => "us" }, + "values" => [{ "time" => "2015-07-07T14:58:37Z", "temp" => 92, "value" => 0.3445 }, + { "time" => "2015-07-07T14:59:09Z", "temp" => 68, "value" => 0.8787 }] }, + { "name" => "memory", "tags" => { "region" => "us" }, + "values" => [{ "time" => "2015-07-07T14:58:37Z", "free" => 92 * 2**20, "total" => 128 * 2**20 }, + { "time" => "2015-07-07T14:59:09Z", "free" => 68 * 2**20, "total" => 128 * 2**20 }] }] + end + let(:query) { 'SELECT * FROM cpu; SELECT * FROM memory' } + + it "should return array with single hash containing multiple values" do + expect(subject.query(query)).to eq(expected_result) + end + end + + context "with series with different tags" do + let(:response) do + { "results" => [{ "series" => [{ "name" => "cpu", "tags" => { "region" => "pl" }, "columns" => %w(time temp value), "values" => [["2015-07-07T15:13:04Z", 34, 0.343443]] }, + { "name" => "cpu", "tags" => { "region" => "us" }, "columns" => %w(time temp value), "values" => [["2015-07-07T14:58:37Z", 92, 0.3445], ["2015-07-07T14:59:09Z", 68, 0.8787]] }] }, + { "series" => [{ "name" => "memory", "tags" => { "region" => "pl" }, "columns" => %w(time free total), "values" => [["2015-07-07T15:13:04Z", 35_651_584, 134_217_728]] }, + { "name" => "memory", "tags" => { "region" => "us" }, "columns" => %w(time free total), "values" => [["2015-07-07T14:58:37Z", 96_468_992, 134_217_728], ["2015-07-07T14:59:09Z", 71_303_168, 134_217_728]] }] }] } + end + let(:expected_result) do + [{ "name" => "cpu", "tags" => { "region" => "pl" }, + "values" => [{ "time" => "2015-07-07T15:13:04Z", "temp" => 34, "value" => 0.343443 }] }, + { "name" => "cpu", "tags" => { "region" => "us" }, + "values" => [{ "time" => "2015-07-07T14:58:37Z", "temp" => 92, "value" => 0.3445 }, + { "time" => "2015-07-07T14:59:09Z", "temp" => 68, "value" => 0.8787 }] }, + { "name" => "memory", "tags" => { "region" => "pl" }, + "values" => [{ "time" => "2015-07-07T15:13:04Z", "free" => 34 * 2**20, "total" => 128 * 2**20 }] }, + { "name" => "memory", "tags" => { "region" => "us" }, + "values" => [{ "time" => "2015-07-07T14:58:37Z", "free" => 92 * 2**20, "total" => 128 * 2**20 }, + { "time" => "2015-07-07T14:59:09Z", "free" => 68 * 2**20, "total" => 128 * 2**20 }] }] + end + let(:query) { 'SELECT * FROM cpu; SELECT * FROM memory' } + + it "should return array with 2 elements grouped by tags" do + expect(subject.query(query)).to eq(expected_result) + end + end + + context "with a block" do + let(:response) do + { "results" => [{ "series" => [{ "name" => "cpu", "tags" => { "region" => "pl" }, "columns" => %w(time temp value), "values" => [["2015-07-07T15:13:04Z", 34, 0.343443]] }, + { "name" => "cpu", "tags" => { "region" => "us" }, "columns" => %w(time temp value), "values" => [["2015-07-07T14:58:37Z", 92, 0.3445], ["2015-07-07T14:59:09Z", 68, 0.8787]] }] }, + { "series" => [{ "name" => "memory", "tags" => { "region" => "pl" }, "columns" => %w(time free total), "values" => [["2015-07-07T15:13:04Z", 35_651_584, 134_217_728]] }, + { "name" => "memory", "tags" => { "region" => "us" }, "columns" => %w(time free total), "values" => [["2015-07-07T14:58:37Z", 96_468_992, 134_217_728], ["2015-07-07T14:59:09Z", 71_303_168, 134_217_728]] }] }] } + end + + let(:expected_result) do + [{ "name" => "cpu", "tags" => { "region" => "pl" }, + "values" => [{ "time" => "2015-07-07T15:13:04Z", "temp" => 34, "value" => 0.343443 }] }, + { "name" => "cpu", "tags" => { "region" => "us" }, + "values" => [{ "time" => "2015-07-07T14:58:37Z", "temp" => 92, "value" => 0.3445 }, + { "time" => "2015-07-07T14:59:09Z", "temp" => 68, "value" => 0.8787 }] }, + { "name" => "memory", "tags" => { "region" => "pl" }, + "values" => [{ "time" => "2015-07-07T15:13:04Z", "free" => 34 * 2**20, "total" => 128 * 2**20 }] }, + { "name" => "memory", "tags" => { "region" => "us" }, + "values" => [{ "time" => "2015-07-07T14:58:37Z", "free" => 92 * 2**20, "total" => 128 * 2**20 }, + { "time" => "2015-07-07T14:59:09Z", "free" => 68 * 2**20, "total" => 128 * 2**20 }] }] + end + let(:query) { 'SELECT * FROM cpu; SELECT * FROM memory' } + + it "should accept a block and yield name, tags and points" do + results = [] + subject.query(query) do |name, tags, points| + results << { 'name' => name, 'tags' => tags, 'values' => points } + end + expect(results).to eq(expected_result) + end + end + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/retry_requests_spec.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/retry_requests_spec.rb new file mode 100644 index 0000000..69af5e4 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/retry_requests_spec.rb @@ -0,0 +1,104 @@ +require "spec_helper" +require "json" + +describe InfluxDB::Client do + let(:client) do + described_class.new( + "database", + { + host: "influxdb.test", + port: 9999, + username: "username", + password: "password", + time_precision: "s" + }.merge(args) + ) + end + + let(:args) { {} } + + let(:database) { client.config.database } + + describe "retrying requests" do + let(:series) { "cpu" } + let(:data) do + { tags: { region: 'us', host: 'server_1' }, + values: { temp: 88, value: 54 } } + end + let(:body) do + InfluxDB::PointValue.new(data.merge(series: series)).dump + end + + subject { client.write_point(series, data) } + + before do + allow(client).to receive(:log) + stub_request(:post, "http://influxdb.test:9999/write").with( + query: { u: "username", p: "password", precision: 's', db: database }, + headers: { "Content-Type" => "application/octet-stream" }, + body: body + ).to_raise(Timeout::Error) + end + + it "raises when stopped" do + client.stop! + expect(client).not_to receive(:sleep) + expect { subject }.to raise_error(InfluxDB::ConnectionError) do |e| + expect(e.cause).to be_an_instance_of(Timeout::Error) + end + end + + context "when retry is 0" do + let(:args) { { retry: 0 } } + it "raise error directly" do + expect(client).not_to receive(:sleep) + expect { subject }.to raise_error(InfluxDB::ConnectionError) do |e| + expect(e.cause).to be_an_instance_of(Timeout::Error) + end + end + end + + context "when retry is 'n'" do + let(:args) { { retry: 3 } } + + it "raise error after 'n' attemps" do + expect(client).to receive(:sleep).exactly(3).times + expect { subject }.to raise_error(InfluxDB::ConnectionError) do |e| + expect(e.cause).to be_an_instance_of(Timeout::Error) + end + end + end + + context "when retry is -1" do + let(:args) { { retry: -1 } } + before do + stub_request(:post, "http://influxdb.test:9999/write") + .with( + query: { u: "username", p: "password", precision: 's', db: database }, + headers: { "Content-Type" => "application/octet-stream" }, + body: body + ) + .to_raise(Timeout::Error).then + .to_raise(Timeout::Error).then + .to_raise(Timeout::Error).then + .to_raise(Timeout::Error).then + .to_return(status: 204) + end + + it "keep trying until get the connection" do + expect(client).to receive(:sleep).exactly(4).times + expect { subject }.to_not raise_error + end + end + + it "raise an exception if the server didn't return 200" do + stub_request(:post, "http://influxdb.test:9999/write").with( + query: { u: "username", p: "password", precision: 's', db: database }, + headers: { "Content-Type" => "application/octet-stream" }, + body: body + ).to_return(status: 401) + + expect { client.write_point(series, data) }.to raise_error(InfluxDB::AuthenticationError) + end + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/udp_client_spec.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/udp_client_spec.rb new file mode 100644 index 0000000..3aa4f9c --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/udp_client_spec.rb @@ -0,0 +1,21 @@ +require "spec_helper" + +describe InfluxDB::Client do + let(:client) { described_class.new(udp: { host: "localhost", port: 44_444 }) } + + specify { expect(client.writer).to be_a(InfluxDB::Writer::UDP) } + + describe "#write" do + let(:message) { 'responses,region=eu value=5i' } + + it "sends a UPD packet" do + s = UDPSocket.new + s.bind("localhost", 44_444) + + client.write_point("responses", values: { value: 5 }, tags: { region: 'eu' }) + + rec_message = s.recvfrom(30).first + expect(rec_message).to eq message + end + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/write_points_spec.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/write_points_spec.rb new file mode 100644 index 0000000..e4c28cb --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/write_points_spec.rb @@ -0,0 +1,184 @@ +require "spec_helper" +require "json" + +describe InfluxDB::Client do + let(:subject) do + described_class.new "database", { + host: "influxdb.test", + port: 9999, + username: "username", + password: "password", + time_precision: "s" + }.merge(args) + end + + let(:args) { {} } + + let(:database) { subject.config.database } + + describe "#write_point" do + let(:series) { "cpu" } + let(:data) do + { tags: { region: 'us', host: 'server_1' }, + values: { temp: 88, value: 54 } } + end + let(:body) do + InfluxDB::PointValue.new(data.merge(series: series)).dump + end + + before do + stub_request(:post, "http://influxdb.test:9999/write").with( + query: { u: "username", p: "password", precision: 's', db: database }, + headers: { "Content-Type" => "application/octet-stream" }, + body: body + ).to_return(status: 204) + end + + it "should POST to add single point" do + expect(subject.write_point(series, data)).to be_a(Net::HTTPNoContent) + end + + it "should not mutate data object" do + original_data = data + subject.write_point(series, data) + expect(data[:series]).to be_nil + expect(original_data).to eql(data) + end + end + + describe "#write_points" do + context "with multiple series" do + let(:data) do + [{ series: 'cpu', + tags: { region: 'us', host: 'server_1' }, + values: { temp: 88, value: 54 } }, + { series: 'gpu', + tags: { region: 'uk', host: 'server_5' }, + values: { value: 0.5435345 } }] + end + let(:body) do + data.map do |point| + InfluxDB::PointValue.new(point).dump + end.join("\n") + end + + before do + stub_request(:post, "http://influxdb.test:9999/write").with( + query: { u: "username", p: "password", precision: 's', db: database }, + headers: { "Content-Type" => "application/octet-stream" }, + body: body + ).to_return(status: 204) + end + + it "should POST multiple points" do + expect(subject.write_points(data)).to be_a(Net::HTTPNoContent) + end + end + + context "with no tags" do + let(:data) do + [{ series: 'cpu', + values: { temp: 88, value: 54 } }, + { series: 'gpu', + values: { value: 0.5435345 } }] + end + let(:body) do + data.map do |point| + InfluxDB::PointValue.new(point).dump + end.join("\n") + end + + before do + stub_request(:post, "http://influxdb.test:9999/write").with( + query: { u: "username", p: "password", precision: 's', db: database }, + headers: { "Content-Type" => "application/octet-stream" }, + body: body + ).to_return(status: 204) + end + + it "should POST multiple points" do + expect(subject.write_points(data)).to be_a(Net::HTTPNoContent) + end + end + + context "with time precision set to milisceconds" do + let(:data) do + [{ series: 'cpu', + values: { temp: 88, value: 54 }, + timestamp: (Time.now.to_f * 1000).to_i }, + { series: 'gpu', + values: { value: 0.5435345 }, + timestamp: (Time.now.to_f * 1000).to_i }] + end + + let(:body) do + data.map do |point| + InfluxDB::PointValue.new(point).dump + end.join("\n") + end + + before do + stub_request(:post, "http://influxdb.test:9999/write").with( + query: { u: "username", p: "password", precision: 'ms', db: database }, + headers: { "Content-Type" => "application/octet-stream" }, + body: body + ).to_return(status: 204) + end + it "should POST multiple points" do + expect(subject.write_points(data, 'ms')).to be_a(Net::HTTPNoContent) + end + end + + context "with retention policy" do + let(:data) do + [{ series: 'cpu', + values: { temp: 88, value: 54 } }, + { series: 'gpu', + values: { value: 0.5435345 } }] + end + + let(:body) do + data.map do |point| + InfluxDB::PointValue.new(point).dump + end.join("\n") + end + + before do + stub_request(:post, "http://influxdb.test:9999/write").with( + query: { u: "username", p: "password", precision: 's', db: database, rp: 'rp_1_hour' }, + headers: { "Content-Type" => "application/octet-stream" }, + body: body + ).to_return(status: 204) + end + it "should POST multiple points" do + expect(subject.write_points(data, nil, 'rp_1_hour')).to be_a(Net::HTTPNoContent) + end + end + + context "with database" do + let(:data) do + [{ series: 'cpu', + values: { temp: 88, value: 54 } }, + { series: 'gpu', + values: { value: 0.5435345 } }] + end + + let(:body) do + data.map do |point| + InfluxDB::PointValue.new(point).dump + end.join("\n") + end + + before do + stub_request(:post, "http://influxdb.test:9999/write").with( + query: { u: "username", p: "password", precision: 's', db: 'overriden_db' }, + headers: { "Content-Type" => "application/octet-stream" }, + body: body + ).to_return(status: 204) + end + it "should POST multiple points" do + expect(subject.write_points(data, nil, nil, 'overriden_db')).to be_a(Net::HTTPNoContent) + end + end + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/client_spec.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/client_spec.rb new file mode 100644 index 0000000..d1b0e52 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/client_spec.rb @@ -0,0 +1,120 @@ +require "spec_helper" +require "json" + +describe InfluxDB::Client do + let(:subject) do + described_class.new( + "database", + { + host: "influxdb.test", + port: 9999, + username: "username", + password: "password", + time_precision: "s" + }.merge(args) + ) + end + + let(:args) { {} } + + specify { is_expected.not_to be_stopped } + + context "with basic auth" do + let(:args) { { auth_method: 'basic_auth' } } + + let(:credentials) { "username:password" } + let(:auth_header) { { "Authorization" => "Basic " + Base64.encode64(credentials).chomp } } + + let(:stub_url) { "http://influxdb.test:9999/" } + let(:url) { subject.send(:full_url, '/') } + + it "GET" do + stub_request(:get, stub_url).with(headers: auth_header).to_return(body: '[]') + expect(subject.get(url, parse: true)).to eq [] + end + + it "POST" do + stub_request(:post, stub_url).with(headers: auth_header).to_return(status: 204) + expect(subject.post(url, {})).to be_a(Net::HTTPNoContent) + end + end + + describe "#full_url" do + it "returns String" do + expect(subject.send(:full_url, "/unknown")).to be_a String + end + + it "escapes params" do + url = subject.send(:full_url, "/unknown", value: ' !@#$%^&*()/\\_+-=?|`~') + expect(url).to include("value=+%21%40%23%24%25%5E%26%2A%28%29%2F%5C_%2B-%3D%3F%7C%60%7E") + end + + context "with prefix" do + let(:args) { { prefix: '/dev' } } + + it "returns path with prefix" do + expect(subject.send(:full_url, "/series")).to start_with("/dev") + end + end + end + + describe "GET #ping" do + it "returns OK" do + stub_request(:get, "http://influxdb.test:9999/ping") + .to_return(status: 204) + + expect(subject.ping).to be_a(Net::HTTPNoContent) + end + + context "with prefix" do + let(:args) { { prefix: '/dev' } } + + it "returns OK with prefix" do + stub_request(:get, "http://influxdb.test:9999/dev/ping") + .to_return(status: 204) + + expect(subject.ping).to be_a(Net::HTTPNoContent) + end + end + end + + describe "GET #version" do + it "returns 1.1.1" do + stub_request(:get, "http://influxdb.test:9999/ping") + .to_return(status: 204, headers: { 'x-influxdb-version' => '1.1.1' }) + + expect(subject.version).to eq('1.1.1') + end + + context "with prefix" do + let(:args) { { prefix: '/dev' } } + + it "returns 1.1.1 with prefix" do + stub_request(:get, "http://influxdb.test:9999/dev/ping") + .to_return(status: 204, headers: { 'x-influxdb-version' => '1.1.1' }) + + expect(subject.version).to eq('1.1.1') + end + end + end + + describe "Load balancing" do + let(:args) { { hosts: hosts } } + let(:hosts) do + [ + "influxdb.test0", + "influxdb.test1", + "influxdb.test2" + ] + end + let(:cycle) { 3 } + let!(:stubs) do + hosts.map { |host| stub_request(:get, "http://#{host}:9999/ping").to_return(status: 204) } + end + + it "balance requests" do + (hosts.size * cycle).times { subject.ping } + stubs.cycle(cycle) { |stub| expect(stub).to have_been_requested.times(cycle) } + end + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/config_spec.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/config_spec.rb new file mode 100644 index 0000000..8c543db --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/config_spec.rb @@ -0,0 +1,127 @@ +require 'spec_helper' + +describe InfluxDB::Config do + let(:conf) do + InfluxDB::Client.new(*args).config + end + + let(:args) { {} } + + context "with no parameters specified" do + specify { expect(conf.database).to be_nil } + specify { expect(conf.hosts).to eq ["localhost"] } + specify { expect(conf.port).to eq 8086 } + specify { expect(conf.username).to eq "root" } + specify { expect(conf.password).to eq "root" } + specify { expect(conf.use_ssl).to be_falsey } + specify { expect(conf.time_precision).to eq "s" } + specify { expect(conf.auth_method).to eq "params" } + specify { expect(conf.denormalize).to be_truthy } + specify { expect(conf).not_to be_udp } + specify { expect(conf).not_to be_async } + specify { expect(conf.epoch).to be_falsey } + end + + context "with no database specified" do + let(:args) do + [{ + host: "host", + port: "port", + username: "username", + password: "password", + time_precision: "m" + }] + end + + specify { expect(conf.database).to be_nil } + specify { expect(conf.hosts).to eq ["host"] } + specify { expect(conf.port).to eq "port" } + specify { expect(conf.username).to eq "username" } + specify { expect(conf.password).to eq "password" } + specify { expect(conf.time_precision).to eq "m" } + specify { expect(conf.epoch).to be_falsey } + end + + context "with both a database and options specified" do + let(:args) do + [ + "database", + host: "host", + port: "port", + username: "username", + password: "password", + time_precision: "m" + ] + end + + specify { expect(conf.database).to eq "database" } + specify { expect(conf.hosts).to eq ["host"] } + specify { expect(conf.port).to eq "port" } + specify { expect(conf.username).to eq "username" } + specify { expect(conf.password).to eq "password" } + specify { expect(conf.time_precision).to eq "m" } + specify { expect(conf.epoch).to be_falsey } + end + + context "with ssl option specified" do + let(:args) { [{ use_ssl: true }] } + + specify { expect(conf.database).to be_nil } + specify { expect(conf.hosts).to eq ["localhost"] } + specify { expect(conf.port).to eq 8086 } + specify { expect(conf.username).to eq "root" } + specify { expect(conf.password).to eq "root" } + specify { expect(conf.use_ssl).to be_truthy } + end + + context "with multiple hosts specified" do + let(:args) { [{ hosts: ["1.1.1.1", "2.2.2.2"] }] } + + specify { expect(conf.database).to be_nil } + specify { expect(conf.port).to eq 8086 } + specify { expect(conf.username).to eq "root" } + specify { expect(conf.password).to eq "root" } + specify { expect(conf.hosts).to eq ["1.1.1.1", "2.2.2.2"] } + end + + context "with auth_method basic auth specified" do + let(:args) { [{ auth_method: 'basic_auth' }] } + + specify { expect(conf.database).to be_nil } + specify { expect(conf.hosts).to eq ["localhost"] } + specify { expect(conf.port).to eq 8086 } + specify { expect(conf.username).to eq "root" } + specify { expect(conf.password).to eq "root" } + specify { expect(conf.auth_method).to eq "basic_auth" } + end + + context "with udp specified with params" do + let(:args) { [{ udp: { host: 'localhost', port: 4444 } }] } + + specify { expect(conf).to be_udp } + end + + context "with udp specified as true" do + let(:args) { [{ udp: true }] } + + specify { expect(conf).to be_udp } + end + + context "with async specified with params" do + let(:args) { [{ async: { max_queue: 20_000 } }] } + + specify { expect(conf).to be_async } + end + + context "with async specified as true" do + let(:args) { [{ async: true }] } + + specify { expect(conf).to be_async } + end + + context "with epoch specified as seconds" do + let(:args) { [{ epoch: 's' }] } + + specify { expect(conf.epoch).to eq 's' } + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/logging_spec.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/logging_spec.rb new file mode 100644 index 0000000..804808f --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/logging_spec.rb @@ -0,0 +1,51 @@ +require 'spec_helper' +require 'logger' + +describe InfluxDB::Logging do + class LoggerTest # :nodoc: + include InfluxDB::Logging + + def write_to_log(level, message) + log(level, message) + end + end + + around do |example| + old_logger = InfluxDB::Logging.logger + example.call + InfluxDB::Logging.logger = old_logger + end + + it "has a default logger" do + expect(InfluxDB::Logging.logger).to be_a(Logger) + end + + it "allows setting of a logger" do + new_logger = Logger.new(STDOUT) + InfluxDB::Logging.logger = new_logger + expect(InfluxDB::Logging.logger).to eq(new_logger) + end + + it "allows disabling of a logger" do + InfluxDB::Logging.logger = false + expect(InfluxDB::Logging.logger).to eql false + end + + context "when logging is disabled" do + subject { LoggerTest.new } + it "does not log" do + InfluxDB::Logging.logger = false + expect(InfluxDB::Logging.logger).not_to receive(:debug) + subject.write_to_log(:debug, 'test') + end + end + + context "when included in classes" do + subject { LoggerTest.new } + + it "logs" do + expect(InfluxDB::Logging.logger).to receive(:debug).with(an_instance_of(String)).once + subject.write_to_log(:debug, 'test') + end + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/max_queue_spec.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/max_queue_spec.rb new file mode 100644 index 0000000..2543e40 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/max_queue_spec.rb @@ -0,0 +1,29 @@ +require 'spec_helper' + +describe InfluxDB::MaxQueue do + specify { is_expected.to be_a(Queue) } + + context "#new" do + it "allows max_depth to be set" do + expect(described_class.new(500).max).to eq 500 + end + end + + context "#push" do + let(:queue) { described_class.new(5) } + + it "allows an item to be added if the queue is not full" do + expect(queue.size).to be_zero + queue.push(1) + expect(queue.size).to eq 1 + end + + it "doesn't allow items to be added if the queue is full" do + expect(queue.size).to be_zero + 5.times { |n| queue.push(n) } + expect(queue.size).to eq 5 + queue.push(6) + expect(queue.size).to eq 5 + end + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/point_value_spec.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/point_value_spec.rb new file mode 100644 index 0000000..9b44f24 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/point_value_spec.rb @@ -0,0 +1,89 @@ +# encoding: UTF-8 + +require "spec_helper" + +describe InfluxDB::PointValue do + describe "escaping" do + let(:data) do + point = { + series: '1= ,"\\1', + tags: { + '2= ,"\\2' => '3= ,"\\3' + }, + values: { + '4= ,"\\4' => '5= ,"\\5', + intval: 5, + floatval: 7.0, + invalid_encoding: "a b", + non_latin: "Улан-Удэ" + } + } + if RUBY_VERSION > "2.0.0" + # see github.com/influxdata/influxdb-ruby/issues/171 for details + point[:values][:invalid_encoding] = "a\255 b" + end + point + end + + it 'should escape correctly' do + point = InfluxDB::PointValue.new(data) + expected = %(1=\\ \\,"\\1,2\\=\\ \\,"\\2=3\\=\\ \\,"\\3 ) + + %(4\\=\\ \\,\\"\\4="5= ,\\"\\5",intval=5i,floatval=7.0,invalid_encoding="a b",non_latin="Улан-Удэ") + expect(point.dump).to eq(expected) + end + end + + describe 'dump' do + context "with all possible data passed" do + let(:expected_value) do + 'responses,region=eu,status=200 value=5i,threshold=0.54 1436349652' + end + it 'should have proper form' do + point = InfluxDB::PointValue.new(series: "responses", + values: { value: 5, threshold: 0.54 }, + tags: { region: 'eu', status: 200 }, + timestamp: 1_436_349_652) + + expect(point.dump).to eq(expected_value) + end + end + + context "with no tags" do + let(:expected_value) do + "responses value=5i,threshold=0.54 1436349652" + end + it 'should have proper form' do + point = InfluxDB::PointValue.new(series: "responses", + values: { value: 5, threshold: 0.54 }, + timestamp: 1_436_349_652) + + expect(point.dump).to eq(expected_value) + end + end + + context "with values only" do + let(:expected_value) do + "responses value=5i,threshold=0.54" + end + it 'should have proper form' do + point = InfluxDB::PointValue.new(series: "responses", + values: { value: 5, threshold: 0.54 }) + + expect(point.dump).to eq(expected_value) + end + end + + context "empty tag values" do + let(:expected_value) do + "responses,region=eu value=5i" + end + + it "should be omitted" do + point = InfluxDB::PointValue.new(series: "responses", + values: { value: 5 }, + tags: { region: "eu", status: nil, other: "", nil => "ignored", "" => "ignored" }) + expect(point.dump).to eq(expected_value) + end + end + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/query_builder_spec.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/query_builder_spec.rb new file mode 100644 index 0000000..70d7b0f --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/query_builder_spec.rb @@ -0,0 +1,63 @@ +require "spec_helper" + +RSpec.describe InfluxDB::Query::Builder do + let(:builder) { described_class.new } + + describe "#quote" do + subject { builder } + + it "should quote parameters properly" do + expect(subject.quote(3.14)).to eq "3.14" + expect(subject.quote(14)).to eq "14" + + expect(subject.quote("3.14")).to eq "'3.14'" + expect(subject.quote("Ben Hur's Carriage")).to eq "'Ben Hur\\'s Carriage'" + + expect(subject.quote(true)).to eq "true" + expect(subject.quote(false)).to eq "false" + expect(subject.quote(0 || 1)).to eq "0" + + expect(subject.quote(:symbol)).to eq "'symbol'" + + expect { subject.quote(/regex/) }.to raise_error(ArgumentError, /Unexpected parameter type Regex/) + end + end + + describe "#build" do + subject { builder.build(query, params) } + + context "named parameters" do + let(:query) { "SELECT value FROM rpm WHERE f = %{f_val} group by time(%{minutes}m)" } + let(:params) { { f_val: "value", minutes: 5 } } + + it { is_expected.to eq "SELECT value FROM rpm WHERE f = 'value' group by time(5m)" } + + context "with string keys" do + let(:params) { { "f_val" => "value", "minutes" => 5 } } + + it { is_expected.to eq "SELECT value FROM rpm WHERE f = 'value' group by time(5m)" } + end + end + + context "positional parameter" do + let(:query) { "SELECT value FROM rpm WHERE time > %{1}" } + let(:params) { [1_437_019_900] } + + it { is_expected.to eq "SELECT value FROM rpm WHERE time > 1437019900" } + end + + context "missing parameters" do + let(:query) { "SELECT value FROM rpm WHERE time > %{1}" } + let(:params) { [] } + + it { expect { subject }.to raise_error(/key.1. not found/) } + end + + context "extra parameters" do + let(:query) { "SELECT value FROM rpm WHERE time > %{a}" } + let(:params) { { "a" => 0, "b" => 2 } } + + it { is_expected.to eq "SELECT value FROM rpm WHERE time > 0" } + end + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/worker_spec.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/worker_spec.rb new file mode 100644 index 0000000..4002832 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/worker_spec.rb @@ -0,0 +1,27 @@ +require "spec_helper" +require 'timeout' + +describe InfluxDB::Writer::Async::Worker do + let(:fake_client) { double(stopped?: false) } + let(:worker) { described_class.new(fake_client, {}) } + + describe "#push" do + let(:payload1) { "responses,region=eu value=5" } + let(:payload2) { "responses,region=eu value=6" } + let(:aggregate) { "#{payload1}\n#{payload2}" } + + it "writes aggregate payload to the client" do + queue = Queue.new + allow(fake_client).to receive(:write) do |data, _precision| + queue.push(data) + end + worker.push(payload1) + worker.push(payload2) + + Timeout.timeout(described_class::SLEEP_INTERVAL) do + result = queue.pop + expect(result).to eq aggregate + end + end + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/spec_helper.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/spec_helper.rb new file mode 100644 index 0000000..e8aadea --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/spec_helper.rb @@ -0,0 +1,39 @@ +require "influxdb" +require "webmock/rspec" + +begin + # rubocop:disable Lint/HandleExceptions + require "pry-byebug" +rescue LoadError +end + +RSpec.configure do |config| + config.color = ENV["TRAVIS"] != "true" + + # rubocop:disable Style/ConditionalAssignment + if config.files_to_run.one? || ENV["TRAVIS"] == "true" + config.formatter = :documentation + else + config.formatter = :progress + end + + if ENV["LOG"] + Dir.mkdir("tmp") unless Dir.exist?("tmp") + logfile = File.open("tmp/spec.log", File::WRONLY | File::TRUNC | File::CREAT) + + InfluxDB::Logging.logger = Logger.new(logfile).tap do |logger| + logger.formatter = proc { |severity, _datetime, progname, message| + "%-5s - %s: %s\n".format severity, progname, message + } + end + + config.before(:each) do + InfluxDB::Logging.logger.info("RSpec") { self.class } + InfluxDB::Logging.logger.info("RSpec") { @__inspect_output } + end + + config.after(:each) do + logfile.write "\n" + end + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/.gemtest b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/.gemtest new file mode 100644 index 0000000..e69de29 diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/.gitignore b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/.gitignore new file mode 100644 index 0000000..79744e1 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/.gitignore @@ -0,0 +1,5 @@ +pkg/* +Gemfile.lock +coverage/* +doc/* +.yardoc diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/.rspec b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/.rspec new file mode 100644 index 0000000..8c1177f --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/.rspec @@ -0,0 +1,3 @@ +--colour +--format doc +--backtrace \ No newline at end of file diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/.travis.yml b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/.travis.yml new file mode 100644 index 0000000..e10ddff --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/.travis.yml @@ -0,0 +1,5 @@ +rvm: + - 1.9.2 + - 1.9.3 + - 2.0.0 + - jruby diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/Gemfile b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/Gemfile new file mode 100644 index 0000000..34efd14 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/Gemfile @@ -0,0 +1,2 @@ +source "http://rubygems.org" +gemspec \ No newline at end of file diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/README.md b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/README.md new file mode 100644 index 0000000..0e43a6b --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/README.md @@ -0,0 +1,132 @@ +# JsonPath + +This is an implementation of http://goessner.net/articles/JsonPath/. + +## What is JsonPath? + +JsonPath is a way of addressing elements within a JSON object. Similar to xpath of yore, JsonPath lets you +traverse a json object and manipulate or access it. + +## Usage + +### Command-line + +There is stand-alone usage through the binary `jsonpath` + + jsonpath [expression] (file|string) + + If you omit the second argument, it will read stdin, assuming one valid JSON object + per line. Expression must be a valid jsonpath expression. + +### Library + +To use JsonPath as a library simply include and get goin'! + +~~~~~ {ruby} +require 'jsonpath' + +json = <<-HERE_DOC +{"store": + {"bicycle": + {"price":19.95, "color":"red"}, + "book":[ + {"price":8.95, "category":"reference", "title":"Sayings of the Century", "author":"Nigel Rees"}, + {"price":12.99, "category":"fiction", "title":"Sword of Honour", "author":"Evelyn Waugh"}, + {"price":8.99, "category":"fiction", "isbn":"0-553-21311-3", "title":"Moby Dick", "author":"Herman Melville","color":"blue"}, + {"price":22.99, "category":"fiction", "isbn":"0-395-19395-8", "title":"The Lord of the Rings", "author":"Tolkien"} + ] + } +} +HERE_DOC +~~~~~ + +Now that we have a JSON object, let's get all the prices present in the object. We create an object for the path +in the following way. + +~~~~~ {ruby} +path = JsonPath.new('$..price') +~~~~~ + +Now that we have a path, let's apply it to the object above. + +~~~~~ {ruby} +path.on(json) +# => [19.95, 8.95, 12.99, 8.99, 22.99] +~~~~~ + +Or on some other object ... + +~~~~~ {ruby} +path.on('{"books":[{"title":"A Tale of Two Somethings","price":18.88}]}') +# => [18.88] +~~~~~ + +You can also just combine this into one mega-call with the convenient `JsonPath.on` method. + +~~~~~ {ruby} +JsonPath.on(json, '$..author') +# => ["Nigel Rees", "Evelyn Waugh", "Herman Melville", "Tolkien"] +~~~~~ + +Of course the full JsonPath syntax is supported, such as array slices + +~~~~~ {ruby} +JsonPath.new('$..book[::2]').on(json) +# => [ +# {"price"=>8.95, "category"=>"reference", "author"=>"Nigel Rees", "title"=>"Sayings of the Century"}, +# {"price"=>8.99, "category"=>"fiction", "author"=>"Herman Melville", "title"=>"Moby Dick", "isbn"=>"0-553-21311-3"} +# ] +~~~~~ + +...and evals. + +~~~~~ {ruby} +JsonPath.new('$..price[?(@ < 20)]').on(json) +# => [8.95, 8.99] +~~~~~ + +There is a convenience method, `#first` that gives you the first element for a JSON object and path. + +~~~~~ {ruby} +JsonPath.new('$..color').first(object) +# => "red" +~~~~~ + +As well, we can directly create an `Enumerable` at any time using `#[]`. + +~~~~~ {ruby} +enum = JsonPath.new('$..color')[object] +# => # +enum.first +# => "red" +enum.any?{ |c| c == 'red' } +# => true +~~~~~ + +You can optionally prevent eval from being called on sub-expressions by passing in :allow_eval => false to the constructor. + +### Manipulation + +If you'd like to do substitution in a json object, you can use `#gsub` or `#gsub!` to modify the object in place. + +~~~~~ {ruby} +JsonPath.for('{"candy":"lollipop"}').gsub('$..candy') {|v| "big turks" }.to_hash +~~~~~ + +The result will be + +~~~~~ {ruby} +{'candy' => 'big turks'} +~~~~~ + +If you'd like to remove all nil keys, you can use `#compact` and `#compact!`. To remove all keys under a certain path, use `#delete` or `#delete!`. You can even chain these methods together as follows: + +~~~~~ {ruby} +json = '{"candy":"lollipop","noncandy":null,"other":"things"}' +o = JsonPath.for(json). + gsub('$..candy') {|v| "big turks" }. + compact. + delete('$..other'). + to_hash +# => {"candy" => "big turks"} +~~~~~ diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/Rakefile b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/Rakefile new file mode 100644 index 0000000..39f6501 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/Rakefile @@ -0,0 +1,12 @@ +require 'bundler' +Bundler::GemHelper.install_tasks + +task :test do + $: << 'lib' + require 'minitest/autorun' + require 'phocus' + require 'jsonpath' + Dir['./test/**/test_*.rb'].each { |test| require test } +end + +task :default => :test \ No newline at end of file diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/bin/jsonpath b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/bin/jsonpath new file mode 100755 index 0000000..4793a6d --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/bin/jsonpath @@ -0,0 +1,22 @@ +#!/usr/bin/env ruby + +require 'jsonpath' +require 'multi_json' + +def usage + puts "jsonpath [expression] (file|string) + +If you omit the second argument, it will read stdin, assuming one valid JSON object +per line. Expression must be a valid jsonpath expression." + exit! +end + +usage unless ARGV[0] + +jsonpath = JsonPath.new(ARGV[0]) +case ARGV[1] +when nil #stdin + puts MultiJson.encode(jsonpath.on(MultiJson.decode(STDIN.read))) +when String + puts MultiJson.encode(jsonpath.on(MultiJson.decode(File.exist?(ARGV[1]) ? File.read(ARGV[1]) : ARGV[1]))) +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/jsonpath.gemspec b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/jsonpath.gemspec new file mode 100644 index 0000000..7ff16b0 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/jsonpath.gemspec @@ -0,0 +1,32 @@ +# -*- encoding: utf-8 -*- + +require File.join(File.dirname(__FILE__), 'lib', 'jsonpath', 'version') + +Gem::Specification.new do |s| + s.name = 'jsonpath' + s.version = JsonPath::VERSION + s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= + s.authors = ["Joshua Hull"] + s.summary = "Ruby implementation of http://goessner.net/articles/JsonPath/" + s.description = "Ruby implementation of http://goessner.net/articles/JsonPath/." + s.email = %q{joshbuddy@gmail.com} + s.extra_rdoc_files = ['README.md'] + s.files = `git ls-files`.split("\n") + s.homepage = %q{http://github.com/joshbuddy/jsonpath} + s.rdoc_options = ["--charset=UTF-8"] + s.require_paths = ["lib"] + s.rubygems_version = %q{1.3.7} + s.test_files = `git ls-files`.split("\n").select{|f| f =~ /^spec/} + s.rubyforge_project = 'jsonpath' + s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } + s.licenses = ['MIT'] + + # dependencies + s.add_runtime_dependency 'multi_json' + s.add_development_dependency 'code_stats' + s.add_development_dependency 'rake' + s.add_development_dependency 'minitest', '~> 2.2.0' + s.add_development_dependency 'phocus' + s.add_development_dependency 'bundler' +end + diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/lib/jsonpath.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/lib/jsonpath.rb new file mode 100644 index 0000000..82bd295 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/lib/jsonpath.rb @@ -0,0 +1,93 @@ +require 'strscan' +require 'multi_json' +require 'jsonpath/proxy' +require 'jsonpath/enumerable' +require 'jsonpath/version' + +class JsonPath + + PATH_ALL = '$..*' + + attr_accessor :path + + def initialize(path, opts = nil) + @opts = opts + scanner = StringScanner.new(path) + @path = [] + while not scanner.eos? + if token = scanner.scan(/\$/) + @path << token + elsif token = scanner.scan(/@/) + @path << token + elsif token = scanner.scan(/[a-zA-Z0-9_-]+/) + @path << "['#{token}']" + elsif token = scanner.scan(/'(.*?)'/) + @path << "[#{token}]" + elsif token = scanner.scan(/\[/) + count = 1 + while !count.zero? + if t = scanner.scan(/\[/) + token << t + count += 1 + elsif t = scanner.scan(/\]/) + token << t + count -= 1 + elsif t = scanner.scan(/[^\[\]]+/) + token << t + elsif scanner.eos? + raise ArgumentError, 'unclosed bracket' + end + end + @path << token + elsif token = scanner.scan(/\]/) + raise ArgumentError, 'unmatched closing bracket' + elsif token = scanner.scan(/\.\./) + @path << token + elsif scanner.scan(/\./) + nil + elsif token = scanner.scan(/\*/) + @path << token + elsif token = scanner.scan(/[><=] \d+/) + @path.last << token + elsif token = scanner.scan(/./) + @path.last << token + end + end + end + + def join(join_path) + res = deep_clone + res.path += JsonPath.new(join_path).path + res + end + + def on(obj_or_str) + enum_on(obj_or_str).to_a + end + + def first(obj_or_str, *args) + enum_on(obj_or_str).first(*args) + end + + def enum_on(obj_or_str, mode = nil) + JsonPath::Enumerable.new(self, self.class.process_object(obj_or_str), mode, @opts) + end + alias_method :[], :enum_on + + def self.on(obj_or_str, path, opts = nil) + self.new(path, opts).on(process_object(obj_or_str)) + end + + def self.for(obj_or_str) + Proxy.new(process_object(obj_or_str)) + end + + private + def self.process_object(obj_or_str) + obj_or_str.is_a?(String) ? MultiJson.decode(obj_or_str) : obj_or_str + end + + def deep_clone + Marshal.load Marshal.dump(self) + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/lib/jsonpath/enumerable.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/lib/jsonpath/enumerable.rb new file mode 100644 index 0000000..373ac66 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/lib/jsonpath/enumerable.rb @@ -0,0 +1,135 @@ +class JsonPath + class Enumerable + include ::Enumerable + attr_reader :allow_eval + alias_method :allow_eval?, :allow_eval + + def initialize(path, object, mode, options = nil) + @path, @object, @mode, @options = path.path, object, mode, options + @allow_eval = @options && @options.key?(:allow_eval) ? @options[:allow_eval] : true + end + + def each(context = @object, key = nil, pos = 0, &blk) + node = key ? context[key] : context + @_current_node = node + return yield_value(blk, context, key) if pos == @path.size + case expr = @path[pos] + when '*', '..' + each(context, key, pos + 1, &blk) + when '$' + each(context, key, pos + 1, &blk) if node == @object + when '@' + each(context, key, pos + 1, &blk) + when /^\[(.*)\]$/ + expr[1,expr.size - 2].split(',').each do |sub_path| + case sub_path[0] + when ?', ?" + if node.is_a?(Hash) + k = sub_path[1,sub_path.size - 2] + each(node, k, pos + 1, &blk) if node.key?(k) + end + when ?? + raise "Cannot use ?(...) unless eval is enabled" unless allow_eval? + case node + when Hash, Array + (node.is_a?(Hash) ? node.keys : (0..node.size)).each do |e| + @_current_node = node[e] + if process_function_or_literal(sub_path[1, sub_path.size - 1]) + each(@_current_node, nil, pos + 1, &blk) + end + end + else + yield node if process_function_or_literal(sub_path[1, sub_path.size - 1]) + end + else + if node.is_a?(Array) + next if node.empty? + array_args = sub_path.split(':') + if array_args[0] == ?* + start_idx = 0 + end_idx = node.size - 1 + else + start_idx = process_function_or_literal(array_args[0], 0) + next unless start_idx + end_idx = (array_args[1] && process_function_or_literal(array_args[1], -1) || (sub_path.count(':') == 0 ? start_idx : -1)) + next unless end_idx + if start_idx == end_idx + next unless start_idx < node.size + end + end + start_idx %= node.size + end_idx %= node.size + step = process_function_or_literal(array_args[2], 1) + next unless step + (start_idx..end_idx).step(step) {|i| each(node, i, pos + 1, &blk)} + end + end + end + else + if pos == (@path.size - 1) && node && allow_eval? + if eval("node #{@path[pos]}") + yield_value(blk, context, key) + end + end + end + + if pos > 0 && @path[pos-1] == '..' + case node + when Hash then node.each {|k, v| each(node, k, pos, &blk) } + when Array then node.each_with_index {|n, i| each(node, i, pos, &blk) } + end + end + end + + private + def yield_value(blk, context, key) + case @mode + when nil + blk.call(key ? context[key] : context) + when :compact + context.delete(key) if key && context[key].nil? + when :delete + context.delete(key) if key + when :substitute + if key + context[key] = blk.call(context[key]) + else + context.replace(blk.call(context[key])) + end + end + end + + def process_function_or_literal(exp, default = nil) + if exp.nil? + default + elsif exp[0] == ?( + return nil unless allow_eval? && @_current_node + identifiers = /@?(\.(\w+))+/.match(exp) + + if !identifiers.nil? && !@_current_node.methods.include?(identifiers[2].to_sym) + exp_to_eval = exp.dup + exp_to_eval[identifiers[0]] = identifiers[0].split('.').map{|el| el == '@' ? '@_current_node' : "['#{el}']"}.join + begin + return eval(exp_to_eval) + rescue StandardError # if eval failed because of bad arguments or missing methods + return default + end + end + + # otherwise eval as is + # TODO: this eval is wrong, because hash accessor could be nil and nil cannot be compared with anything, + # for instance, @_current_node['price'] - we can't be sure that 'price' are in every node, but it's only in several nodes + # I wrapped this eval into rescue returning false when error, but this eval should be refactored. + begin + eval(exp.gsub(/@/, '@_current_node')) + rescue + false + end + elsif exp.empty? + default + else + Integer(exp) + end + end + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/lib/jsonpath/proxy.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/lib/jsonpath/proxy.rb new file mode 100644 index 0000000..4e8f1b7 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/lib/jsonpath/proxy.rb @@ -0,0 +1,54 @@ +class JsonPath + class Proxy + attr_reader :obj + alias_method :to_hash, :obj + + def initialize(obj) + @obj = obj + end + + def gsub(path, replacement = nil, &replacement_block) + _gsub(_deep_copy, path, replacement ? proc{replacement} : replacement_block) + end + + def gsub!(path, replacement = nil, &replacement_block) + _gsub(@obj, path, replacement ? proc{replacement} : replacement_block) + end + + def delete(path = JsonPath::PATH_ALL) + _delete(_deep_copy, path) + end + + def delete!(path = JsonPath::PATH_ALL) + _delete(@obj, path) + end + + def compact(path = JsonPath::PATH_ALL) + _compact(_deep_copy, path) + end + + def compact!(path = JsonPath::PATH_ALL) + _compact(@obj, path) + end + + private + def _deep_copy + Marshal::load(Marshal::dump(@obj)) + end + + def _gsub(obj, path, replacement) + JsonPath.new(path)[obj, :substitute].each(&replacement) + Proxy.new(obj) + end + + def _delete(obj, path) + JsonPath.new(path)[obj, :delete].each + Proxy.new(obj) + end + + def _compact(obj, path) + JsonPath.new(path)[obj, :compact].each + Proxy.new(obj) + end + end +end \ No newline at end of file diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/lib/jsonpath/version.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/lib/jsonpath/version.rb new file mode 100644 index 0000000..b7a592a --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/lib/jsonpath/version.rb @@ -0,0 +1,3 @@ +class JsonPath + VERSION = '0.5.8' +end \ No newline at end of file diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/test/test_jsonpath.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/test/test_jsonpath.rb new file mode 100644 index 0000000..76c267b --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/test/test_jsonpath.rb @@ -0,0 +1,231 @@ +class TestJsonpath < MiniTest::Unit::TestCase + + def setup + @object = example_object + @object2 = example_object + end + + def test_bracket_matching + assert_raises(ArgumentError) { + JsonPath.new('$.store.book[0') + } + assert_raises(ArgumentError) { + JsonPath.new('$.store.book[0]]') + } + end + + def test_lookup_direct_path + assert_equal 7, JsonPath.new('$.store.*').on(@object).first['book'].size + end + + def test_lookup_missing_element + assert_equal [], JsonPath.new('$.store.book[99].price').on(@object) + end + + def test_retrieve_all_authors + assert_equal [ + @object['store']['book'][0]['author'], + @object['store']['book'][1]['author'], + @object['store']['book'][2]['author'], + @object['store']['book'][3]['author'], + @object['store']['book'][4]['author'], + @object['store']['book'][5]['author'], + @object['store']['book'][6]['author'] + ], JsonPath.new('$..author').on(@object) + end + + def test_retrieve_all_prices + assert_equal [ + @object['store']['bicycle']['price'], + @object['store']['book'][0]['price'], + @object['store']['book'][1]['price'], + @object['store']['book'][2]['price'], + @object['store']['book'][3]['price'] + ].sort, JsonPath.new('$..price').on(@object).sort + end + + def test_recognize_array_splices + assert_equal [@object['store']['book'][0], @object['store']['book'][1]], JsonPath.new('$..book[0:1:1]').on(@object) + assert_equal [@object['store']['book'][1], @object['store']['book'][3], @object['store']['book'][5]], JsonPath.new('$..book[1::2]').on(@object) + assert_equal [@object['store']['book'][0], @object['store']['book'][2], @object['store']['book'][4], @object['store']['book'][6]], JsonPath.new('$..book[::2]').on(@object) + assert_equal [@object['store']['book'][0], @object['store']['book'][2]], JsonPath.new('$..book[:-5:2]').on(@object) + assert_equal [@object['store']['book'][5], @object['store']['book'][6]], JsonPath.new('$..book[5::]').on(@object) + end + + def test_recognize_array_comma + assert_equal [@object['store']['book'][0], @object['store']['book'][1]], JsonPath.new('$..book[0,1]').on(@object) + assert_equal [@object['store']['book'][2], @object['store']['book'][6]], JsonPath.new('$..book[2,-1::]').on(@object) + end + + def test_recognize_filters + assert_equal [@object['store']['book'][2], @object['store']['book'][3]], JsonPath.new("$..book[?(@['isbn'])]").on(@object) + assert_equal [@object['store']['book'][0], @object['store']['book'][2]], JsonPath.new("$..book[?(@['price'] < 10)]").on(@object) + assert_equal [@object['store']['book'][0], @object['store']['book'][2]], JsonPath.new("$..book[?(@['price'] == 9)]").on(@object) + assert_equal [@object['store']['book'][3]], JsonPath.new("$..book[?(@['price'] > 20)]").on(@object) + end + + if RUBY_VERSION[/^1\.9/] + def test_recognize_filters_on_val + assert_equal [@object['store']['book'][1]['price'], @object['store']['book'][3]['price'], @object['store']['bicycle']['price']], JsonPath.new("$..price[?(@ > 10)]").on(@object) + end + end + + def test_no_eval + assert_equal [], JsonPath.new('$..book[(@.length-2)]', :allow_eval => false).on(@object) + end + + def test_paths_with_underscores + assert_equal [@object['store']['bicycle']['catalogue_number']], JsonPath.new('$.store.bicycle.catalogue_number').on(@object) + end + + def test_path_with_hyphens + assert_equal [@object['store']['bicycle']['single-speed']], JsonPath.new('$.store.bicycle.single-speed').on(@object) + end + + def test_paths_with_numbers + assert_equal [@object['store']['bicycle']['2seater']], JsonPath.new('$.store.bicycle.2seater').on(@object) + end + + def test_recognize_array_with_evald_index + assert_equal [@object['store']['book'][2]], JsonPath.new('$..book[(@.length-5)]').on(@object) + end + + def test_use_first + assert_equal @object['store']['book'][2], JsonPath.new('$..book[(@.length-5)]').first(@object) + end + + def test_counting + assert_equal 49, JsonPath.new('$..*').on(@object).to_a.size + end + + def test_space_in_path + assert_equal ['e'], JsonPath.new("$.'c d'").on({"a" => "a","b" => "b", "c d" => "e"}) + end + + def test_class_method + assert_equal JsonPath.new('$..author').on(@object), JsonPath.on(@object, '$..author') + end + + def test_join + assert_equal JsonPath.new('$.store.book..author').on(@object), JsonPath.new('$.store').join('book..author').on(@object) + end + + def test_gsub + @object2['store']['bicycle']['price'] += 10 + @object2['store']['book'][0]['price'] += 10 + @object2['store']['book'][1]['price'] += 10 + @object2['store']['book'][2]['price'] += 10 + @object2['store']['book'][3]['price'] += 10 + assert_equal @object2, JsonPath.for(@object).gsub('$..price') { |p| p + 10 }.to_hash + end + + def test_gsub! + JsonPath.for(@object).gsub!('$..price') { |p| p + 10 } + assert_equal 30, @object['store']['bicycle']['price'] + assert_equal 19, @object['store']['book'][0]['price'] + assert_equal 23, @object['store']['book'][1]['price'] + assert_equal 19, @object['store']['book'][2]['price'] + assert_equal 33, @object['store']['book'][3]['price'] + end + + def test_weird_gsub! + h = {'hi' => 'there'} + JsonPath.for(@object).gsub!('$.*') { |n| h } + assert_equal h, @object + end + + def test_compact + h = {'hi' => 'there', 'you' => nil} + JsonPath.for(h).compact! + assert_equal({'hi' => 'there'}, h) + end + + def test_delete + h = {'hi' => 'there', 'you' => nil} + JsonPath.for(h).delete!('*.hi') + assert_equal({'you' => nil}, h) + end + + def test_wildcard + assert_equal @object['store']['book'].collect{|e| e['price']}.compact, JsonPath.on(@object, '$..book[*].price') + end + + def test_wildcard_empty_array + object = @object.merge("bicycle" => { "tire" => [] }) + assert_equal [], JsonPath.on(object, "$..bicycle.tire[*]") + end + + def test_support_filter_by_childnode_value + assert_equal [@object['store']['book'][3]], JsonPath.new("$..book[?(@.price > 20)]").on(@object) + end + + def test_support_filter_by_childnode_value_with_inconsistent_children + @object['store']['book'][0] = "string_instead_of_object" + assert_equal [@object['store']['book'][3]], JsonPath.new("$..book[?(@.price > 20)]").on(@object) + end + + def test_support_filter_by_childnode_value_and_select_child_key + assert_equal [23], JsonPath.new("$..book[?(@.price > 20)].price").on(@object) + end + + def test_support_filter_by_childnode_value_over_childnode_and_select_child_key + assert_equal ["Osennie Vizity"], JsonPath.new("$..book[?(@.written.year == 1996)].title").on(@object) + end + + def example_object + { "store"=> { + "book" => [ + { "category"=> "reference", + "author"=> "Nigel Rees", + "title"=> "Sayings of the Century", + "price"=> 9 + }, + { "category"=> "fiction", + "author"=> "Evelyn Waugh", + "title"=> "Sword of Honour", + "price"=> 13 + }, + { "category"=> "fiction", + "author"=> "Herman Melville", + "title"=> "Moby Dick", + "isbn"=> "0-553-21311-3", + "price"=> 9 + }, + { "category"=> "fiction", + "author"=> "J. R. R. Tolkien", + "title"=> "The Lord of the Rings", + "isbn"=> "0-395-19395-8", + "price"=> 23 + }, + { "category"=> "russian_fiction", + "author"=> "Lukyanenko", + "title"=> "Imperatory Illuziy", + "written" => { + "year" => 1995 + } + }, + { "category"=> "russian_fiction", + "author"=> "Lukyanenko", + "title"=> "Osennie Vizity", + "written" => { + "year" => 1996 + } + }, + { "category"=> "russian_fiction", + "author"=> "Lukyanenko", + "title"=> "Ne vremya dlya drakonov", + "written" => { + "year" => 1997 + } + } + ], + "bicycle"=> { + "color"=> "red", + "price"=> 20, + "catalogue_number" => 12345, + "single-speed" => "no", + "2seater" => "yes"} + } } + end + +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/test/test_jsonpath_bin.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/test/test_jsonpath_bin.rb new file mode 100644 index 0000000..626a119 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/test/test_jsonpath_bin.rb @@ -0,0 +1,21 @@ +class TestJsonpathBin < MiniTest::Unit::TestCase + def setup + @runner = "ruby -Ilib bin/jsonpath" + @original_dir = Dir.pwd + Dir.chdir(File.join(File.dirname(__FILE__), '..')) + end + + def teardown + Dir.chdir(@original_dir) + `rm /tmp/test.json` + end + + def test_stdin + assert_equal '["time"]', `echo '{"test": "time"}' | #{@runner} '$.test'`.strip + end + + def test_stdin + File.open('/tmp/test.json', 'w'){|f| f << '{"test": "time"}'} + assert_equal '["time"]', `#{@runner} '$.test' /tmp/test.json`.strip + end +end \ No newline at end of file diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/linux-kstat-0.1.3-universal-linux/CHANGES b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/linux-kstat-0.1.3-universal-linux/CHANGES new file mode 100644 index 0000000..f909654 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/linux-kstat-0.1.3-universal-linux/CHANGES @@ -0,0 +1,11 @@ += 0.1.3 - 18-Dec-2014 +* Now properly ignores blank lines. Thanks go to "onlinehead" for the patch. + += 0.1.2 - 2-Nov-2014 +* Updates to the gemspec and Rakefile. + += 0.1.1 - 20-May-2011 +* Set the spec platform to 'universal-linux'. + += 0.1.0 - 10-Feb-2011 +* Initial release. diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/linux-kstat-0.1.3-universal-linux/MANIFEST b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/linux-kstat-0.1.3-universal-linux/MANIFEST new file mode 100644 index 0000000..0a6c769 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/linux-kstat-0.1.3-universal-linux/MANIFEST @@ -0,0 +1,7 @@ +* CHANGES +* README +* MANIFEST +* Rakefile +* linux-kstat.gemspec +* lib/linux/kstat.rb +* test/test_linux_kstat.rb diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/linux-kstat-0.1.3-universal-linux/README b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/linux-kstat-0.1.3-universal-linux/README new file mode 100644 index 0000000..6ab49cb --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/linux-kstat-0.1.3-universal-linux/README @@ -0,0 +1,43 @@ += Description + A Ruby library for gathering Linux kernel statistics out of /proc/stat. + += Installation + gem install linux-kstat + += Synopsis + require 'linux/kstat' + + kstat = Linux::Kstat.new + + p kstat[:cpu] + p kstat[:procs_running] + += Details + The values for most of the keys are a single numeric value. However, in the + case of "cpu" keys, the result is a 7 element hash of numeric values. In + the case of the "intr" key, the value is an array containing the list of + interrupts. + += Information about /proc/stat + See http://www.linuxhowtos.org/System/procstat.htm for more information + about the meaning of each of the fields. + += Known Bugs + None known. Please report any bugs on the github project page. + + http://www.github.com/djberg96/linux-kstat + += License + Artistic 2.0 + += Copyright + (C) 2003-2014 Daniel J. Berger + All Rights Reserved.` + += Warranty + This package is provided "as is" and without any express or + implied warranties, including, without limitation, the implied + warranties of merchantability and fitness for a particular purpose. + += Author + Daniel J. Berger diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/linux-kstat-0.1.3-universal-linux/Rakefile b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/linux-kstat-0.1.3-universal-linux/Rakefile new file mode 100644 index 0000000..a8bc277 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/linux-kstat-0.1.3-universal-linux/Rakefile @@ -0,0 +1,36 @@ +require 'rake' +require 'rake/clean' +require 'rake/testtask' + +CLEAN.include('**/*.gem', '**/*.rbc') + +namespace :gem do + desc 'Build the linux-kstat gem' + task :create => [:clean] do + spec = eval(IO.read('linux-kstat.gemspec')) + if Gem::VERSION < "2.0" + Gem::Builder.new(spec).build + else + require 'rubygems/package' + Gem::Package.build(spec) + end + end + + desc "Install the linux-kstat gem" + task :install => [:create] do + file = Dir["*.gem"].first + if RUBY_PLATFORM == 'java' + sh "jruby -S gem install -l #{file}" + else + sh "gem install -l #{file}" + end + end +end + +Rake::TestTask.new do |t| + task :test => :clean + t.warning = true + t.verbose = true +end + +task :default => :test diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/linux-kstat-0.1.3-universal-linux/lib/linux/kstat.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/linux-kstat-0.1.3-universal-linux/lib/linux/kstat.rb new file mode 100644 index 0000000..19607c5 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/linux-kstat-0.1.3-universal-linux/lib/linux/kstat.rb @@ -0,0 +1,78 @@ +require 'forwardable' + +# The Linux module serves as a namespace only. +module Linux + # The Kstat class encapsulates Linux kernel statistics derived from /proc/stat. + class Kstat + extend Forwardable + + # The version of the linux-kstat library + VERSION = '0.1.3' + + # :stopdoc: + + # Delegate the the [] and inspect methods to the @hash variable + def_delegator(:@hash, :[]) + def_delegator(:@hash, :inspect) + + # :startdoc: + + # Create a new Linux::Kstat instance. You can access the information + # stored in this object the same way you would access a hash key. Note + # that all keys are symbols. + # + # Example: + # + # kstat = Linux::Kstat.new + # + # kstat[:cpu] => { + # :idle => 250713454, + # :iowait => 2745691, + # :irq => 39717, + # :softirq => 31323, + # :system => 1881655, + # :nice => 117158, + # :user => 7137418 + # } + # + # kstat[:processes] # => 1299560 + # + def initialize + @hash = get_proc_stat_info + end + + private + + # Parse the information out of /proc/stat and assign keys and values to + # a hash that can be accessed via the Forwardable module. + # + def get_proc_stat_info + hash = {} + + IO.readlines('/proc/stat').each{ |line| + info = line.split + unless info.empty? + if info.first =~ /^cpu/i + hash[info.first.to_sym] = { + :user => info[1].to_i, + :nice => info[2].to_i, + :system => info[3].to_i, + :idle => info[4].to_i, + :iowait => info[5].to_i, + :irq => info[6].to_i, + :softirq => info[7].to_i + } + else + if info.size > 2 + hash[info.first.to_sym] = info[1..-1].map{ |e| e.to_i } + else + hash[info.first.to_sym] = info[1].to_i + end + end + end + } + + hash + end + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/linux-kstat-0.1.3-universal-linux/linux-kstat.gemspec b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/linux-kstat-0.1.3-universal-linux/linux-kstat.gemspec new file mode 100644 index 0000000..b126fa5 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/linux-kstat-0.1.3-universal-linux/linux-kstat.gemspec @@ -0,0 +1,24 @@ +require 'rubygems' +require 'rbconfig' + +Gem::Specification.new do |gem| + gem.name = 'linux-kstat' + gem.version = '0.1.3' + gem.license = 'Artistic 2.0' + gem.author = 'Daniel J. Berger' + gem.email = 'djberg96@gmail.com' + gem.platform = Gem::Platform.new('universal-linux') + gem.homepage = 'https://github.com/djberg96/linux-kstat' + gem.summary = 'Ruby interface for Linux kernel stats in /proc/stat' + gem.test_files = Dir['test/test*'] + gem.files = Dir['**/*'].reject{ |f| f.include?('git') } + + gem.extra_rdoc_files = ['README', 'CHANGES', 'MANIFEST'] + + gem.add_development_dependency('test-unit', '>= 2.5.0') + + gem.description = <<-EOF + The linux-kstat library provides a hash style interface for reading + Linux kernel statistics read out of /proc/stat. + EOF +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/linux-kstat-0.1.3-universal-linux/test/test_linux_kstat.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/linux-kstat-0.1.3-universal-linux/test/test_linux_kstat.rb new file mode 100644 index 0000000..63c2ffe --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/linux-kstat-0.1.3-universal-linux/test/test_linux_kstat.rb @@ -0,0 +1,36 @@ +####################################################################### +# test_linux_kstat.rb +# +# Test suite for the linux-kstat library. +####################################################################### +require 'test-unit' +require 'linux/kstat' + +class TC_Linux_Kstat < Test::Unit::TestCase + def setup + @kstat = Linux::Kstat.new + end + + test "version constant is set to the expected value" do + assert_equal('0.1.3', Linux::Kstat::VERSION) + end + + test "kstat object can be accessed like a hash" do + assert_respond_to(@kstat, :[]) + assert_nothing_raised{ @kstat[:cpu] } + end + + test "kstat object contains expected keys" do + assert_kind_of(Hash, @kstat[:cpu]) + assert_kind_of(Numeric, @kstat[:btime]) + assert_kind_of(Array, @kstat[:intr]) + end + + test "values cannot be assigned to keys" do + assert_raise(NoMethodError){ @kstat[:cpu] = 'test' } + end + + def teardown + @kstat = nil + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/CHANGELOG.md b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/CHANGELOG.md new file mode 100644 index 0000000..8b98307 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/CHANGELOG.md @@ -0,0 +1,245 @@ +1.12.1 +------ + +* [Prevent meory leak in OptionsCache](https://github.com/intridea/multi_json/commit/aa7498199ad272f3d4a13750d7c568a66047e2ee) + +1.12.0 +------ + +* [Introduce global options cache to improve peroformance](https://github.com/intridea/multi_json/commit/7aaef2a1bc2b83c95e4208b12dad5d1d87ff20a6) + +1.11.2 +------ + +* [Only pass one argument to JrJackson when two is not supported](https://github.com/intridea/multi_json/commit/e798fa517c817fc706982d3f3c61129b6651d601) + +1.11.1 +------ + +* [Dump method passes options throught for JrJackson adapter](https://github.com/intridea/multi_json/commit/3c730fd12135c3e7bf212f878958004908f13909) + +1.11.0 +------ + +* [Make all adapters read IO object before load](https://github.com/intridea/multi_json/commit/167f559e18d4efee05e1f160a2661d16dbb215d4) + +1.10.1 +------ +* [Explicitly require stringio for Gson adapter](https://github.com/intridea/multi_json/commit/623ec8142d4a212fa0db763bb71295789a119929) +* [Do not read StringIO object before passing it to JrJackson](https://github.com/intridea/multi_json/commit/a6dc935df08e7b3d5d701fbb9298384c96df0fde) + +1.10.0 +------ +* [Performance tweaks](https://github.com/intridea/multi_json/commit/58724acfed31866d079eaafb1cd824e341ade287) + +1.9.3 +----- +* [Convert indent option to Fixnum before passing to Oj](https://github.com/intridea/multi_json/commit/826fc5535b863b74fc9f981dfdda3e26f1ee4e5b) + +1.9.2 +----- +* [Enable use_to_json option for Oj adapter by default](https://github.com/intridea/multi_json/commit/76a4aaf697b10bbabd5d535d83cf1149efcfe5c7) + +1.9.1 +----- +* [Remove unused LoadError file](https://github.com/intridea/multi_json/commit/65dedd84d59baeefc25c477fedf0bbe85e7ce2cd) + +1.9.0 +---- +* [Rename LoadError to ParseError](https://github.com/intridea/multi_json/commit/4abb98fe3a90b2a7b3d1594515c8a06042b4a27d) +* [Adapter load failure throws AdapterError instead of ArgumentError](https://github.com/intridea/multi_json/commit/4da612b617bd932bb6fa1cc4c43210327f98f271) + +1.8.4 +----- +* [Make Gson adapter explicitly read StringIO object](https://github.com/intridea/multi_json/commit/b58b498747ff6e94f41488c971b2a30a98760ef2) + +1.8.3 +----- +* [Make JrJackson explicitly read StringIO objects](https://github.com/intridea/multi_json/commit/e1f162d5b668e5e4db5afa175361a601a8aa2b05) +* [Prevent calling #downcase on alias symbols](https://github.com/intridea/multi_json/commit/c1cf075453ce0110f7decc4f906444b1233bb67c) + +1.8.2 +----- +* [Downcase adapter string name for OS compatibility](https://github.com/intridea/multi_json/commit/b8e15a032247a63f1410d21a18add05035f3fa66) + +1.8.1 +----- +* [Let the adapter handle strings with invalid encoding](https://github.com/intridea/multi_json/commit/6af2bf87b89f44eabf2ae9ca96779febc65ea94b) + +1.8.0 +----- +* [Raise MultiJson::LoadError on blank input](https://github.com/intridea/multi_json/commit/c44f9c928bb25fe672246ad394b3e5b991be32e6) + +1.7.9 +----- +* [Explicitly require json gem code even when constant is defined](https://github.com/intridea/multi_json/commit/36f7906c66477eb4b55b7afeaa3684b6db69eff2) + +1.7.8 +----- +* [Reorder JrJackson before json_gem](https://github.com/intridea/multi_json/commit/315b6e460b6e4dcdb6c82e04e4be8ee975d395da) +* [Update vendored OkJson to version 43](https://github.com/intridea/multi_json/commit/99a6b662f6ef4036e3ee94d7eb547fa72fb2ab50) + +1.7.7 +----- +* [Fix options caching issues](https://github.com/intridea/multi_json/commit/a3f14c3661688c5927638fa6088c7b46a67e875e) + +1.7.6 +----- +* [Bring back MultiJson::VERSION constant](https://github.com/intridea/multi_json/commit/31b990c2725e6673bf8ce57540fe66b57a751a72) + +1.7.5 +----- +* [Fix warning '*' interpreted as argument prefix](https://github.com/intridea/multi_json/commit/b698962c7f64430222a1f06430669706a47aff89) +* [Remove stdlib warning](https://github.com/intridea/multi_json/commit/d06eec6b7996ac8b4ff0e2229efd835379b0c30f) + +1.7.4 +----- +* [Cache options for better performance](https://github.com/intridea/multi_json/commit/8a26ee93140c4bed36194ed9fb887a1b6919257b) + +1.7.3 +----- +* [Require json/ext to ensure extension version gets loaded for json_gem](https://github.com/intridea/multi_json/commit/942686f7e8597418c6f90ee69e1d45242fac07b1) +* [Rename JrJackson](https://github.com/intridea/multi_json/commit/078de7ba8b6035343c3e96b4767549e9ec43369a) +* [Prefer JrJackson to JSON gem if present](https://github.com/intridea/multi_json/commit/af8bd9799a66855f04b3aff1c488485950cec7bf) +* [Print a warning if outdated gem versions are used](https://github.com/intridea/multi_json/commit/e7438e7ba2be0236cfa24c2bb9ad40ee821286d1) +* [Loosen required_rubygems_version for compatibility with Ubuntu 10.04](https://github.com/intridea/multi_json/commit/59fad014e8fe41dbc6f09485ea0dc21fc42fd7a7) + +1.7.2 +----- +* [Rename Jrjackson adapter to JrJackson](https://github.com/intridea/multi_json/commit/b36dc915fc0e6548cbad06b5db6f520e040c9c8b) +* [Implement jrjackson -> jr_jackson alias for back-compatability](https://github.com/intridea/multi_json/commit/aa50ab8b7bb646b8b75d5d65dfeadae8248a4f10) +* [Update vendored OkJson module](https://github.com/intridea/multi_json/commit/30a3f474e17dd86a697c3fab04f468d1a4fd69d7) + +1.7.1 +----- +* [Fix capitalization of JrJackson class](https://github.com/intridea/multi_json/commit/5373a5e38c647f02427a0477cb8e0e0dafad1b8d) + +1.7.0 +----- +* [Add load_options/dump_options to MultiJson](https://github.com/intridea/multi_json/commit/a153956be6b0df06ea1705ce3c1ff0b5b0e27ea5) +* [MultiJson does not modify arguments](https://github.com/intridea/multi_json/commit/58525b01c4c2f6635ba2ac13d6fd987b79f3962f) +* [Enable quirks_mode by default for json_gem/json_pure adapters](https://github.com/intridea/multi_json/commit/1fd4e6635c436515b7d7d5a0bee4548de8571520) +* [Add JrJackson adapter](https://github.com/intridea/multi_json/commit/4dd86fa96300aaaf6d762578b9b31ea82adb056d) +* [Raise ArgumentError on bad adapter input](https://github.com/intridea/multi_json/commit/911a3756bdff2cb5ac06497da3fa3e72199cb7ad) + +1.6.1 +----- +* [Revert "Use JSON.generate instead of #to_json"](https://github.com/intridea/multi_json/issues/86) + +1.6.0 +----- +* [Add gson.rb support](https://github.com/intridea/multi_json/pull/71) +* [Add MultiJson.default_options](https://github.com/intridea/multi_json/pull/70) +* [Add MultiJson.with_adapter](https://github.com/intridea/multi_json/pull/67) +* [Stringify all possible keys for ok_json](https://github.com/intridea/multi_json/pull/66) +* [Use JSON.generate instead of #to_json](https://github.com/intridea/multi_json/issues/73) +* [Alias `MultiJson::DecodeError` to `MultiJson::LoadError`](https://github.com/intridea/multi_json/pull/79) + +1.5.1 +----- +* [Do not allow Oj or JSON to create symbols by searching for classes](https://github.com/intridea/multi_json/commit/193e28cf4dc61b6e7b7b7d80f06f74c76df65c41) + +1.5.0 +----- +* [Add `MultiJson.with_adapter` method](https://github.com/intridea/multi_json/commit/d14c5d28cae96557a0421298621b9499e1f28104) +* [Stringify all possible keys for `ok_json`](https://github.com/intridea/multi_json/commit/73998074058e1e58c557ffa7b9541d486d6041fa) + +1.4.0 +----- +* [Allow `load`/`dump` of JSON fragments](https://github.com/intridea/multi_json/commit/707aae7d48d39c85b38febbd2c210ba87f6e4a36) + +1.3.7 +----- +* [Fix rescue clause for MagLev](https://github.com/intridea/multi_json/commit/39abdf50199828c50e85b2ce8f8ba31fcbbc9332) +* [Remove unnecessary check for string version of options key](https://github.com/intridea/multi_json/commit/660101b70e962b3c007d0b90d45944fa47d13ec4) +* [Explicitly set default adapter when adapter is set to `nil` or `false`](https://github.com/intridea/multi_json/commit/a9e587d5a63eafb4baee9fb211265e4dd96a26bc) +* [Fix Oj `ParseError` mapping for Oj 1.4.0](https://github.com/intridea/multi_json/commit/7d9045338cc9029401c16f3c409d54ce97f275e2) + +1.3.6 +----- +* [Allow adapter-specific options to be passed through to Oj](https://github.com/intridea/multi_json/commit/d0e5feeebcba0bc69400dd203a295f5c30971223) + +1.3.5 +----- +* [Add pretty support to Oj adapter](https://github.com/intridea/multi_json/commit/0c8f75f03020c53bcf4c6be258faf433d24b2c2b) + +1.3.4 +----- +* [Use `class << self` instead of `module_function` to create aliases](https://github.com/intridea/multi_json/commit/ba1451c4c48baa297e049889be241a424cb05980) + +1.3.3 +----- +* [Remove deprecation warnings](https://github.com/intridea/multi_json/commit/36b524e71544eb0186826a891bcc03b2820a008f) + +1.3.2 +----- +* [Add ability to use adapter per call](https://github.com/intridea/multi_json/commit/106bbec469d5d0a832bfa31fffcb8c0f0cdc9bd3) +* [Add and deprecate `default_engine` method](https://github.com/intridea/multi_json/commit/fc3df0c7a3e2ab9ce0c2c7e7617a4da97dd13f6e) + +1.3.1 +----- +* [Only warn once for each instance a deprecated method is called](https://github.com/intridea/multi_json/commit/e21d6eb7da74b3f283995c1d27d5880e75f0ae84) + +1.3.0 +----- +* [Implement `load`/`dump`; deprecate `decode`/`encode`](https://github.com/intridea/multi_json/commit/e90fd6cb1b0293eb0c73c2f4eb0f7a1764370216) +* [Rename engines to adapters](https://github.com/intridea/multi_json/commit/ae7fd144a7949a9c221dcaa446196ec23db908df) + +1.2.0 +----- +* [Add support for Oj](https://github.com/intridea/multi_json/commit/acd06b233edabe6c44f226873db7b49dab560c60) + +1.1.0 +----- +* [`NSJSONSerialization` support for MacRuby](https://github.com/intridea/multi_json/commit/f862e2fc966cac8867fe7da3997fc76e8a6cf5d4) + +1.0.4 +----- +* [Set data context to `DecodeError` exception](https://github.com/intridea/multi_json/commit/19ddafd44029c6681f66fae2a0f6eabfd0f85176) +* [Allow `ok_json` to fallback to `to_json`](https://github.com/intridea/multi_json/commit/c157240b1193b283d06d1bd4d4b5b06bcf3761f8) +* [Add warning when using `ok_json`](https://github.com/intridea/multi_json/commit/dd4b68810c84f826fb98f9713bfb29ab96888d57) +* [Options can be passed to an engine on encode](https://github.com/intridea/multi_json/commit/e0a7ff5d5ff621ffccc61617ed8aeec5816e81f7) + +1.0.3 +----- +* [`Array` support for `stringify_keys`](https://github.com/intridea/multi_json/commit/644d1c5c7c7f6a27663b11668527b346094e38b9) +* [`Array` support for `symbolize_keys`](https://github.com/intridea/multi_json/commit/c885377d47a2aa39cb0d971fea78db2d2fa479a7) + +1.0.2 +----- +* [Allow encoding of rootless JSON when `ok_json` is used](https://github.com/intridea/multi_json/commit/d1cde7de97cb0f6152aef8daf14037521cdce8c6) + +1.0.1 +----- +* [Correct an issue with `ok_json` not being returned as the default engine](https://github.com/intridea/multi_json/commit/d33c141619c54cccd770199694da8fd1bd8f449d) + +1.0.0 +----- +* [Remove `ActiveSupport::JSON` support](https://github.com/intridea/multi_json/commit/c2f4140141d785a24b3f56e58811b0e561b37f6a) +* [Fix `@engine` ivar warning](https://github.com/intridea/multi_json/commit/3b978a8995721a8dffedc3b75a7f49e5494ec553) +* [Only `rescue` from parsing errors during decoding, not any `StandardError`](https://github.com/intridea/multi_json/commit/391d00b5e85294d42d41347605d8d46b4a7f66cc) +* [Rename `okjson` engine and vendored lib to `ok_json`](https://github.com/intridea/multi_json/commit/5bd1afc977a8208ddb0443e1d57cb79665c019f1) +* [Add `StringIO` support to `json` gem and `ok_json`](https://github.com/intridea/multi_json/commit/1706b11568db7f50af451fce5f4d679aeb3bbe8f) + +0.0.5 +----- +* [Trap all JSON decoding errors; raise `MultiJson::DecodeError`](https://github.com/intridea/multi_json/commit/dea9a1aef6dd1212aa1e5a37ab1669f9b045b732) + +0.0.4 +----- +* [Fix default_engine check for `json` gem](https://github.com/intridea/multi_json/commit/caced0c4e8c795922a109ebc00c3c4fa8635bed8) +* [Make requirement mapper an `Array` to preserve order in Ruby versions < 1.9](https://github.com/intridea/multi_json/commit/526f5f29a42131574a088ad9bbb43d7f48439b2c) + +0.0.3 +----- +* [Improve defaulting and documentation](https://github.com/sferik/twitter/commit/3a0e41b9e4b0909201045fa47704b78c9d949b73) + +0.0.2 +----- + +* [Rename to `multi_json`](https://github.com/sferik/twitter/commit/461ab89ce071c8c9fabfc183581e0ec523788b62) + +0.0.1 +----- + +* [Initial commit](https://github.com/sferik/twitter/commit/518c21ab299c500527491e6c049ab2229e22a805) diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/CONTRIBUTING.md b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/CONTRIBUTING.md new file mode 100644 index 0000000..3e8bfd5 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/CONTRIBUTING.md @@ -0,0 +1,46 @@ +## Contributing +In the spirit of [free software][free-sw], **everyone** is encouraged to help +improve this project. + +[free-sw]: http://www.fsf.org/licensing/essays/free-sw.html + +Here are some ways *you* can contribute: + +* by using alpha, beta, and prerelease versions +* by reporting bugs +* by suggesting new features +* by writing or editing documentation +* by writing specifications +* by writing code (**no patch is too small**: fix typos, add comments, clean up + inconsistent whitespace) +* by refactoring code +* by closing [issues][] +* by reviewing patches + +[issues]: https://github.com/intridea/multi_json/issues + +## Submitting an Issue +We use the [GitHub issue tracker][issues] to track bugs and features. Before +submitting a bug report or feature request, check to make sure it hasn't +already been submitted. When submitting a bug report, please include a [Gist][] +that includes a stack trace and any details that may be necessary to reproduce +the bug, including your gem version, Ruby version, and operating system. +Ideally, a bug report should include a pull request with failing specs. + +[gist]: https://gist.github.com/ + +## Submitting a Pull Request +1. [Fork the repository.][fork] +2. [Create a topic branch.][branch] +3. Add specs for your unimplemented feature or bug fix. +4. Run `bundle exec rake spec`. If your specs pass, return to step 3. +5. Implement your feature or bug fix. +6. Run `bundle exec rake spec`. If your specs fail, return to step 5. +7. Run `open coverage/index.html`. If your changes are not completely covered + by your tests, return to step 3. +8. Add, commit, and push your changes. +9. [Submit a pull request.][pr] + +[fork]: http://help.github.com/fork-a-repo/ +[branch]: http://learn.github.com/p/branching.html +[pr]: http://help.github.com/send-pull-requests/ diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/LICENSE.md b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/LICENSE.md new file mode 100644 index 0000000..1768f37 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/LICENSE.md @@ -0,0 +1,20 @@ +Copyright (c) 2010-2013 Michael Bleigh, Josh Kalderimis, Erik Michaels-Ober, Pavel Pravosud + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/README.md b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/README.md new file mode 100644 index 0000000..ee8b86e --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/README.md @@ -0,0 +1,121 @@ +# MultiJSON + +[![Gem Version](http://img.shields.io/gem/v/multi_json.svg)][gem] +[![Build Status](http://travis-ci.org/intridea/multi_json.svg)][travis] +[![Dependency Status](http://img.shields.io/gemnasium/intridea/multi_json.svg)][gemnasium] +[![Code Climate](http://img.shields.io/codeclimate/github/intridea/multi_json.svg)][codeclimate] + +[gem]: https://rubygems.org/gems/multi_json +[travis]: http://travis-ci.org/intridea/multi_json +[gemnasium]: https://gemnasium.com/intridea/multi_json +[codeclimate]: https://codeclimate.com/github/intridea/multi_json + +Lots of Ruby libraries parse JSON and everyone has their favorite JSON coder. +Instead of choosing a single JSON coder and forcing users of your library to be +stuck with it, you can use MultiJSON instead, which will simply choose the +fastest available JSON coder. Here's how to use it: + +```ruby +require 'multi_json' + +MultiJson.load('{"abc":"def"}') #=> {"abc" => "def"} +MultiJson.load('{"abc":"def"}', :symbolize_keys => true) #=> {:abc => "def"} +MultiJson.dump({:abc => 'def'}) # convert Ruby back to JSON +MultiJson.dump({:abc => 'def'}, :pretty => true) # encoded in a pretty form (if supported by the coder) +``` + +When loading invalid JSON, MultiJson will throw a `MultiJson::ParseError`. `MultiJson::DecodeError` and `MultiJson::LoadError` are aliases for backwards compatibility. + +```ruby +begin + MultiJson.load('{invalid json}') +rescue MultiJson::ParseError => exception + exception.data # => "{invalid json}" + exception.cause # => JSON::ParserError: 795: unexpected token at '{invalid json}' +end +``` + +`ParseError` instance has `cause` reader which contains the original exception. +It also has `data` reader with the input that caused the problem. + +The `use` method, which sets the MultiJson adapter, takes either a symbol or a +class (to allow for custom JSON parsers) that responds to both `.load` and `.dump` +at the class level. + +When MultiJson fails to load the specified adapter, it'll throw `MultiJson::AdapterError` +which inherits from `ArgumentError`. + +MultiJSON tries to have intelligent defaulting. That is, if you have any of the +supported engines already loaded, it will utilize them before attempting to +load any. When loading, libraries are ordered by speed. First Oj, then Yajl, +then the JSON gem, then JSON pure. If no other JSON library is available, +MultiJSON falls back to [OkJson][], a simple, vendorable JSON parser. + +[okjson]: https://github.com/kr/okjson + +## Supported JSON Engines + +* [Oj](https://github.com/ohler55/oj) Optimized JSON by Peter Ohler +* [Yajl](https://github.com/brianmario/yajl-ruby) Yet Another JSON Library by Brian Lopez +* [JSON](https://github.com/flori/json) The default JSON gem with C-extensions (ships with Ruby 1.9) +* [JSON Pure](https://github.com/flori/json) A Ruby variant of the JSON gem +* [NSJSONSerialization](https://developer.apple.com/library/ios/#documentation/Foundation/Reference/NSJSONSerialization_Class/Reference/Reference.html) Wrapper for Apple's NSJSONSerialization in the Cocoa Framework (MacRuby only) +* [gson.rb](https://github.com/avsej/gson.rb) A Ruby wrapper for google-gson library (JRuby only) +* [JrJackson](https://github.com/guyboertje/jrjackson) JRuby wrapper for Jackson (JRuby only) +* [OkJson][okjson] A simple, vendorable JSON parser + +## Supported Ruby Versions +This library aims to support and is [tested against][travis] the following Ruby +implementations: + +* Ruby 1.8.7 +* Ruby 1.9.2 +* Ruby 1.9.3 +* Ruby 2.0.0 +* Ruby 2.1 +* Ruby 2.2.4 +* Ruby 2.3.1 +* [JRuby][] +* [Rubinius][] +* [MacRuby][] (not tested on Travis CI) + +[jruby]: http://www.jruby.org/ +[rubinius]: http://rubini.us/ +[macruby]: http://www.macruby.org/ + +If something doesn't work on one of these interpreters, it's a bug. + +This library may inadvertently work (or seem to work) on other Ruby +implementations, however support will only be provided for the versions listed +above. + +If you would like this library to support another Ruby version, you may +volunteer to be a maintainer. Being a maintainer entails making sure all tests +run and pass on that implementation. When something breaks on your +implementation, you will be responsible for providing patches in a timely +fashion. If critical issues for a particular implementation exist at the time +of a major release, support for that Ruby version may be dropped. + +## Versioning + +This library aims to adhere to [Semantic Versioning 2.0.0][semver]. Violations +of this scheme should be reported as bugs. Specifically, if a minor or patch +version is released that breaks backward compatibility, that version should be +immediately yanked and/or a new version should be immediately released that +restores compatibility. Breaking changes to the public API will only be +introduced with new major versions. As a result of this policy, you can (and +should) specify a dependency on this gem using the [Pessimistic Version +Constraint][pvc] with two digits of precision. For example: + +```ruby +spec.add_dependency 'multi_json', '~> 1.0' +``` + +[semver]: http://semver.org/ +[pvc]: http://docs.rubygems.org/read/chapter/16#page74 + +## Copyright +Copyright (c) 2010-2013 Michael Bleigh, Josh Kalderimis, Erik Michaels-Ober, +and Pavel Pravosud. See [LICENSE][] for details. + +[license]: LICENSE.md diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json.rb new file mode 100644 index 0000000..02c7250 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json.rb @@ -0,0 +1,161 @@ +require 'multi_json/options' +require 'multi_json/version' +require 'multi_json/adapter_error' +require 'multi_json/parse_error' +require 'multi_json/options_cache' + +module MultiJson + include Options + extend self + + def default_options=(value) + Kernel.warn "MultiJson.default_options setter is deprecated\n" \ + 'Use MultiJson.load_options and MultiJson.dump_options instead' + + self.load_options = self.dump_options = value + end + + def default_options + Kernel.warn "MultiJson.default_options is deprecated\n" \ + 'Use MultiJson.load_options or MultiJson.dump_options instead' + + load_options + end + + %w(cached_options reset_cached_options!).each do |method_name| + define_method method_name do |*| + Kernel.warn "MultiJson.#{method_name} method is deprecated and no longer used." + end + end + + ALIASES = {'jrjackson' => 'jr_jackson'} + + REQUIREMENT_MAP = [ + [:oj, 'oj'], + [:yajl, 'yajl'], + [:jr_jackson, 'jrjackson'], + [:json_gem, 'json/ext'], + [:gson, 'gson'], + [:json_pure, 'json/pure'], + ] + + # The default adapter based on what you currently + # have loaded and installed. First checks to see + # if any adapters are already loaded, then checks + # to see which are installed if none are loaded. + def default_adapter + return :oj if defined?(::Oj) + return :yajl if defined?(::Yajl) + return :jr_jackson if defined?(::JrJackson) + return :json_gem if defined?(::JSON::JSON_LOADED) + return :gson if defined?(::Gson) + + REQUIREMENT_MAP.each do |adapter, library| + begin + require library + return adapter + rescue ::LoadError + next + end + end + + Kernel.warn '[WARNING] MultiJson is using the default adapter (ok_json). ' \ + 'We recommend loading a different JSON library to improve performance.' + + :ok_json + end + alias_method :default_engine, :default_adapter + + # Get the current adapter class. + def adapter + return @adapter if defined?(@adapter) && @adapter + + use nil # load default adapter + + @adapter + end + alias_method :engine, :adapter + + # Set the JSON parser utilizing a symbol, string, or class. + # Supported by default are: + # + # * :oj + # * :json_gem + # * :json_pure + # * :ok_json + # * :yajl + # * :nsjsonserialization (MacRuby only) + # * :gson (JRuby only) + # * :jr_jackson (JRuby only) + def use(new_adapter) + @adapter = load_adapter(new_adapter) + ensure + OptionsCache.reset + end + alias_method :adapter=, :use + alias_method :engine=, :use + + def load_adapter(new_adapter) + case new_adapter + when String, Symbol + load_adapter_from_string_name new_adapter.to_s + when NilClass, FalseClass + load_adapter default_adapter + when Class, Module + new_adapter + else + fail ::LoadError, new_adapter + end + rescue ::LoadError => exception + raise AdapterError.build(exception) + end + + # Decode a JSON string into Ruby. + # + # Options + # + # :symbolize_keys :: If true, will use symbols instead of strings for the keys. + # :adapter :: If set, the selected adapter will be used for this call. + def load(string, options = {}) + adapter = current_adapter(options) + begin + adapter.load(string, options) + rescue adapter::ParseError => exception + raise ParseError.build(exception, string) + end + end + alias_method :decode, :load + + def current_adapter(options = {}) + if (new_adapter = options[:adapter]) + load_adapter(new_adapter) + else + adapter + end + end + + # Encodes a Ruby object as JSON. + def dump(object, options = {}) + current_adapter(options).dump(object, options) + end + alias_method :encode, :dump + + # Executes passed block using specified adapter. + def with_adapter(new_adapter) + old_adapter = adapter + self.adapter = new_adapter + yield + ensure + self.adapter = old_adapter + end + alias_method :with_engine, :with_adapter + +private + + def load_adapter_from_string_name(name) + name = ALIASES.fetch(name, name) + require "multi_json/adapters/#{name.downcase}" + klass_name = name.to_s.split('_').map(&:capitalize) * '' + MultiJson::Adapters.const_get(klass_name) + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapter.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapter.rb new file mode 100644 index 0000000..1d54d9a --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapter.rb @@ -0,0 +1,49 @@ +require 'singleton' +require 'multi_json/options' + +module MultiJson + class Adapter + extend Options + include Singleton + + class << self + def defaults(action, value) + metaclass = class << self; self; end + + metaclass.instance_eval do + define_method("default_#{action}_options") { value } + end + end + + def load(string, options = {}) + fail self::ParseError if blank?(string) + string = string.read if string.respond_to?(:read) + instance.load(string, cached_load_options(options)) + end + + def dump(object, options = {}) + instance.dump(object, cached_dump_options(options)) + end + + private + + def blank?(input) + input.nil? || /\A\s*\z/ === input + rescue ArgumentError # invalid byte sequence in UTF-8 + false + end + + def cached_dump_options(options) + OptionsCache.fetch(:dump, options) do + dump_options(options).merge(MultiJson.dump_options(options)).merge!(options) + end + end + + def cached_load_options(options) + OptionsCache.fetch(:load, options) do + load_options(options).merge(MultiJson.load_options(options)).merge!(options) + end + end + end + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapter_error.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapter_error.rb new file mode 100644 index 0000000..86902b6 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapter_error.rb @@ -0,0 +1,15 @@ +module MultiJson + class AdapterError < ArgumentError + attr_reader :cause + + def self.build(original_exception) + message = "Did not recognize your adapter specification (#{original_exception.message})." + new(message).tap do |exception| + exception.instance_eval do + @cause = original_exception + set_backtrace original_exception.backtrace + end + end + end + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapters/gson.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapters/gson.rb new file mode 100644 index 0000000..797fbf4 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapters/gson.rb @@ -0,0 +1,20 @@ +require 'gson' +require 'stringio' +require 'multi_json/adapter' + +module MultiJson + module Adapters + # Use the gson.rb library to dump/load. + class Gson < Adapter + ParseError = ::Gson::DecodeError + + def load(string, options = {}) + ::Gson::Decoder.new(options).decode(string) + end + + def dump(object, options = {}) + ::Gson::Encoder.new(options).encode(object) + end + end + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapters/jr_jackson.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapters/jr_jackson.rb new file mode 100644 index 0000000..a7e6cd8 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapters/jr_jackson.rb @@ -0,0 +1,25 @@ +require 'jrjackson' unless defined?(::JrJackson) +require 'multi_json/adapter' + +module MultiJson + module Adapters + # Use the jrjackson.rb library to dump/load. + class JrJackson < Adapter + ParseError = ::JrJackson::ParseError + + def load(string, options = {}) #:nodoc: + ::JrJackson::Json.load(string, options) + end + + if ::JrJackson::Json.method(:dump).arity == 1 + def dump(object, _) + ::JrJackson::Json.dump(object) + end + else + def dump(object, options = {}) + ::JrJackson::Json.dump(object, options) + end + end + end + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapters/json_common.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapters/json_common.rb new file mode 100644 index 0000000..e188895 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapters/json_common.rb @@ -0,0 +1,23 @@ +require 'multi_json/adapter' + +module MultiJson + module Adapters + class JsonCommon < Adapter + defaults :load, :create_additions => false, :quirks_mode => true + + def load(string, options = {}) + if string.respond_to?(:force_encoding) + string = string.dup.force_encoding(::Encoding::ASCII_8BIT) + end + + options[:symbolize_names] = true if options.delete(:symbolize_keys) + ::JSON.parse(string, options) + end + + def dump(object, options = {}) + options.merge!(::JSON::PRETTY_STATE_PROTOTYPE.to_h) if options.delete(:pretty) + object.to_json(options) + end + end + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapters/json_gem.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapters/json_gem.rb new file mode 100644 index 0000000..035de37 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapters/json_gem.rb @@ -0,0 +1,11 @@ +require 'json/ext' +require 'multi_json/adapters/json_common' + +module MultiJson + module Adapters + # Use the JSON gem to dump/load. + class JsonGem < JsonCommon + ParseError = ::JSON::ParserError + end + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapters/json_pure.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapters/json_pure.rb new file mode 100644 index 0000000..c5d7036 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapters/json_pure.rb @@ -0,0 +1,11 @@ +require 'json/pure' +require 'multi_json/adapters/json_common' + +module MultiJson + module Adapters + # Use JSON pure to dump/load. + class JsonPure < JsonCommon + ParseError = ::JSON::ParserError + end + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapters/nsjsonserialization.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapters/nsjsonserialization.rb new file mode 100644 index 0000000..207b0e2 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapters/nsjsonserialization.rb @@ -0,0 +1,32 @@ +framework 'Foundation' +require 'multi_json/adapters/ok_json' + +module MultiJson + module Adapters + class Nsjsonserialization < MultiJson::Adapters::OkJson + ParseError = ::MultiJson::OkJson::Error + + def load(string, options = {}) + data = string.dataUsingEncoding(NSUTF8StringEncoding) + object = NSJSONSerialization.JSONObjectWithData(data, :options => NSJSONReadingMutableContainers | NSJSONReadingMutableLeaves, :error => nil) + if object + object = symbolize_keys(object) if options[:symbolize_keys] + object + else + super(string, options) + end + end + + def dump(object, options = {}) + pretty = options[:pretty] ? NSJSONWritingPrettyPrinted : 0 + object = object.as_json if object.respond_to?(:as_json) + if NSJSONSerialization.isValidJSONObject(object) + data = NSJSONSerialization.dataWithJSONObject(object, :options => pretty, :error => nil) + NSMutableString.alloc.initWithData(data, :encoding => NSUTF8StringEncoding) + else + super(object, options) + end + end + end + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapters/oj.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapters/oj.rb new file mode 100644 index 0000000..7d6c1f8 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapters/oj.rb @@ -0,0 +1,25 @@ +require 'oj' +require 'multi_json/adapter' + +module MultiJson + module Adapters + # Use the Oj library to dump/load. + class Oj < Adapter + defaults :load, :mode => :strict, :symbolize_keys => false + defaults :dump, :mode => :compat, :time_format => :ruby, :use_to_json => true + + ParseError = defined?(::Oj::ParseError) ? ::Oj::ParseError : SyntaxError + + def load(string, options = {}) + options[:symbol_keys] = options[:symbolize_keys] + ::Oj.load(string, options) + end + + def dump(object, options = {}) + options.merge!(:indent => 2) if options[:pretty] + options[:indent] = options[:indent].to_i if options[:indent] + ::Oj.dump(object, options) + end + end + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapters/ok_json.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapters/ok_json.rb new file mode 100644 index 0000000..7f51145 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapters/ok_json.rb @@ -0,0 +1,23 @@ +require 'multi_json/adapter' +require 'multi_json/convertible_hash_keys' +require 'multi_json/vendor/okjson' + +module MultiJson + module Adapters + class OkJson < Adapter + include ConvertibleHashKeys + ParseError = ::MultiJson::OkJson::Error + + def load(string, options = {}) + result = ::MultiJson::OkJson.decode("[#{string}]").first + options[:symbolize_keys] ? symbolize_keys(result) : result + rescue ArgumentError # invalid byte sequence in UTF-8 + raise ParseError + end + + def dump(object, _ = {}) + ::MultiJson::OkJson.valenc(stringify_keys(object)) + end + end + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapters/yajl.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapters/yajl.rb new file mode 100644 index 0000000..1c297a5 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapters/yajl.rb @@ -0,0 +1,19 @@ +require 'yajl' +require 'multi_json/adapter' + +module MultiJson + module Adapters + # Use the Yajl-Ruby library to dump/load. + class Yajl < Adapter + ParseError = ::Yajl::ParseError + + def load(string, options = {}) + ::Yajl::Parser.new(:symbolize_keys => options[:symbolize_keys]).parse(string) + end + + def dump(object, options = {}) + ::Yajl::Encoder.encode(object, options) + end + end + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/convertible_hash_keys.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/convertible_hash_keys.rb new file mode 100644 index 0000000..1253e66 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/convertible_hash_keys.rb @@ -0,0 +1,43 @@ +module MultiJson + module ConvertibleHashKeys + private + + def symbolize_keys(hash) + prepare_hash(hash) do |key| + key.respond_to?(:to_sym) ? key.to_sym : key + end + end + + def stringify_keys(hash) + prepare_hash(hash) do |key| + key.respond_to?(:to_s) ? key.to_s : key + end + end + + def prepare_hash(hash, &key_modifier) + return hash unless block_given? + case hash + when Array + hash.map do |value| + prepare_hash(value, &key_modifier) + end + when Hash + hash.inject({}) do |result, (key, value)| + new_key = key_modifier.call(key) + new_value = prepare_hash(value, &key_modifier) + result.merge! new_key => new_value + end + when String, Numeric, true, false, nil + hash + else + if hash.respond_to?(:to_json) + hash + elsif hash.respond_to?(:to_s) + hash.to_s + else + hash + end + end + end + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/options.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/options.rb new file mode 100644 index 0000000..a56a90e --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/options.rb @@ -0,0 +1,39 @@ +module MultiJson + module Options + def load_options=(options) + OptionsCache.reset + @load_options = options + end + + def dump_options=(options) + OptionsCache.reset + @dump_options = options + end + + def load_options(*args) + defined?(@load_options) && get_options(@load_options, *args) || default_load_options + end + + def dump_options(*args) + defined?(@dump_options) && get_options(@dump_options, *args) || default_dump_options + end + + def default_load_options + @default_load_options ||= {} + end + + def default_dump_options + @default_dump_options ||= {} + end + + private + + def get_options(options, *args) + if options.respond_to?(:call) && options.arity + options.arity == 0 ? options[] : options[*args] + elsif options.respond_to?(:to_hash) + options.to_hash + end + end + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/options_cache.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/options_cache.rb new file mode 100644 index 0000000..05bf59d --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/options_cache.rb @@ -0,0 +1,29 @@ +module MultiJson + module OptionsCache + extend self + + def reset + @dump_cache = {} + @load_cache = {} + end + + def fetch(type, key) + cache = instance_variable_get("@#{type}_cache") + cache.key?(key) ? cache[key] : write(cache, key, &Proc.new) + end + + private + + # Normally MultiJson is used with a few option sets for both dump/load + # methods. When options are generated dynamically though, every call would + # cause a cache miss and the cache would grow indefinitely. To prevent + # this, we just reset the cache every time the number of keys outgrows + # 1000. + MAX_CACHE_SIZE = 1000 + + def write(cache, key) + cache.clear if cache.length >= MAX_CACHE_SIZE + cache[key] = yield + end + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/parse_error.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/parse_error.rb new file mode 100644 index 0000000..407a622 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/parse_error.rb @@ -0,0 +1,17 @@ +module MultiJson + class ParseError < StandardError + attr_reader :data, :cause + + def self.build(original_exception, data) + new(original_exception.message).tap do |exception| + exception.instance_eval do + @cause = original_exception + set_backtrace original_exception.backtrace + @data = data + end + end + end + end + + DecodeError = LoadError = ParseError # Legacy support +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/vendor/okjson.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/vendor/okjson.rb new file mode 100644 index 0000000..0d5f814 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/vendor/okjson.rb @@ -0,0 +1,606 @@ +# encoding: UTF-8 +# +# Copyright 2011, 2012 Keith Rarick +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. + +# See https://github.com/kr/okjson for updates. + +require 'stringio' + +module MultiJson + # Some parts adapted from + # https://golang.org/src/encoding/json/decode.go and + # https://golang.org/src/unicode/utf8/utf8.go + module OkJson + Upstream = '45' + extend self + + + # Decodes a json document in string s and + # returns the corresponding ruby value. + # String s must be valid UTF-8. If you have + # a string in some other encoding, convert + # it first. + # + # String values in the resulting structure + # will be UTF-8. + def decode(s) + ts = lex(s) + v, ts = textparse(ts) + if ts.length > 0 + raise Error, 'trailing garbage' + end + v + end + + + # Encodes x into a json text. It may contain only + # Array, Hash, String, Numeric, true, false, nil. + # (Note, this list excludes Symbol.) + # X itself must be an Array or a Hash. + # No other value can be encoded, and an error will + # be raised if x contains any other value, such as + # Nan, Infinity, Symbol, and Proc, or if a Hash key + # is not a String. + # Strings contained in x must be valid UTF-8. + def encode(x) + case x + when Hash then objenc(x) + when Array then arrenc(x) + else + raise Error, 'root value must be an Array or a Hash' + end + end + + + def valenc(x) + case x + when Hash then objenc(x) + when Array then arrenc(x) + when String then strenc(x) + when Numeric then numenc(x) + when true then "true" + when false then "false" + when nil then "null" + else + if x.respond_to?(:to_json) + x.to_json + else + raise Error, "cannot encode #{x.class}: #{x.inspect}" + end + end + end + + + private + + + # Parses a "json text" in the sense of RFC 4627. + # Returns the parsed value and any trailing tokens. + # Note: this is almost the same as valparse, + # except that it does not accept atomic values. + def textparse(ts) + if ts.length <= 0 + raise Error, 'empty' + end + + typ, _, val = ts[0] + case typ + when '{' then objparse(ts) + when '[' then arrparse(ts) + else + raise Error, "unexpected #{val.inspect}" + end + end + + + # Parses a "value" in the sense of RFC 4627. + # Returns the parsed value and any trailing tokens. + def valparse(ts) + if ts.length <= 0 + raise Error, 'empty' + end + + typ, _, val = ts[0] + case typ + when '{' then objparse(ts) + when '[' then arrparse(ts) + when :val,:str then [val, ts[1..-1]] + else + raise Error, "unexpected #{val.inspect}" + end + end + + + # Parses an "object" in the sense of RFC 4627. + # Returns the parsed value and any trailing tokens. + def objparse(ts) + ts = eat('{', ts) + obj = {} + + if ts[0][0] == '}' + return obj, ts[1..-1] + end + + k, v, ts = pairparse(ts) + obj[k] = v + + if ts[0][0] == '}' + return obj, ts[1..-1] + end + + loop do + ts = eat(',', ts) + + k, v, ts = pairparse(ts) + obj[k] = v + + if ts[0][0] == '}' + return obj, ts[1..-1] + end + end + end + + + # Parses a "member" in the sense of RFC 4627. + # Returns the parsed values and any trailing tokens. + def pairparse(ts) + (typ, _, k), ts = ts[0], ts[1..-1] + if typ != :str + raise Error, "unexpected #{k.inspect}" + end + ts = eat(':', ts) + v, ts = valparse(ts) + [k, v, ts] + end + + + # Parses an "array" in the sense of RFC 4627. + # Returns the parsed value and any trailing tokens. + def arrparse(ts) + ts = eat('[', ts) + arr = [] + + if ts[0][0] == ']' + return arr, ts[1..-1] + end + + v, ts = valparse(ts) + arr << v + + if ts[0][0] == ']' + return arr, ts[1..-1] + end + + loop do + ts = eat(',', ts) + + v, ts = valparse(ts) + arr << v + + if ts[0][0] == ']' + return arr, ts[1..-1] + end + end + end + + + def eat(typ, ts) + if ts[0][0] != typ + raise Error, "expected #{typ} (got #{ts[0].inspect})" + end + ts[1..-1] + end + + + # Scans s and returns a list of json tokens, + # excluding white space (as defined in RFC 4627). + def lex(s) + ts = [] + while s.length > 0 + typ, lexeme, val = tok(s) + if typ == nil + raise Error, "invalid character at #{s[0,10].inspect}" + end + if typ != :space + ts << [typ, lexeme, val] + end + s = s[lexeme.length..-1] + end + ts + end + + + # Scans the first token in s and + # returns a 3-element list, or nil + # if s does not begin with a valid token. + # + # The first list element is one of + # '{', '}', ':', ',', '[', ']', + # :val, :str, and :space. + # + # The second element is the lexeme. + # + # The third element is the value of the + # token for :val and :str, otherwise + # it is the lexeme. + def tok(s) + case s[0] + when ?{ then ['{', s[0,1], s[0,1]] + when ?} then ['}', s[0,1], s[0,1]] + when ?: then [':', s[0,1], s[0,1]] + when ?, then [',', s[0,1], s[0,1]] + when ?[ then ['[', s[0,1], s[0,1]] + when ?] then [']', s[0,1], s[0,1]] + when ?n then nulltok(s) + when ?t then truetok(s) + when ?f then falsetok(s) + when ?" then strtok(s) + when Spc, ?\t, ?\n, ?\r then [:space, s[0,1], s[0,1]] + else + numtok(s) + end + end + + + def nulltok(s); s[0,4] == 'null' ? [:val, 'null', nil] : [] end + def truetok(s); s[0,4] == 'true' ? [:val, 'true', true] : [] end + def falsetok(s); s[0,5] == 'false' ? [:val, 'false', false] : [] end + + + def numtok(s) + m = /(-?(?:[1-9][0-9]+|[0-9]))([.][0-9]+)?([eE][+-]?[0-9]+)?/.match(s) + if m && m.begin(0) == 0 + if !m[2] && !m[3] + [:val, m[0], Integer(m[0])] + elsif m[2] + [:val, m[0], Float(m[0])] + else + [:val, m[0], Integer(m[1])*(10**m[3][1..-1].to_i(10))] + end + else + [] + end + end + + + def strtok(s) + m = /"([^"\\]|\\["\/\\bfnrt]|\\u[0-9a-fA-F]{4})*"/.match(s) + if ! m + raise Error, "invalid string literal at #{abbrev(s)}" + end + [:str, m[0], unquote(m[0])] + end + + + def abbrev(s) + t = s[0,10] + p = t['`'] + t = t[0,p] if p + t = t + '...' if t.length < s.length + '`' + t + '`' + end + + + # Converts a quoted json string literal q into a UTF-8-encoded string. + # The rules are different than for Ruby, so we cannot use eval. + # Unquote will raise an error if q contains control characters. + def unquote(q) + q = q[1...-1] + a = q.dup # allocate a big enough string + # In ruby >= 1.9, a[w] is a codepoint, not a byte. + if rubydoesenc? + a.force_encoding('UTF-8') + end + r, w = 0, 0 + while r < q.length + c = q[r] + if c == ?\\ + r += 1 + if r >= q.length + raise Error, "string literal ends with a \"\\\": \"#{q}\"" + end + + case q[r] + when ?",?\\,?/,?' + a[w] = q[r] + r += 1 + w += 1 + when ?b,?f,?n,?r,?t + a[w] = Unesc[q[r]] + r += 1 + w += 1 + when ?u + r += 1 + uchar = begin + hexdec4(q[r,4]) + rescue RuntimeError => e + raise Error, "invalid escape sequence \\u#{q[r,4]}: #{e}" + end + r += 4 + if surrogate? uchar + if q.length >= r+6 + uchar1 = hexdec4(q[r+2,4]) + uchar = subst(uchar, uchar1) + if uchar != Ucharerr + # A valid pair; consume. + r += 6 + end + end + end + if rubydoesenc? + a[w] = '' << uchar + w += 1 + else + w += ucharenc(a, w, uchar) + end + else + raise Error, "invalid escape char #{q[r]} in \"#{q}\"" + end + elsif c == ?" || c < Spc + raise Error, "invalid character in string literal \"#{q}\"" + else + # Copy anything else byte-for-byte. + # Valid UTF-8 will remain valid UTF-8. + # Invalid UTF-8 will remain invalid UTF-8. + # In ruby >= 1.9, c is a codepoint, not a byte, + # in which case this is still what we want. + a[w] = c + r += 1 + w += 1 + end + end + a[0,w] + end + + + # Encodes unicode character u as UTF-8 + # bytes in string a at position i. + # Returns the number of bytes written. + def ucharenc(a, i, u) + if u <= Uchar1max + a[i] = (u & 0xff).chr + 1 + elsif u <= Uchar2max + a[i+0] = (Utag2 | ((u>>6)&0xff)).chr + a[i+1] = (Utagx | (u&Umaskx)).chr + 2 + elsif u <= Uchar3max + a[i+0] = (Utag3 | ((u>>12)&0xff)).chr + a[i+1] = (Utagx | ((u>>6)&Umaskx)).chr + a[i+2] = (Utagx | (u&Umaskx)).chr + 3 + else + a[i+0] = (Utag4 | ((u>>18)&0xff)).chr + a[i+1] = (Utagx | ((u>>12)&Umaskx)).chr + a[i+2] = (Utagx | ((u>>6)&Umaskx)).chr + a[i+3] = (Utagx | (u&Umaskx)).chr + 4 + end + end + + + def hexdec4(s) + if s.length != 4 + raise Error, 'short' + end + (nibble(s[0])<<12) | (nibble(s[1])<<8) | (nibble(s[2])<<4) | nibble(s[3]) + end + + + def subst(u1, u2) + if Usurr1 <= u1 && u1 < Usurr2 && Usurr2 <= u2 && u2 < Usurr3 + return ((u1-Usurr1)<<10) | (u2-Usurr2) + Usurrself + end + return Ucharerr + end + + + def surrogate?(u) + Usurr1 <= u && u < Usurr3 + end + + + def nibble(c) + if ?0 <= c && c <= ?9 then c.ord - ?0.ord + elsif ?a <= c && c <= ?z then c.ord - ?a.ord + 10 + elsif ?A <= c && c <= ?Z then c.ord - ?A.ord + 10 + else + raise Error, "invalid hex code #{c}" + end + end + + + def objenc(x) + '{' + x.map{|k,v| keyenc(k) + ':' + valenc(v)}.join(',') + '}' + end + + + def arrenc(a) + '[' + a.map{|x| valenc(x)}.join(',') + ']' + end + + + def keyenc(k) + case k + when String then strenc(k) + else + raise Error, "Hash key is not a string: #{k.inspect}" + end + end + + + def strenc(s) + t = StringIO.new + t.putc(?") + r = 0 + + while r < s.length + case s[r] + when ?" then t.print('\\"') + when ?\\ then t.print('\\\\') + when ?\b then t.print('\\b') + when ?\f then t.print('\\f') + when ?\n then t.print('\\n') + when ?\r then t.print('\\r') + when ?\t then t.print('\\t') + else + c = s[r] + # In ruby >= 1.9, s[r] is a codepoint, not a byte. + if rubydoesenc? + begin + # c.ord will raise an error if c is invalid UTF-8 + if c.ord < Spc.ord + c = "\\u%04x" % [c.ord] + end + t.write(c) + rescue + t.write(Ustrerr) + end + elsif c < Spc + t.write("\\u%04x" % c) + elsif Spc <= c && c <= ?~ + t.putc(c) + else + n = ucharcopy(t, s, r) # ensure valid UTF-8 output + r += n - 1 # r is incremented below + end + end + r += 1 + end + t.putc(?") + t.string + end + + + def numenc(x) + if ((x.nan? || x.infinite?) rescue false) + raise Error, "Numeric cannot be represented: #{x}" + end + "#{x}" + end + + + # Copies the valid UTF-8 bytes of a single character + # from string s at position i to I/O object t, and + # returns the number of bytes copied. + # If no valid UTF-8 char exists at position i, + # ucharcopy writes Ustrerr and returns 1. + def ucharcopy(t, s, i) + n = s.length - i + raise Utf8Error if n < 1 + + c0 = s[i].ord + + # 1-byte, 7-bit sequence? + if c0 < Utagx + t.putc(c0) + return 1 + end + + raise Utf8Error if c0 < Utag2 # unexpected continuation byte? + + raise Utf8Error if n < 2 # need continuation byte + c1 = s[i+1].ord + raise Utf8Error if c1 < Utagx || Utag2 <= c1 + + # 2-byte, 11-bit sequence? + if c0 < Utag3 + raise Utf8Error if ((c0&Umask2)<<6 | (c1&Umaskx)) <= Uchar1max + t.putc(c0) + t.putc(c1) + return 2 + end + + # need second continuation byte + raise Utf8Error if n < 3 + + c2 = s[i+2].ord + raise Utf8Error if c2 < Utagx || Utag2 <= c2 + + # 3-byte, 16-bit sequence? + if c0 < Utag4 + u = (c0&Umask3)<<12 | (c1&Umaskx)<<6 | (c2&Umaskx) + raise Utf8Error if u <= Uchar2max + t.putc(c0) + t.putc(c1) + t.putc(c2) + return 3 + end + + # need third continuation byte + raise Utf8Error if n < 4 + c3 = s[i+3].ord + raise Utf8Error if c3 < Utagx || Utag2 <= c3 + + # 4-byte, 21-bit sequence? + if c0 < Utag5 + u = (c0&Umask4)<<18 | (c1&Umaskx)<<12 | (c2&Umaskx)<<6 | (c3&Umaskx) + raise Utf8Error if u <= Uchar3max + t.putc(c0) + t.putc(c1) + t.putc(c2) + t.putc(c3) + return 4 + end + + raise Utf8Error + rescue Utf8Error + t.write(Ustrerr) + return 1 + end + + + def rubydoesenc? + ::String.method_defined?(:force_encoding) + end + + + class Utf8Error < ::StandardError + end + + + class Error < ::StandardError + end + + + Utagx = 0b1000_0000 + Utag2 = 0b1100_0000 + Utag3 = 0b1110_0000 + Utag4 = 0b1111_0000 + Utag5 = 0b1111_1000 + Umaskx = 0b0011_1111 + Umask2 = 0b0001_1111 + Umask3 = 0b0000_1111 + Umask4 = 0b0000_0111 + Uchar1max = (1<<7) - 1 + Uchar2max = (1<<11) - 1 + Uchar3max = (1<<16) - 1 + Ucharerr = 0xFFFD # unicode "replacement char" + Ustrerr = "\xef\xbf\xbd" # unicode "replacement char" + Usurrself = 0x10000 + Usurr1 = 0xd800 + Usurr2 = 0xdc00 + Usurr3 = 0xe000 + + Spc = ' '[0] + Unesc = {?b=>?\b, ?f=>?\f, ?n=>?\n, ?r=>?\r, ?t=>?\t} + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/version.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/version.rb new file mode 100644 index 0000000..bc37e01 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/version.rb @@ -0,0 +1,17 @@ +module MultiJson + class Version + MAJOR = 1 unless defined? MultiJson::Version::MAJOR + MINOR = 12 unless defined? MultiJson::Version::MINOR + PATCH = 1 unless defined? MultiJson::Version::PATCH + PRE = nil unless defined? MultiJson::Version::PRE + + class << self + # @return [String] + def to_s + [MAJOR, MINOR, PATCH, PRE].compact.join('.') + end + end + end + + VERSION = Version.to_s.freeze +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/multi_json.gemspec b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/multi_json.gemspec new file mode 100644 index 0000000..e9de919 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/multi_json.gemspec @@ -0,0 +1,20 @@ +# coding: utf-8 +require File.expand_path('../lib/multi_json/version.rb', __FILE__) + +Gem::Specification.new do |spec| + spec.authors = ['Michael Bleigh', 'Josh Kalderimis', 'Erik Michaels-Ober', 'Pavel Pravosud'] + spec.cert_chain = %w(certs/rwz.pem) + spec.summary = 'A common interface to multiple JSON libraries.' + spec.description = 'A common interface to multiple JSON libraries, including Oj, Yajl, the JSON gem (with C-extensions), the pure-Ruby JSON gem, NSJSONSerialization, gson.rb, JrJackson, and OkJson.' + spec.email = %w(michael@intridea.com josh.kalderimis@gmail.com sferik@gmail.com pavel@pravosud.com) + spec.files = Dir['CHANGELOG.md', 'CONTRIBUTING.md', 'LICENSE.md', 'README.md', 'multi_json.gemspec', 'lib/**/*'] + spec.homepage = 'http://github.com/intridea/multi_json' + spec.license = 'MIT' + spec.name = 'multi_json' + spec.require_path = 'lib' + spec.signing_key = File.expand_path('~/.ssh/gem-private_key.pem') if $PROGRAM_NAME =~ /gem\z/ + spec.version = MultiJson::Version + + spec.required_rubygems_version = '>= 1.3.5' + spec.add_development_dependency 'bundler', '~> 1.0' +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/CHANGELOG.md b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/CHANGELOG.md new file mode 100644 index 0000000..00b2aa1 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/CHANGELOG.md @@ -0,0 +1,47 @@ +#Change Log +This project adheres to [Semantic Versioning](http://semver.org/). + +This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachangelog.com/) + +## [Unreleased] + +## [1.0.0] - 2016-06-15 +### Changed +- Modified check-cpu.rb to change state if >= threshold +- Updated Rubocop to 0.40, applied auto-correct +- Loosened sensu-plugin dependency to ~> 1.2 +- Specify the /proc location for use within a container + +### Added +- Added metrics-numastat.rb +- check-cpu.rb: Added --idle-metrics flag for indicating counters which should be considered idle + +### Removed +- Remove Ruby 1.9.3 support; add Ruby 2.3.0 support in test matrix + +## [0.0.4] - 2015-09-29 +### Changed +- Fix getopts syntax in check-cpu.sh +- Improvements to system/metrics-user-pct-usage.rb (option to use uid instead of username) + +## [0.0.3] - 2015-07-14 +### Changed +- updated sensu-plugin gem to 1.2.0 + +## [0.0.2] - 2015-06-02 +### Fixed +- added binstubs + +### Changed +- removed cruft from /lib + +## 0.0.1 - 2015-05-21 +### Added +- initial release + + +[Unreleased]: https://github.com/sensu-plugins/sensu-plugins-cpu-checks/compare/1.0.0...HEAD +[1.0.0]: https://github.com/sensu-plugins/sensu-plugins-cpu-checks/compare/0.0.4...1.0.0 +[0.0.4]: https://github.com/sensu-plugins/sensu-plugins-cpu-checks/compare/0.0.3...0.0.4 +[0.0.3]: https://github.com/sensu-plugins/sensu-plugins-cpu-checks/compare/0.0.2...0.0.3 +[0.0.2]: https://github.com/sensu-plugins/sensu-plugins-cpu-checks/compare/0.0.1...0.0.2 diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/LICENSE b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/LICENSE new file mode 100644 index 0000000..f661cbd --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/LICENSE @@ -0,0 +1,22 @@ +Copyright (c) 2015 Sensu-Plugins + +MIT License + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/README.md b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/README.md new file mode 100644 index 0000000..93bb848 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/README.md @@ -0,0 +1,25 @@ +## Sensu-Plugins-cpu-checks + +[ ![Build Status](https://travis-ci.org/sensu-plugins/sensu-plugins-cpu-checks.svg?branch=master)](https://travis-ci.org/sensu-plugins/sensu-plugins-cpu-checks) +[![Gem Version](https://badge.fury.io/rb/sensu-plugins-cpu-checks.svg)](http://badge.fury.io/rb/sensu-plugins-cpu-checks) +[![Code Climate](https://codeclimate.com/github/sensu-plugins/sensu-plugins-cpu-checks/badges/gpa.svg)](https://codeclimate.com/github/sensu-plugins/sensu-plugins-cpu-checks) +[![Test Coverage](https://codeclimate.com/github/sensu-plugins/sensu-plugins-cpu-checks/badges/coverage.svg)](https://codeclimate.com/github/sensu-plugins/sensu-plugins-cpu-checks) +[![Dependency Status](https://gemnasium.com/sensu-plugins/sensu-plugins-cpu-checks.svg)](https://gemnasium.com/sensu-plugins/sensu-plugins-cpu-checks) + +## Functionality + +## Files + * bin/check-cpu.rb + * bin/check-cpu.sh + * bin/metrics-cpu-mpstat.rb + * bin/metrics-cpu-pcnt-usage.rb + * bin/metrics-numastat.rb + * bin/metrics-user-pct-usage.rb + +## Usage + +## Installation + +[Installation and Setup](http://sensu-plugins.io/docs/installation_instructions.html) + +## Notes diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/bin/check-cpu.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/bin/check-cpu.rb new file mode 100755 index 0000000..d101ecf --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/bin/check-cpu.rb @@ -0,0 +1,120 @@ +#! /usr/bin/env ruby +# +# check-cpu +# +# DESCRIPTION: +# Check cpu usage +# +# OUTPUT: +# plain text +# +# PLATFORMS: +# Linux +# +# DEPENDENCIES: +# gem: sensu-plugin +# +# USAGE: +# #YELLOW +# +# NOTES: +# +# LICENSE: +# Copyright 2014 Sonian, Inc. and contributors. +# Released under the same terms as Sensu (the MIT license); see LICENSE +# for details. +# + +require 'sensu-plugin/check/cli' + +# +# Check CPU +# +class CheckCPU < Sensu::Plugin::Check::CLI + CPU_METRICS = [:user, :nice, :system, :idle, :iowait, :irq, :softirq, :steal, :guest, :guest_nice].freeze + + option :warn, + short: '-w WARN', + proc: proc(&:to_f), + default: 80 + + option :crit, + short: '-c CRIT', + proc: proc(&:to_f), + default: 100 + + option :sleep, + long: '--sleep SLEEP', + proc: proc(&:to_f), + default: 1 + + option :proc_path, + long: '--proc-path /proc', + proc: proc(&:to_f), + default: '/proc' + + option :idle_metrics, + long: '--idle-metrics METRICS', + description: 'Treat the specified metrics as idle. Defaults to idle,iowait,steal,guest,guest_nice', + proc: proc { |x| x.split(/,/).map { |y| y.strip.to_sym } }, + default: [:idle, :iowait, :steal, :guest, :guest_nice] + + CPU_METRICS.each do |metric| + option metric, + long: "--#{metric}", + description: "Check cpu #{metric} instead of total cpu usage", + boolean: true, + default: false + end + + def acquire_cpu_stats + File.open("#{config[:proc_path]}/stat", 'r').each_line do |line| + info = line.split(/\s+/) + name = info.shift + return info.map(&:to_f) if name =~ /^cpu$/ + end + end + + def run + cpu_stats_before = acquire_cpu_stats + sleep config[:sleep] + cpu_stats_after = acquire_cpu_stats + + # Some kernels don't have 'guest' and 'guest_nice' values + metrics = CPU_METRICS.slice(0, cpu_stats_after.length) + + cpu_total_diff = 0.to_f + cpu_stats_diff = [] + metrics.each_index do |i| + cpu_stats_diff[i] = cpu_stats_after[i] - cpu_stats_before[i] + cpu_total_diff += cpu_stats_diff[i] + end + + cpu_stats = [] + metrics.each_index do |i| + cpu_stats[i] = 100 * (cpu_stats_diff[i] / cpu_total_diff) + end + + idle_diff = metrics.each_with_index.map { |metric, i| config[:idle_metrics].include?(metric) ? cpu_stats_diff[i] : 0.0 }.reduce(0.0, :+) + + cpu_usage = 100 * (cpu_total_diff - idle_diff) / cpu_total_diff + checked_usage = cpu_usage + + self.class.check_name 'CheckCPU TOTAL' + metrics.each do |metric| + if config[metric] + self.class.check_name "CheckCPU #{metric.to_s.upcase}" + checked_usage = cpu_stats[metrics.find_index(metric)] + end + end + + msg = "total=#{(cpu_usage * 100).round / 100.0}" + cpu_stats.each_index { |i| msg += " #{metrics[i]}=#{(cpu_stats[i] * 100).round / 100.0}" } + + message msg + + critical if checked_usage >= config[:crit] + warning if checked_usage >= config[:warn] + ok + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/bin/check-cpu.sh b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/bin/check-cpu.sh new file mode 100755 index 0000000..d625f36 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/bin/check-cpu.sh @@ -0,0 +1,84 @@ +#!/bin/bash +# +# Check CPU usage +# +# === +# +# Examples: +# +# check-cpu.sh -w 85 -c 95 +# +# Date: 2014-09-12 +# Author: Jun Ichikawa +# +# Released under the same terms as Sensu (the MIT license); see LICENSE +# for details. + +# get arguments +while getopts ':w:c:h' OPT; do + case $OPT in + w) WARN=$OPTARG;; + c) CRIT=$OPTARG;; + h) hlp="yes";; + *) unknown="yes";; + esac +done + +PROC_PATH=${PROC_PATH:-'/proc'} + +# usage +HELP=" + usage: $0 [ -w value -c value -p -h ] + + -w --> Warning percentage < value + -c --> Critical percentage < value + -h --> print this help screen +" + +if [ "$hlp" = "yes" ]; then + echo "$HELP" + exit 0 +fi + +cpuusage1=(`cat /proc/stat | head -1`) +if [ ${#cpuusage1} -eq 0 ]; then + echo "CRITICAL - CPU UNKNOWN" + exit 2 +fi +sleep 1 +cpuusage2=(`cat $PROC_PATH/stat | head -1`) +if [ ${#cpuusage2} -eq 0 ]; then + echo "CRITICAL - CPU UNKNOWN" + exit 2 +fi + +WARN=${WARN:=90} +CRIT=${CRIT:=95} + +cpu_diff=(0) +total=0 +usage_diff=0 +for i in `seq 1 9` +do + cpu_diff=("${cpu_diff[@]}" `echo "${cpuusage2[$i]}-${cpuusage1[$i]}" | bc`) + total=`echo "$total+${cpu_diff[$i]}" | bc` + if [ $i -ne "4" ]; then + usage_diff=`echo "$usage_diff+${cpu_diff[$i]}" | bc` + else + idl=$cpu_diff[$i] + fi +done +cpu_usage=`echo "scale=2; 100*$usage_diff/$total" | bc` + +if [ "$(echo "${cpu_usage} > ${CRIT}" | bc)" -eq 1 ]; then + echo "CPU CRITICAL - ${cpu_usage}% is greater than critical point.[${CRIT}]" + exit 2 +fi + +if [ "$(echo "${cpu_usage} > ${WARN}" | bc)" -eq 1 ]; then + echo "CPU WARNING - ${cpu_usage}% is greater than warning point.[${WARN}]" + exit 1 +fi + +echo "CPU OK - Usage:${cpu_usage}" +exit 0 diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/bin/metrics-cpu-mpstat.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/bin/metrics-cpu-mpstat.rb new file mode 100755 index 0000000..b938e69 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/bin/metrics-cpu-mpstat.rb @@ -0,0 +1,87 @@ +#! /usr/bin/env ruby +# encoding: UTF-8 +# +# cpu-mpstat-metrics +# +# DESCRIPTION: +# Uses the linux/kstat rubygem to do the hard work in /proc/stat +# includes individual cpu and overall cpu usage +# +# OUTPUT: +# metric data +# +# PLATFORMS: +# Linux +# +# DEPENDENCIES: +# gem: sensu-plugin +# gem: linux/kstat +# +# USAGE: +# +# NOTES: +# +# LICENSE: +# Copyright 2012 Sonian, Inc +# Released under the same terms as Sensu (the MIT license); see LICENSE +# for details. +# + +require 'sensu-plugin/metric/cli' +require 'socket' +require 'linux/kstat' + +# +# CPU Graphite +# +class CpuGraphite < Sensu::Plugin::Metric::CLI::Graphite + option :scheme, + description: 'Metric naming scheme, text to prepend to metric', + short: '-s SCHEME', + long: '--scheme SCHEME', + default: "#{Socket.gethostname}.cpu" + + def acquire_mpstats + kstat = Linux::Kstat.new + mpstat = {} + i = '' + until kstat[:"cpu#{i}"].nil? + mpstat[:"cpu#{i}"] = kstat[:"cpu#{i}"] + if i == '' + i = 0 + else + i += 1 + end + end + mpstat + end + + def delta_cpu_metrics(baseline_cpus, sample_cpus) + delta_cpus = {} + baseline_cpus.each do |cpu, columns| + delta_cpus[:"#{cpu}"] = {} + columns.each do |task, time| + delta_cpus[:"#{cpu}"][:"#{task}"] = sample_cpus[:"#{cpu}"][:"#{task}"] - time + end + end + delta_cpus + end + + def run + baseline_cpus = acquire_mpstats + # measure for a second then get the deltas in jiffies + sleep(1) + sample_cpus = acquire_mpstats + delta_cpus = delta_cpu_metrics(baseline_cpus, sample_cpus) + cpu_count = sample_cpus.length - 1 + delta_cpus.each_pair do |cpu, columns| + # assumes architecture's jiffie is 1/100th of a second + columns.each_pair do |task, time| + # #YELLOW + time = time / cpu_count if cpu.to_s == 'cpu' # rubocop:disable Style/SelfAssignment + output "#{config[:scheme]}.#{cpu}.#{task}", time + end + end + ok + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/bin/metrics-cpu-pcnt-usage.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/bin/metrics-cpu-pcnt-usage.rb new file mode 100755 index 0000000..a72e2a4 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/bin/metrics-cpu-pcnt-usage.rb @@ -0,0 +1,85 @@ +#! /usr/bin/env ruby +# encoding: UTF-8 +# +# cpu-pct-usage-metrics +# +# DESCRIPTION: +# +# OUTPUT: +# metric data +# +# PLATFORMS: +# Linux +# +# DEPENDENCIES: +# gem: sensu-plugin +# +# USAGE: +# +# NOTES: +# +# LICENSE: +# Copyright 2012 Sonian, Inc +# Released under the same terms as Sensu (the MIT license); see LICENSE +# for details. +# +require 'sensu-plugin/metric/cli' +require 'socket' + +# +# CPU Graphite +# +class CpuGraphite < Sensu::Plugin::Metric::CLI::Graphite + option :scheme, + description: 'Metric naming scheme, text to prepend to metric', + short: '-s SCHEME', + long: '--scheme SCHEME', + default: "#{Socket.gethostname}.cpu" + + option :proc_path, + long: '--proc-path /proc', + proc: proc(&:to_f), + default: '/proc' + + def acquire_proc_stats + cpu_metrics = %w(user nice system idle iowait irq softirq steal guest) + File.open("#{config[:proc_path]}/stat", 'r').each_line do |line| + info = line.split(/\s+/) + next if info.empty? + name = info.shift + + # we are matching TOTAL stats and returning a hash of values + if name =~ /^cpu$/ + # return the CPU metrics sample as a hash + # filter out nil values, as some kernels don't have a 'guest' value + return Hash[cpu_metrics.zip(info.map(&:to_i))].reject { |_key, value| value.nil? } + end + end + end + + def sum_cpu_metrics(metrics) + # #YELLOW + metrics.values.reduce { |sum, metric| sum + metric } # rubocop:disable SingleLineBlockParams + end + + def run + cpu_sample1 = acquire_proc_stats + sleep(1) + cpu_sample2 = acquire_proc_stats + cpu_metrics = cpu_sample2.keys + + # we will sum all jiffy counts read in acquire_proc_stats + cpu_total1 = sum_cpu_metrics(cpu_sample1) + cpu_total2 = sum_cpu_metrics(cpu_sample2) + # total cpu usage in last second in CPU jiffs (1/100 s) + cpu_total_diff = cpu_total2 - cpu_total1 + # per CPU metric diff + cpu_sample_diff = Hash[cpu_sample2.map { |k, v| [k, v - cpu_sample1[k]] }] + + cpu_metrics.each do |metric| + metric_val = sprintf('%.02f', (cpu_sample_diff[metric] / cpu_total_diff.to_f) * 100) + output "#{config[:scheme]}.#{metric}", metric_val + end + ok + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/bin/metrics-cpu.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/bin/metrics-cpu.rb new file mode 100755 index 0000000..ccbeafe --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/bin/metrics-cpu.rb @@ -0,0 +1,71 @@ +#! /usr/bin/env ruby +# encoding: UTF-8 +# +# cpu-metrics +# +# DESCRIPTION: +# +# OUTPUT: +# metric data +# +# PLATFORMS: +# Linux +# +# DEPENDENCIES: +# gem: sensu-plugin +# +# USAGE: +# +# NOTES: +# +# LICENSE: +# Copyright 2012 Sonian, Inc +# Released under the same terms as Sensu (the MIT license); see LICENSE +# for details. +# +require 'sensu-plugin/metric/cli' +require 'socket' + +# +# CPU Graphite +# +class CpuGraphite < Sensu::Plugin::Metric::CLI::Graphite + option :scheme, + description: 'Metric naming scheme, text to prepend to metric', + short: '-s SCHEME', + long: '--scheme SCHEME', + default: "#{Socket.gethostname}.cpu" + + option :proc_path, + long: '--proc-path /proc', + proc: proc(&:to_f), + default: '/proc' + + def run + cpu_metrics = %w(user nice system idle iowait irq softirq steal guest) + other_metrics = %w(ctxt processes procs_running procs_blocked btime intr) + cpu_count = 0 + + File.open("#{config[:proc_path]}/stat", 'r').each_line do |line| + info = line.split(/\s+/) + next if info.empty? + name = info.shift + + if name =~ /cpu([0-9]+|)/ + # #YELLOW + cpu_count = cpu_count + 1 # rubocop:disable Style/SelfAssignment + name = 'total' if name == 'cpu' + info.size.times { |i| output "#{config[:scheme]}.#{name}.#{cpu_metrics[i]}", info[i] } + end + + output "#{config[:scheme]}.#{name}", info.last if other_metrics.include? name + end + if cpu_count > 0 + # writes the number of cpus, the minus 1 is because /proc/stat/ + # first line is a "cpu" which is stats for total cpus + output "#{config[:scheme]}.cpu_count", cpu_count - 1 + end + + ok + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/bin/metrics-numastat.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/bin/metrics-numastat.rb new file mode 100755 index 0000000..ef2c2a7 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/bin/metrics-numastat.rb @@ -0,0 +1,58 @@ +#!/usr/bin/env ruby +# +# metrics-numastat +# +# DESCRIPTION: +# Simple wrapper around `numastat` for getting per-NUMA-node memory stats. +# +# OUTPUT: +# metric data +# +# PLATFORMS: +# Linux +# +# DEPENDENCIES: +# gem: sensu-plugin +# +# USAGE: +# +# NOTES: +# +# LICENSE: +# Copyright 2016 Mitsutoshi Aoe +# Released under the same terms as Sensu (the MIT license); see LICENSE +# for details. +# + +require 'socket' +require 'sensu-plugin/metric/cli' + +class NumastatMetrics < Sensu::Plugin::Metric::CLI::Graphite + option :scheme, + description: 'Metric naming scheme, text to prepend to metric', + short: '-s SCHEME', + long: '--scheme SCHEME', + default: "#{Socket.gethostname}.numastat" + + def run + begin + output = `/usr/bin/numastat` + rescue Errno::ENOENT => err + unknown err + end + + nodes = [] + output.each_line do |line| + nodes = line.split(' ') if nodes.empty? + next unless /^([^\s]+)\s+(.+)$/ =~ line + key = Regexp.last_match[1] + vals = Regexp.last_match[2] + next if key.nil? || vals.nil? + nodes.zip(vals.split(' ')).each do |node, val| + output "#{config[:scheme]}.#{node}.#{key}", val + end + end + + ok + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/bin/metrics-user-pct-usage.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/bin/metrics-user-pct-usage.rb new file mode 100755 index 0000000..6577dfa --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/bin/metrics-user-pct-usage.rb @@ -0,0 +1,79 @@ +#! /usr/bin/env ruby +# +# System User Percentage Metric Plugin +# +# DESCRIPTION: +# Produces Graphite output of sum of %CPU over all processes by user. +# E.g., if user joe is running two processes, each using 10% CPU, and +# jane is running one process using 50% CPU, output will be: +# +# joe 20.0 (timestamp) +# jane 50.0 (timestamp) +# +# OUTPUT: +# Graphite metric data. +# +# PLATFORMS: +# Linux, BSD, OS X +# +# DEPENDENCIES: +# gem: sensu-plugin +# gem: socket +# +# USAGE: +# ./user-pct-usage-metrics.rb --ignore_inactive true +# NOTES: +# +# LICENSE: +# John VanDyk +# Released under the same terms as Sensu (the MIT license); see LICENSE +# for details. +# + +require 'sensu-plugin/metric/cli' +require 'socket' + +# +# User Percent +# +class UserPercent < Sensu::Plugin::Metric::CLI::Graphite + option :scheme, + description: 'Metric naming scheme prepended to .username', + long: '--scheme SCHEME', + default: "#{Socket.gethostname}.user_percent" + + option :ignore_inactive, + description: 'Boolean. If true, ignore users using 0% CPU', + long: '--ignore_inactive', + default: true + + option :uid, + description: 'Boolean. If true, uses uid instead of username', + long: '--uid', + default: false + + def run + timestamp = Time.now.to_i + usertype = config[:uid] ? 'uid' : 'user' + pslist = `ps -A -o #{usertype}= -o %cpu= -o %mem=` + + users = {} + pslist.lines.each do |line| + user, cpu, mem = line.split + users[user] = {} unless users[user] + h = { 'cpu' => cpu.to_f, 'mem' => mem.to_f } + users[user] = users[user].merge(h) { |_key, oldval, newval| newval + oldval } + end + + if config[:ignore_inactive] + users.delete_if { |_key, value| value['cpu'] == 0 } + end + + users.each do |user, h| + h.each do |key, value| + output [config[:scheme], user].join(".#{key}."), value, timestamp + end + end + ok + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/lib/sensu-plugins-cpu-checks.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/lib/sensu-plugins-cpu-checks.rb new file mode 100644 index 0000000..e98114f --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/lib/sensu-plugins-cpu-checks.rb @@ -0,0 +1 @@ +require 'sensu-plugins-cpu-checks/version' diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/lib/sensu-plugins-cpu-checks/version.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/lib/sensu-plugins-cpu-checks/version.rb new file mode 100644 index 0000000..d21de22 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/lib/sensu-plugins-cpu-checks/version.rb @@ -0,0 +1,9 @@ +module SensuPluginsCpuChecks + module Version + MAJOR = 1 + MINOR = 0 + PATCH = 0 + + VER_STRING = [MAJOR, MINOR, PATCH].compact.join('.') + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-influxdb-1.1.0/CHANGELOG.md b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-influxdb-1.1.0/CHANGELOG.md new file mode 100644 index 0000000..9fe4847 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-influxdb-1.1.0/CHANGELOG.md @@ -0,0 +1,77 @@ +#Change Log +This project adheres to [Semantic Versioning](http://semver.org/). + +This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachangelog.com/) + +## [Unreleased] + +## [1.1.0] - 2016-12-01 +### Added +- Added tags support for mutator-influxdb-line-protocol.rb +- Added retry support for check-influxdb-query.rb - The InfluxDB gem by default retries indefinitely and will cause the query to hang. A retry of 12 will retry for approx 37 seconds. + +### Changed +- Update to `influxdb` gem 0.3.13 + +## [1.0.0] - 2016-10-06 +### Added +- Ruby 2.3.0 support + +### Removed +- Ruby 1.9.3 support + +### Changed +- Update `influxdb` dep to 0.3.10 +- Update `dentaku` dep to 2.0.9 +- Update `sensu-plugin` dep to ~> 1.3 +- Update `jsonpath` dep to 0.5.8 +- Update to rubocop 0.40 and cleanup + +### [0.0.7] - 2016-04-26 +- Line protocol mutator extension +- added tags support for metrics-influxdb.rb +- Fixed option tag in check-influxdb-query +- added support for storing check status for metrics-influxdb.rb +- metrics-influxdb.rb will now create the database if needed +- metrics-influxdb.rb can now be configured to use a specific settings block + +### [0.0.6] - 2016-04-18 +- supress warning if only checking for an existing return value in check-influxdb-query. + +### [0.0.5] - 2015-10-19 +- added support for https in check-influxdb. +- pass ssl arguments to the influxdb object in check-influxdb-query. +- renamed the config option in check-influxdb from ssl to verify_ssl. +- changed README to update the config option ssl_ca_cert. + +### [0.0.4] - 2015-08-10 +- updated metrics-influxdb.rb to symbolize keys for InfluxDB::Client +- updated influxdb gem to 0.2.2 +- updated metrics-influxdb.rb to support influxdb 0.9.x +- updated check-influxdb.rb and check-influxdb-query.rb to support influxdb 0.9.x +- updated README.md file + +## [0.0.3] - 2015-07-14 +### Changed +- updated sensu-plugin gem to 1.2.0 + +## [0.0.2] - 2015-06-03 +### Fixed +- added binstubs + +### Changed +- removed cruft from /lib + +## 0.0.1 - 2015-04-29 +### Added +- initial release + +[Unreleased]: https://github.com/sensu-plugins/sensu-plugins-influxdb/compare/1.1.0...HEAD +[1.1.0]: https://github.com/sensu-plugins/sensu-plugins-influxdb/compare/1.0.0...1.1.0 +[1.0.0]: https://github.com/sensu-plugins/sensu-plugins-influxdb/compare/0.0.7...1.0.0 +[0.0.7]: https://github.com/sensu-plugins/sensu-plugins-influxdb/compare/0.0.6...0.0.7 +[0.0.6]: https://github.com/sensu-plugins/sensu-plugins-influxdb/compare/0.0.5...0.0.6 +[0.0.5]: https://github.com/sensu-plugins/sensu-plugins-influxdb/compare/0.0.4...0.0.5 +[0.0.4]: https://github.com/sensu-plugins/sensu-plugins-influxdb/compare/0.0.3...0.0.4 +[0.0.3]: https://github.com/sensu-plugins/sensu-plugins-influxdb/compare/0.0.2...0.0.3 +[0.0.2]: https://github.com/sensu-plugins/sensu-plugins-influxdb/compare/0.0.1...0.0.2 diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-influxdb-1.1.0/LICENSE b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-influxdb-1.1.0/LICENSE new file mode 100644 index 0000000..f661cbd --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-influxdb-1.1.0/LICENSE @@ -0,0 +1,22 @@ +Copyright (c) 2015 Sensu-Plugins + +MIT License + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-influxdb-1.1.0/README.md b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-influxdb-1.1.0/README.md new file mode 100644 index 0000000..a9a6306 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-influxdb-1.1.0/README.md @@ -0,0 +1,108 @@ +## Sensu-Plugins-influxdb + +[![Build Status](https://travis-ci.org/sensu-plugins/sensu-plugins-influxdb.svg?branch=master)](https://travis-ci.org/sensu-plugins/sensu-plugins-influxdb) +[![Gem Version](https://badge.fury.io/rb/sensu-plugins-influxdb.svg)](http://badge.fury.io/rb/sensu-plugins-influxdb) +[![Code Climate](https://codeclimate.com/github/sensu-plugins/sensu-plugins-influxdb/badges/gpa.svg)](https://codeclimate.com/github/sensu-plugins/sensu-plugins-influxdb) +[![Test Coverage](https://codeclimate.com/github/sensu-plugins/sensu-plugins-influxdb/badges/coverage.svg)](https://codeclimate.com/github/sensu-plugins/sensu-plugins-influxdb) +[![Dependency Status](https://gemnasium.com/sensu-plugins/sensu-plugins-influxdb.svg)](https://gemnasium.com/sensu-plugins/sensu-plugins-influxdb) + +## Functionality + +## Files + * bin/check-influxdb.rb + * bin/check-influxdb-query.rb + * bin/metrics-influxdb.rb + * bin/mutator-influxdb-line-protocol.rb + +## Usage - metrics-influxdb.rb +Add the following to `/etc/sensu/conf.d/influx.conf` "plugin expects `influxdb` to be a top level node in the json +**metrics-influxdb** +``` +{ + "influxdb": { + "hosts" : ["influxdb.familyguy.com"], + "host" : "influxdb.familyguy.com", + "port" : "8086", + "username" : "root", + "password" : "root", + "database" : "stats", + # OPTIONAL + "time_precision": "s", + "use_ssl" : false, + "verify_ssl" : true, + "ssl_ca_cert" : "path to the ca certificate file", + "auth_method" : "params", + "initial_delay" : 0.01, + "max_delay" : 30, + "open_timeout" : 5, + "read_timeout" : 300, + "retry" : null, + "prefix" : "", + "denormalize" : true, + "status" : true + } +} +``` +Then add the following to your `/ect/sensu/conf.d/handlers.conf`: +``` +{ + "handlers": { + "influx-tcp": { + "type": "pipe", + "command": "/opt/sensu/embedded/bin/metrics-influxdb.rb" + } + } +} +``` + +Setting "status" to true will store the metric using the status as the value and the check name as the series + +## Usage - mutator-influxdb-line-protocol.rb +Add the mutator-influxdb-line-protocol.rb file into /etc/sensu/extensions/ + +Then add the following to your `/ect/sensu/conf.d/handlers.conf`: +``` +{ + "handlers": { + "influxdb_udp": { + "type": "udp", + "socket": { + "host": "localhost", + "port": 8090 + }, + "mutator": "influxdb_line_protocol", + } + } +} +``` + +## Check configuration +To ship additional tags to your metrics via mutator-influxdb-line-protocol.rb (only available in influxdb >= 0.9), just add a tags block inside your check. + +``` +{ + "checks": { + "cpu-metrics": { + "command": "/opt/sensu/embedded/bin/metrics-cpu-pcnt-usage.rb", + "handlers": [ + "influxdb_udp" + ], + "interval": 60, + "subscribers": [ + "base" + ], + "type": "metric", + "standalone": false, + "tags": { + "group": "operations", + } + } + } +} +``` + +## Installation + +[Installation and Setup](http://sensu-plugins.io/docs/installation_instructions.html) + +## Notes diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-influxdb-1.1.0/bin/check-influxdb-query.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-influxdb-1.1.0/bin/check-influxdb-query.rb new file mode 100755 index 0000000..a5525e4 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-influxdb-1.1.0/bin/check-influxdb-query.rb @@ -0,0 +1,197 @@ +#! /usr/bin/env ruby +# +# check-influxdb-query +# +# DESCRIPTION: +# Check InfluxDB queries +# +# OUTPUT: +# plain text +# +# PLATFORMS: +# Linux +# +# DEPENDENCIES: +# gem: sensu-plugin +# gem: jsonpath +# gem: json +# gem: dentaku +# +# USAGE: +# example commands +# +# NOTES: +# See the README here https://github.com/zeroXten/check_influxdb_query +# +# LICENSE: +# Copyright 2014, Fraser Scott +# Released under the same terms as Sensu (the MIT license); see LICENSE +# for details. +# + +require 'influxdb' +require 'sensu-plugin/check/cli' +require 'json' +require 'jsonpath' +require 'dentaku' + +# VERSION = '0.1.0' + +# +# Check Influxdb Query +# +class CheckInfluxdbQuery < Sensu::Plugin::Check::CLI + check_name nil + option :host, + short: '-H HOST', + long: '--host HOST', + default: 'localhost', + description: 'InfluxDB host' + + option :port, + short: '-P PORT', + long: '--port PORT', + default: '8086', + description: 'InfluxDB port' + + option :use_ssl, + description: 'Turn on/off SSL (default: false)', + short: '-s', + long: '--use_ssl', + boolean: true, + default: false + + option :verify_ssl, + description: 'Turn on/off using SSL certificate (default: false)', + short: '-v', + long: '--verify_ssl', + boolean: true, + default: false + + option :ssl_ca_cert, + description: 'Path to the ssl ca certificate to connect to the InfluxDB server', + short: '-C CA_CERT', + long: '--ssl_ca_cert CA_CERT' + + option :database, + short: '-d DATABASE', + long: '--database DATABASE', + default: 'influxdb', + description: 'InfluxDB database name' + + option :retry, + short: '-r RETRY', + long: '--retry RETRY', + description: 'InfluxDB retry count with exponential back-off', + proc: proc(&:to_i), + default: 12 + + option :username, + short: '-u USERNAME', + long: '--username USERNAME', + default: 'root', + description: 'API username' + + option :password, + short: '-p PASSWORD', + long: '--password PASSWORD', + default: 'root', + description: 'API password' + + option :query, + short: '-q QUERY', + long: '--query QUERY', + required: true, + description: 'Query to run. See https://influxdb.com/docs/v0.9/query_language/query_syntax.html' + + option :alias, + short: '-a ALIAS', + long: '--alias ALIAS', + default: nil, + description: 'Alias of query (e.g. if query and output gets too long)' + + option :jsonpath, + short: '-j JSONPATH', + long: '--jsonpath JSONPATH', + default: nil, + description: 'Json path to select value. Takes the first value, or 0 if none. See http://goessner.net/articles/JsonPath/' + + option :noresult, + short: '-n', + long: '--noresult', + boolean: true, + description: 'Go critical for no result from query' + + option :warning, + short: '-w WARNING', + long: '--warning WARNING', + default: nil, + description: "Warning threshold expression. E.g. 'value >= 10'. See https://github.com/rubysolo/dentaku" + + option :critical, + short: '-c CRITICAL', + long: '--critical CRITICAL', + default: nil, + description: "Critical threshold expression. E.g. 'value >= 20'. See https://github.com/rubysolo/dentaku" + + option :help, + short: '-h', + long: '--help', + description: 'Show this message', + on: :tail, + boolean: true, + show_options: true, + exit: 0 + + # option :version, + # short: '-v', + # long: '--version', + # description: 'Show version', + # on: :tail, + # boolean: true, + # proc: proc { puts "Version #{VERSION}" }, + # exit: 0 + + def run + influxdb = InfluxDB::Client.new config[:database], + host: config[:host], + port: config[:port], + use_ssl: config[:use_ssl], + verify_ssl: config[:verify_ssl], + ssl_ca_cert: config[:ssl_ca_cert], + retry: config[:retry], + username: config[:username], + password: config[:password] + + value = influxdb.query config[:query] + + query_name = if config[:alias] + config[:alias] + else + config[:query] + end + + if config[:noresult] && value.empty? + critical "No result for query '#{query_name}'" + elsif config[:noresult] && !config[:jsonpath] && !value.empty? + ok "Value returned for query '#{query_name}'" + end + + if config[:jsonpath] + json_path = JsonPath.new(config[:jsonpath]) + value = json_path.on(value).first || 0 + + calc = Dentaku::Calculator.new + if config[:critical] && calc.evaluate(config[:critical], value: value) + critical "Value '#{value}' matched '#{config[:critical]}' for query '#{query_name}'" + elsif config[:warning] && calc.evaluate(config[:warning], value: value) + warning "Value '#{value}' matched '#{config[:warning]}' for query '#{query_name}'" + else + ok "Value '#{value}' ok for query '#{query_name}'" + end + else + puts 'Debug output. Use -j to check value...' + puts JSON.pretty_generate(value) + end + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-influxdb-1.1.0/bin/check-influxdb.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-influxdb-1.1.0/bin/check-influxdb.rb new file mode 100755 index 0000000..78860be --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-influxdb-1.1.0/bin/check-influxdb.rb @@ -0,0 +1,97 @@ +#! /usr/bin/env ruby +# +# check-influx +# +# DESCRIPTION: +# Check if /ping endopoint is responding +# +# OUTPUT: +# plain text +# +# PLATFORMS: +# Linux +# +# DEPENDENCIES: +# gem: sensu-plugin +# +# USAGE: +# #YELLOW +# +# NOTES: +# +# LICENSE: +# Copyright (C) 2014, Mitsutoshi Aoe +# Released under the same terms as Sensu (the MIT license); see LICENSE +# for details. +# + +require 'sensu-plugin/check/cli' +require 'net/https' + +# +# Check InfluxDB +# +class CheckInfluxDB < Sensu::Plugin::Check::CLI + option :host, + description: 'Host address of the InfluxDB server', + short: '-h HOST', + long: '--host HOST', + default: 'localhost' + + option :port, + description: 'Port number of the InfluxDB server', + short: '-p PORT', + long: '--port PORT', + proc: proc(&:to_i), + default: 8086 + + option :use_ssl, + description: 'Turn on/off SSL (default: false)', + short: '-s', + long: '--use_ssl', + boolean: true, + default: false + + option :verify_ssl, + description: 'Turn on/off using SSL certificate (default: false)', + short: '-v', + long: '--verify_ssl', + boolean: true, + default: false + + option :ssl_ca_cert, + description: 'Path to the ssl ca certificate to connect to the InfluxDB server', + short: '-c CA_CERT', + long: '--ssl_ca_cert CA_CERT' + + option :timeout, + description: 'Seconds to wait for the connection to open or read (default: 1.0s)', + short: '-t SECONDS', + long: '--timeout SECONDS', + proc: proc(&:to_f), + default: 1.0 + + def run + http = Net::HTTP.new(config[:host], config[:port]) + http.open_timeout = config[:timeout] + http.read_timeout = config[:timeout] + http.use_ssl = config[:use_ssl] + if config[:verify_ssl] + http.ca_file = config[:ssl_ca_cert] + http.verify_mode = OpenSSL::SSL::VERIFY_PEER + else + http.verify_mode = OpenSSL::SSL::VERIFY_NONE + end + http.start do + response = http.get('/ping') + status_line = "#{response.code} #{response.message}" + if response.is_a?(Net::HTTPSuccess) + ok status_line + else + critical status_line + end + end + rescue => e + critical e.to_s + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-influxdb-1.1.0/bin/metrics-influxdb.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-influxdb-1.1.0/bin/metrics-influxdb.rb new file mode 100755 index 0000000..f525c3a --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-influxdb-1.1.0/bin/metrics-influxdb.rb @@ -0,0 +1,90 @@ +#! /usr/bin/env ruby +# +# metrics-influx.rb +# +# DESCRIPTION: +# +# OUTPUT: +# plain text +# +# PLATFORMS: +# Linux +# +# DEPENDENCIES: +# gem: sensu-plugin +# gem: influxdb +# +# USAGE: +# #YELLOW +# +# NOTES: +# +# LICENSE: +# Copyright (C) 2015, Sensu Plugins +# Released under the same terms as Sensu (the MIT license); see LICENSE +# for details. +# + +require 'sensu-handler' +gem 'influxdb', '>=0.2.0' +require 'influxdb' + +# +# Sensu To Influxdb +# +class SensuToInfluxDB < Sensu::Handler + option :config, + description: 'Configuration information to use', + short: '-c CONFIG', + long: '--config CONFIG', + default: 'influxdb' + + def filter; end + + def create_point(series, value, time) + point = { series: series, + tags: { host: @event['client']['name'], metric: @event['check']['name'] }, + values: { value: value }, + timestamp: time } + point[:tags].merge!(@event['check']['tags']) unless @event['check']['tags'].nil? + point + end + + def parse_output + data = [] + metric_raw = @event['check']['output'] + metric_raw.split("\n").each do |metric| + m = metric.split + next unless m.count == 3 + key = m[0].split('.', 2)[1] + key.tr!('.', '_') + value = m[1].to_f + time = m[2] + point = create_point(key, value, time) + data.push(point) + end + data + end + + def check_status + data = [] + data.push(create_point(@event['check']['name'], @event['check']['status'], @event['client']['timestamp'])) + end + + def handle + opts = settings[config[:config]].each_with_object({}) do |(k, v), sym| + sym[k.to_sym] = v + end + database = opts[:database] + + influxdb_data = InfluxDB::Client.new database, opts + influxdb_data.create_database(database) # Ensure the database exists + + data = if opts[:status] == false || opts[:status].nil? + parse_output + else + check_status + end + influxdb_data.write_points(data) + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-influxdb-1.1.0/bin/mutator-influxdb-line-protocol.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-influxdb-1.1.0/bin/mutator-influxdb-line-protocol.rb new file mode 100755 index 0000000..d9a5b40 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-influxdb-1.1.0/bin/mutator-influxdb-line-protocol.rb @@ -0,0 +1,62 @@ +#! /usr/bin/env ruby +# +# mutator-influxdb-line-protocol +# +# DESCRIPTION: +# Mutates check results to conform to InfluxDB's line protocol format +# +# Place this file in /etc/sensu/extensions and modify your handlers JSON config +# +# handlers.json +# { +# "influxdb_udp": { +# "type": "udp", +# "mutator": "influxdb_line_protocol", +# "socket": { +# "host": "mgt-monitor-db1", +# "port": 8090 +# } +# } +# } + +require 'sensu/extension' + +module Sensu + module Extension + class InfluxDBLineProtocol < Mutator + def name + 'influxdb_line_protocol' + end + + def description + "returns check output formatted for InfluxDB's line protocol" + end + + def run(event) + tags = event[:check][:tags] + host = event[:client][:name] + metric = event[:check][:name] + output = event[:check][:output] + + data = [] + output.split("\n").each do |result| + m = result.split + next unless m.count == 3 + key = m[0].split('.', 2)[1] + key.tr!('.', '_') + value = m[1].to_f + time = m[2].ljust(19, '0') + linedata = "#{key},host=#{host},metric=#{metric}" + if tags + tags.each do |tagname, tagvalue| + linedata << ",#{tagname}=#{tagvalue}" + end + end + data << "#{linedata} value=#{value} #{time}" + end + + yield data.join("\n"), 0 + end + end + end +end diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-influxdb-1.1.0/lib/sensu-plugins-influxdb.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-influxdb-1.1.0/lib/sensu-plugins-influxdb.rb new file mode 100644 index 0000000..4864c4e --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-influxdb-1.1.0/lib/sensu-plugins-influxdb.rb @@ -0,0 +1 @@ +require 'sensu-plugins-influxdb/version' diff --git a/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-influxdb-1.1.0/lib/sensu-plugins-influxdb/version.rb b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-influxdb-1.1.0/lib/sensu-plugins-influxdb/version.rb new file mode 100644 index 0000000..3797363 --- /dev/null +++ b/deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-influxdb-1.1.0/lib/sensu-plugins-influxdb/version.rb @@ -0,0 +1,9 @@ +module SensuPluginsInfluxdb + module Version + MAJOR = 1 + MINOR = 1 + PATCH = 0 + + VER_STRING = [MAJOR, MINOR, PATCH].compact.join('.') + end +end diff --git a/deployment_scripts/puppet/manifests/haproxy.pp b/deployment_scripts/puppet/manifests/haproxy.pp new file mode 100644 index 0000000..7342e63 --- /dev/null +++ b/deployment_scripts/puppet/manifests/haproxy.pp @@ -0,0 +1,47 @@ +$plugin_name = 'fuel-plugin-sensu' +$fuel_plugin_sensu = hiera($plugin_name, undef) + +if ($fuel_plugin_sensu) { + + notice('fuel-plugin-sensu: haproxy.pp') + $plugin_hash = hiera('fuel-plugin-sensu') + $rabbitmq_vip = $plugin_hash['rabbitmq_vip'] + $redis_vip = $plugin_hash['redis_vip'] + $amqp_port = 5673 + $nodes_ips = hiera('sensu_nodes') + $nodes_names = prefix(range(1, size($nodes_ips)), 'amqp_server_') + + Openstack::Ha::Haproxy_service { + internal_virtual_ip => $internal_virtual_ip, + server_names => $nodes_names, + ipaddresses => $ipaddresses, + public => false, + public_ssl => false, + internal => true, + } + + openstack::ha::haproxy_service { 'rabbitmq': + order => '180', + listen_port => $amqp_port, + ipaddresses => $nodes_ips, + internal_virtual_ip => $rabbitmq_vip, + balancermember_port => $amqp_port, + balancermember_options => 'check inter 5000 rise 2 fall 3', + haproxy_config_options => { + 'option' => ['tcpka'], + 'balance' => 'roundrobin', + 'mode' => 'tcp', + } + } + openstack::ha::haproxy_service { 'redis': + order => '181', + listen_port => 6379, + internal_virtual_ip => $redis_vip, + ipaddresses => $nodes_ips, + balancermember_port => 6379, + balancermember_options => 'check inter 1s', + haproxy_config_options => { + 'mode' => 'tcp', + } + } +} diff --git a/deployment_scripts/puppet/manifests/hiera_override.pp b/deployment_scripts/puppet/manifests/hiera_override.pp new file mode 100644 index 0000000..069e378 --- /dev/null +++ b/deployment_scripts/puppet/manifests/hiera_override.pp @@ -0,0 +1,108 @@ +$plugin_name = 'fuel-plugin-sensu' +$fuel_plugin_sensu = hiera($plugin_name, undef) + +if ($fuel_plugin_sensu) { + notice('MODULAR: fuel-plugin-sensu/hiera_override.pp') + $hiera_plugins_dir = '/etc/hiera/plugins' + $plugin_yaml = "${hiera_plugins_dir}/${plugin_name}.yaml" + $network_metadata = hiera_hash('network_metadata') + $sensu_roles = ['influxdb_grafana', 'primary-influxdb_grafana'] + $sensu_nodes = get_nodes_hash_by_roles($network_metadata, $sensu_roles) + $rabbitmq_vip = $fuel_plugin_sensu['rabbitmq_vip'] + $redis_vip = $fuel_plugin_sensu['redis_vip'] + $sensu_userid = sensu + $sensu_rabbit_pass = 'h4U19fDyq5Jrv7sZdq43' + $virtual_host = sensu + $sensu_address_map = get_node_to_ipaddr_map_by_network_role( + $sensu_nodes, + 'management' + ) + + $sensu_nodes_ips = values($sensu_address_map) + $sensu_nodes_names = keys($sensu_address_map) + + $amqp_hosts = $sensu_nodes_ips + $amqp_port = hiera('amqp_port', '5673') + + case hiera_array('roles', 'none') { + /influxdb_grafana/: { + $rabbit_enabled = true + $corosync_roles = $sensu_roles + $deploy_vrouter = false + # Set to true HA + $corosync_nodes = $sensu_nodes + } + default: { + $rabbit_enabled = false + } + } + + $vip_content = inline_template(' + rabbtimq_management_vip: + ipaddr: <%= @rabbitmq_vip %> + is_user_defined: false + namespace: haproxy + network_role: kibana + node_roles: + - influxdb_grafana + - primary-influxdb_grafana + vendor_specific: null + redis_vip: + ipaddr: <%= @redis_vip %> + is_user_defined: false + namespace: haproxy + network_role: kibana + node_roles: + - influxdb_grafana + - primary-influxdb_grafana + vendor_specific: null + +') + $calculated_content = inline_template('<% +require "yaml" +sensu_vhost = @virtual_host +sensu_userid = @sensu_userid +sensu_rabbit_pass == @sensu_rabbit_pass +vip__rabbitmq = @rabbitmq_vip +redis_vip = @redis_vip +sensu_nodes = @sensu_nodes_ips +amqp_hosts = @amqp_hosts.map {|x| x + ":" + @amqp_port}.join(",") +data = { + "sensu_vhost" => sensu_vhost, + "sensu_userid" => sensu_userid, + "sensu_rabbit_pass" => sensu_rabbit_pass, + "vip__rabbitmq" => vip__rabbitmq, + "redis_vip" => redis_vip, + "sensu_nodes" => sensu_nodes, + "amqp_hosts" => amqp_hosts, + "rabbit" => { + "enabled" => @rabbit_enabled, + }, + "deploy_vrouter" => @deploy_vrouter, +} +data["corosync_nodes"] = @corosync_nodes if @corosync_nodes +data["corosync_roles"] = @corosync_roles if @corosync_roles + +-%> +<%= YAML.dump(data) %> +') + + file { 'hiera_plugins' : + ensure => 'directory', + path => $hiera_plugins_dir, + } + + file { 'plugin_yaml' : + ensure => 'present', + path => $plugin_yaml, + content => $calculated_content, + } + file_line {'append astute content': + ensure => present, + path => '/etc/astute.yaml', + line => $vip_content, + after => ' vips:', + match => '\s+rabbtimq_management_vip:', + replace => false, + } +} diff --git a/deployment_scripts/puppet/manifests/influxdb_config.pp b/deployment_scripts/puppet/manifests/influxdb_config.pp new file mode 100644 index 0000000..bf48c59 --- /dev/null +++ b/deployment_scripts/puppet/manifests/influxdb_config.pp @@ -0,0 +1,8 @@ +$plugin_hash = hiera('fuel-plugin-sensu') + +if $plugin_hash { + + class { 'influxdb_config': } + +} + diff --git a/deployment_scripts/puppet/manifests/packages.pp b/deployment_scripts/puppet/manifests/packages.pp new file mode 100644 index 0000000..5c846f5 --- /dev/null +++ b/deployment_scripts/puppet/manifests/packages.pp @@ -0,0 +1,15 @@ +$plugin_name = 'fuel-plugin-sensu' +$fuel_plugin_sensu = hiera($plugin_name, undef) + + $packages = ['sensu','redis-server','curl','jq'] + + define pkg_install { + package {"$name": + ensure => latest, + } + } + +if ($fuel_plugin_sensu) { +notice('fuel-plugin-sensu: packages.pp') +pkg_install { $packages: } +} diff --git a/deployment_scripts/puppet/manifests/rabbitmq_firewall.pp b/deployment_scripts/puppet/manifests/rabbitmq_firewall.pp new file mode 100644 index 0000000..b175e43 --- /dev/null +++ b/deployment_scripts/puppet/manifests/rabbitmq_firewall.pp @@ -0,0 +1,78 @@ +$plugin_name = 'fuel-plugin-sensu' +$fuel_plugin_sensu = hiera($plugin_name, undef) + +if ($fuel_plugin_sensu) { + + notice('MODULAR: fuel-plugin-sensu/rabbitmq_firewall.pp') + $network_scheme = hiera_hash('network_scheme') + $network_metadata = hiera_hash('network_metadata') + + $corosync_input_port = 5404 + $corosync_output_port = 5405 + $erlang_epmd_port = 4369 + $erlang_inet_dist_port = 41055 + $erlang_rabbitmq_backend_port = 5673 + $erlang_rabbitmq_port = 5672 + $pcsd_port = 2224 + + $corosync_networks = get_routable_networks_for_network_role($network_scheme, 'mgmt/corosync') + $rabbitmq_networks = get_routable_networks_for_network_role($network_scheme, 'mgmt/messaging') + + + openstack::firewall::multi_net {'106 rabbitmq': + port => [$erlang_epmd_port, $erlang_rabbitmq_port, $erlang_rabbitmq_backend_port, $erlang_inet_dist_port], + proto => 'tcp', + action => 'accept', + source_nets => $rabbitmq_networks, + } + + # Workaround for fuel bug with firewall + firewall {'003 remote rabbitmq ': + sport => [ 4369, 5672, 41055, 55672, 61613 ], + source => hiera('master_ip'), + proto => 'tcp', + action => 'accept', + } + + # allow local rabbitmq admin traffic for LP#1383258 + firewall {'005 local rabbitmq admin': + sport => [ 15672 ], + iniface => 'lo', + proto => 'tcp', + action => 'accept', + } + + # reject all non-local rabbitmq admin traffic for LP#1450443 + firewall {'006 reject non-local rabbitmq admin': + sport => [ 15672 ], + proto => 'tcp', + action => 'drop', + } + + # allow connections from haproxy namespace + firewall {'030 allow connections from haproxy namespace': + source => '240.0.0.2', + action => 'accept', + } + + openstack::firewall::multi_net {'113 corosync-input': + port => $corosync_input_port, + proto => 'udp', + action => 'accept', + source_nets => $corosync_networks, + } + + openstack::firewall::multi_net {'114 corosync-output': + port => $corosync_output_port, + proto => 'udp', + action => 'accept', + source_nets => $corosync_networks, + } + + openstack::firewall::multi_net {'115 pcsd-server': + port => $pcsd_port, + proto => 'tcp', + action => 'accept', + source_nets => $corosync_networks, + } +} diff --git a/deployment_scripts/puppet/manifests/rabbitmq_sensu.pp b/deployment_scripts/puppet/manifests/rabbitmq_sensu.pp new file mode 100644 index 0000000..6a64816 --- /dev/null +++ b/deployment_scripts/puppet/manifests/rabbitmq_sensu.pp @@ -0,0 +1,25 @@ +$plugin_name = 'fuel-plugin-sensu' +$fuel_plugin_sensu = hiera($plugin_name, undef) + +if ($fuel_plugin_sensu) { + + notice('MODULAR: fuel-plugin-sensu/rabbitmq_sensu.pp') + $sensu_vhost = hiera('sensu_vhost') + $sensu_userid = hiera('sensu_userid') + $sensu_rabbit_pass = hiera('sensu_rabbit_pass') + + rabbitmq_vhost { $sensu_vhost: + provider => 'rabbitmqctl', + }-> + rabbitmq_user { $sensu_userid: + admin => true, + password => $sensu_rabbit_pass, + provider => 'rabbitmqctl', + }-> + rabbitmq_user_permissions { "${sensu_userid}@${sensu_vhost}": + configure_permission => '.*', + write_permission => '.*', + read_permission => '.*', + provider => 'rabbitmqctl', + } +} diff --git a/deployment_scripts/puppet/manifests/redis_haproxy.pp b/deployment_scripts/puppet/manifests/redis_haproxy.pp new file mode 100644 index 0000000..ed30430 --- /dev/null +++ b/deployment_scripts/puppet/manifests/redis_haproxy.pp @@ -0,0 +1,59 @@ +$plugin_name = 'fuel-plugin-sensu' +$fuel_plugin_sensu = hiera($plugin_name, undef) + +if ($fuel_plugin_sensu) { + + notice('fuel-plugin-sensu: redis_haproxy.pp') + $plugin_hash = hiera('fuel-plugin-sensu') + $redis_vip = $plugin_hash['redis_vip'] + $nodes_ips = hiera('sensu_nodes') + + Openstack::Ha::Haproxy_service { + internal_virtual_ip => $internal_virtual_ip, + server_names => $nodes_names, + ipaddresses => $ipaddresses, + public => false, + public_ssl => false, + internal => true, + } + + $redis_conf = inline_template(' +defaults REDIS +mode tcp +timeout connect 3s +timeout server 6s +timeout client 6s + +# Specifies listening socket for accepting client connections using the default +# REDIS TCP timeout and backend bk_redis TCP health check. +frontend ft_redis +bind <%= @redis_vip%>:6379 name redis +default_backend bk_redis + +# Specifies the backend Redis proxy server TCP health settings +# Ensure it only forward incoming connections to reach a master. +backend bk_redis +option tcp-check +tcp-check connect +tcp-check send PING\r\n +tcp-check expect string +PONG +tcp-check send info\ replication\r\n +tcp-check expect string role:master +tcp-check send QUIT\r\n +tcp-check expect string +OK +mode tcp +<% @nodes_ips.each_with_index.map do |v,i| -%> +server server_<%= i+1 %> <%= v %>:6379 check inter 1s +<% end -%> +') + file{"redis haproxy": + ensure => present, + path => "/etc/haproxy/conf.d/181-redis.cfg", + content => $redis_conf, + notify => Exec['haproxy restart'], + } + exec {"haproxy restart": + command => "crm resource restart clone_p_haproxy", + path => '/usr/sbin/', + } +} diff --git a/deployment_scripts/puppet/manifests/redis_sentinel_config.pp b/deployment_scripts/puppet/manifests/redis_sentinel_config.pp new file mode 100644 index 0000000..a9a5bd7 --- /dev/null +++ b/deployment_scripts/puppet/manifests/redis_sentinel_config.pp @@ -0,0 +1,8 @@ +$plugin_hash = hiera('fuel-plugin-sensu') + +if $plugin_hash { + + class { 'redis_sentinel_config': } + +} + diff --git a/deployment_scripts/puppet/manifests/sensu_config.pp b/deployment_scripts/puppet/manifests/sensu_config.pp new file mode 100644 index 0000000..c48adeb --- /dev/null +++ b/deployment_scripts/puppet/manifests/sensu_config.pp @@ -0,0 +1,8 @@ +$plugin_hash = hiera('fuel-plugin-sensu') + +if $plugin_hash { + + class { 'sensu_config': } + +} + diff --git a/deployment_scripts/puppet/modules/influxdb_config/manifests/init.pp b/deployment_scripts/puppet/modules/influxdb_config/manifests/init.pp new file mode 100644 index 0000000..addaa2c --- /dev/null +++ b/deployment_scripts/puppet/modules/influxdb_config/manifests/init.pp @@ -0,0 +1,20 @@ +class influxdb_config { + notice('MODULAR: fuel-plugin-sensu/influx_config.pp') + $plugin_name = 'fuel-plugin-sensu' + $fuel_plugin_sensu = hiera($plugin_name, undef) + $config = inline_template (' +[[udp]] + enabled = true + bind-address = "<%= @ipaddress_br_mgmt %>:8089" + ') + + file_line {"udp config": + path => "/etc/influxdb/influxdb.conf", + line => $config, + notify => Service['influxdb'], + } + service {"influxdb": + ensure => running, + } + +} diff --git a/deployment_scripts/puppet/modules/redis_sentinel_config/manifests/init.pp b/deployment_scripts/puppet/modules/redis_sentinel_config/manifests/init.pp new file mode 100644 index 0000000..8778368 --- /dev/null +++ b/deployment_scripts/puppet/modules/redis_sentinel_config/manifests/init.pp @@ -0,0 +1,19 @@ +class redis_sentinel_config { + $mgmt= $ipaddress_br_mgmt + $redis_vip = hiera('redis_vip') + + file { '/etc/init.d/redis-sentinel': + content => template('redis_sentinel_config/redis-sentinel.erb'), + mode => '0755', + notify => Service['redis-sentinel'], + } + file { '/etc/redis/sentinel.conf': + content => template('redis_sentinel_config/sentinel.conf.erb'), + notify => Service['redis-sentinel'], + } + + service {"redis-sentinel": + enable => true, + ensure => running, + } +} diff --git a/deployment_scripts/puppet/modules/redis_sentinel_config/templates/redis-sentinel.erb b/deployment_scripts/puppet/modules/redis_sentinel_config/templates/redis-sentinel.erb new file mode 100644 index 0000000..e4c1d54 --- /dev/null +++ b/deployment_scripts/puppet/modules/redis_sentinel_config/templates/redis-sentinel.erb @@ -0,0 +1,77 @@ +#!/bin/bash +### BEGIN INIT INFO +# Provides: redis sentinel +# Required-Start: $all +# Required-Stop: $all +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: Starts redis sentinel +# Description: Starts redis sentinel using start-stop-daemon +### END INIT INFO + +NAME=redis-sentinel +DESC=redis-sentinel +BIN=/usr/bin/redis-server +SENTINEL_PID=/var/run/redis-sentinel.pid +CMD=$1 + +start() { + echo "Starting $NAME ..." + exec 2>&1 $BIN /etc/redis/sentinel.conf --sentinel | logger -t sentinel & + /usr/bin/pgrep -f "/usr/bin/redis-server <%= @mgmt %>:26379" > "${SENTINEL_PID}"; +} + +stop() { + PID=`cat $SENTINEL_PID` + echo "Stopping $NAME ($PID) ..." + kill $PID +} + +restart() { + echo "Restarting $NAME ..." + stop + start +} +status() { + if [ -f "$SENTINEL_PID" ] ; then + pid=$(cat "$SENTINEL_PID") + if ps -p $pid > /dev/null 2> /dev/null ; then + # process by this pid is running. + # It may not be our pid, but that's what you get with just pidfiles. + # TODO(sissel): Check if this process seems to be the same as the one we + # expect. It'd be nice to use flock here, but flock uses fork, not exec, + # so it makes it quite awkward to use in this case. + return 0 + else + return 2 # program is dead but pid file exists + fi + else + return 3 # program is not running + fi +} + + +case "$CMD" in + start) + start + ;; + stop) + stop + ;; + restart) + restart + ;; + status) + status + code=$? + if [ $code -eq 0 ] ; then + echo "$NAME is running" + else + echo "$NAME is not running" + fi + exit $code + ;; + + *) + echo "Usage $0 {start|stop|restart}" +esac diff --git a/deployment_scripts/puppet/modules/redis_sentinel_config/templates/sentinel.conf.erb b/deployment_scripts/puppet/modules/redis_sentinel_config/templates/sentinel.conf.erb new file mode 100644 index 0000000..98c7de0 --- /dev/null +++ b/deployment_scripts/puppet/modules/redis_sentinel_config/templates/sentinel.conf.erb @@ -0,0 +1,6 @@ +port 26379 +bind <%= @mgmt %> +sentinel monitor mymaster <%= @redis_vip %> 6379 2 +sentinel down-after-milliseconds mymaster 30000 +sentinel parallel-syncs mymaster 1 +sentinel failover-timeout mymaster 180000 diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/bin/check-cpu.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/bin/check-cpu.rb new file mode 100755 index 0000000..5c7cf07 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/bin/check-cpu.rb @@ -0,0 +1,22 @@ +#!/opt/sensu/embedded/bin/ruby +# +# This file was generated by RubyGems. +# +# The application 'sensu-plugins-cpu-checks' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require 'rubygems' + +version = ">= 0.a" + +if ARGV.first + str = ARGV.first + str = str.dup.force_encoding("BINARY") if str.respond_to? :force_encoding + if str =~ /\A_(.*)_\z/ and Gem::Version.correct?($1) then + version = $1 + ARGV.shift + end +end + +load Gem.activate_bin_path('sensu-plugins-cpu-checks', 'check-cpu.rb', version) diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/bin/check-influxdb-query.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/bin/check-influxdb-query.rb new file mode 100755 index 0000000..dd971cb --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/bin/check-influxdb-query.rb @@ -0,0 +1,22 @@ +#!/opt/sensu/embedded/bin/ruby +# +# This file was generated by RubyGems. +# +# The application 'sensu-plugins-influxdb' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require 'rubygems' + +version = ">= 0.a" + +if ARGV.first + str = ARGV.first + str = str.dup.force_encoding("BINARY") if str.respond_to? :force_encoding + if str =~ /\A_(.*)_\z/ and Gem::Version.correct?($1) then + version = $1 + ARGV.shift + end +end + +load Gem.activate_bin_path('sensu-plugins-influxdb', 'check-influxdb-query.rb', version) diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/bin/check-influxdb.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/bin/check-influxdb.rb new file mode 100755 index 0000000..9da41d2 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/bin/check-influxdb.rb @@ -0,0 +1,22 @@ +#!/opt/sensu/embedded/bin/ruby +# +# This file was generated by RubyGems. +# +# The application 'sensu-plugins-influxdb' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require 'rubygems' + +version = ">= 0.a" + +if ARGV.first + str = ARGV.first + str = str.dup.force_encoding("BINARY") if str.respond_to? :force_encoding + if str =~ /\A_(.*)_\z/ and Gem::Version.correct?($1) then + version = $1 + ARGV.shift + end +end + +load Gem.activate_bin_path('sensu-plugins-influxdb', 'check-influxdb.rb', version) diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/bin/jsonpath b/deployment_scripts/puppet/modules/sensu_config/files/embedded/bin/jsonpath new file mode 100755 index 0000000..c81fc85 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/bin/jsonpath @@ -0,0 +1,22 @@ +#!/opt/sensu/embedded/bin/ruby +# +# This file was generated by RubyGems. +# +# The application 'jsonpath' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require 'rubygems' + +version = ">= 0.a" + +if ARGV.first + str = ARGV.first + str = str.dup.force_encoding("BINARY") if str.respond_to? :force_encoding + if str =~ /\A_(.*)_\z/ and Gem::Version.correct?($1) then + version = $1 + ARGV.shift + end +end + +load Gem.activate_bin_path('jsonpath', 'jsonpath', version) diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/bin/metrics-cpu-mpstat.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/bin/metrics-cpu-mpstat.rb new file mode 100755 index 0000000..d62ddee --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/bin/metrics-cpu-mpstat.rb @@ -0,0 +1,22 @@ +#!/opt/sensu/embedded/bin/ruby +# +# This file was generated by RubyGems. +# +# The application 'sensu-plugins-cpu-checks' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require 'rubygems' + +version = ">= 0.a" + +if ARGV.first + str = ARGV.first + str = str.dup.force_encoding("BINARY") if str.respond_to? :force_encoding + if str =~ /\A_(.*)_\z/ and Gem::Version.correct?($1) then + version = $1 + ARGV.shift + end +end + +load Gem.activate_bin_path('sensu-plugins-cpu-checks', 'metrics-cpu-mpstat.rb', version) diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/bin/metrics-cpu-pcnt-usage.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/bin/metrics-cpu-pcnt-usage.rb new file mode 100755 index 0000000..86e8c9e --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/bin/metrics-cpu-pcnt-usage.rb @@ -0,0 +1,22 @@ +#!/opt/sensu/embedded/bin/ruby +# +# This file was generated by RubyGems. +# +# The application 'sensu-plugins-cpu-checks' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require 'rubygems' + +version = ">= 0.a" + +if ARGV.first + str = ARGV.first + str = str.dup.force_encoding("BINARY") if str.respond_to? :force_encoding + if str =~ /\A_(.*)_\z/ and Gem::Version.correct?($1) then + version = $1 + ARGV.shift + end +end + +load Gem.activate_bin_path('sensu-plugins-cpu-checks', 'metrics-cpu-pcnt-usage.rb', version) diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/bin/metrics-cpu.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/bin/metrics-cpu.rb new file mode 100755 index 0000000..beb9f4e --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/bin/metrics-cpu.rb @@ -0,0 +1,22 @@ +#!/opt/sensu/embedded/bin/ruby +# +# This file was generated by RubyGems. +# +# The application 'sensu-plugins-cpu-checks' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require 'rubygems' + +version = ">= 0.a" + +if ARGV.first + str = ARGV.first + str = str.dup.force_encoding("BINARY") if str.respond_to? :force_encoding + if str =~ /\A_(.*)_\z/ and Gem::Version.correct?($1) then + version = $1 + ARGV.shift + end +end + +load Gem.activate_bin_path('sensu-plugins-cpu-checks', 'metrics-cpu.rb', version) diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/bin/metrics-influxdb.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/bin/metrics-influxdb.rb new file mode 100755 index 0000000..51c0a75 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/bin/metrics-influxdb.rb @@ -0,0 +1,22 @@ +#!/opt/sensu/embedded/bin/ruby +# +# This file was generated by RubyGems. +# +# The application 'sensu-plugins-influxdb' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require 'rubygems' + +version = ">= 0.a" + +if ARGV.first + str = ARGV.first + str = str.dup.force_encoding("BINARY") if str.respond_to? :force_encoding + if str =~ /\A_(.*)_\z/ and Gem::Version.correct?($1) then + version = $1 + ARGV.shift + end +end + +load Gem.activate_bin_path('sensu-plugins-influxdb', 'metrics-influxdb.rb', version) diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/bin/metrics-numastat.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/bin/metrics-numastat.rb new file mode 100755 index 0000000..eed5bc5 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/bin/metrics-numastat.rb @@ -0,0 +1,22 @@ +#!/opt/sensu/embedded/bin/ruby +# +# This file was generated by RubyGems. +# +# The application 'sensu-plugins-cpu-checks' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require 'rubygems' + +version = ">= 0.a" + +if ARGV.first + str = ARGV.first + str = str.dup.force_encoding("BINARY") if str.respond_to? :force_encoding + if str =~ /\A_(.*)_\z/ and Gem::Version.correct?($1) then + version = $1 + ARGV.shift + end +end + +load Gem.activate_bin_path('sensu-plugins-cpu-checks', 'metrics-numastat.rb', version) diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/bin/metrics-user-pct-usage.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/bin/metrics-user-pct-usage.rb new file mode 100755 index 0000000..a5fd00d --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/bin/metrics-user-pct-usage.rb @@ -0,0 +1,22 @@ +#!/opt/sensu/embedded/bin/ruby +# +# This file was generated by RubyGems. +# +# The application 'sensu-plugins-cpu-checks' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require 'rubygems' + +version = ">= 0.a" + +if ARGV.first + str = ARGV.first + str = str.dup.force_encoding("BINARY") if str.respond_to? :force_encoding + if str =~ /\A_(.*)_\z/ and Gem::Version.correct?($1) then + version = $1 + ARGV.shift + end +end + +load Gem.activate_bin_path('sensu-plugins-cpu-checks', 'metrics-user-pct-usage.rb', version) diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/bin/mutator-influxdb-line-protocol.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/bin/mutator-influxdb-line-protocol.rb new file mode 100755 index 0000000..d2742db --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/bin/mutator-influxdb-line-protocol.rb @@ -0,0 +1,22 @@ +#!/opt/sensu/embedded/bin/ruby +# +# This file was generated by RubyGems. +# +# The application 'sensu-plugins-influxdb' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require 'rubygems' + +version = ">= 0.a" + +if ARGV.first + str = ARGV.first + str = str.dup.force_encoding("BINARY") if str.respond_to? :force_encoding + if str =~ /\A_(.*)_\z/ and Gem::Version.correct?($1) then + version = $1 + ARGV.shift + end +end + +load Gem.activate_bin_path('sensu-plugins-influxdb', 'mutator-influxdb-line-protocol.rb', version) diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/cause-0.1/LICENCE.MIT b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/cause-0.1/LICENCE.MIT new file mode 100644 index 0000000..381d9cf --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/cause-0.1/LICENCE.MIT @@ -0,0 +1,19 @@ +Copyright (c) 2013 Conrad Irwin + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/cause-0.1/README.md b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/cause-0.1/README.md new file mode 100644 index 0000000..1ddb52e --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/cause-0.1/README.md @@ -0,0 +1,32 @@ +This is a back-port of Ruby 2.1.0's [`Exception#cause`](http://www.ruby-doc.org/core-2.1.0/Exception.html#method-i-cause) to older versions of Ruby. + +Installation +------------ + +Add `gem 'cause'` to your `Gemfile`, then run `bundle install`. If you're not +using bundler, then just `gem install cause`. + +Usage +----- + +Just continue programming as normal. When you rescue from exceptions they'll +have a third property, cause, in addition to backtrace and message. The cause +is the exception object that was being handled when the error was raised. + +While this is not directly useful in normal programming, it's very useful for +debugging. Exception trackers like [Bugsnag](https://bugsnag.com/) can then pick up +the cause of the exception to help you find out what went wrong. + +Limitations +----------- + +At the moment you cannot set the cause yourself. Overriding `raise` is hairy +business and I wrote this gem late at night, but with sufficient care it's +probably doable. + +Meta-fu +------- + +This gem is Copyright under the MIT licence. See LICENCE.MIT for details. + +Contributions and bug-reports are welcome. diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/cause-0.1/cause.gemspec b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/cause-0.1/cause.gemspec new file mode 100644 index 0000000..0a1d6da --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/cause-0.1/cause.gemspec @@ -0,0 +1,17 @@ +Gem::Specification.new do |gem| + gem.name = 'cause' + gem.version = '0.1' + + gem.summary = 'A backport of Exception#cause from Ruby 2.1.0' + gem.description = "Allows you access to the error that was being handled when this exception was raised." + + gem.authors = ['Conrad Irwin'] + gem.email = %w(conrad@bugsnag.com) + gem.homepage = 'http://github.com/ConradIrwin/cause' + + gem.license = 'MIT' + + gem.required_ruby_version = '>= 1.8.7' + + gem.files = `git ls-files`.split("\n") +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/cause-0.1/lib/cause.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/cause-0.1/lib/cause.rb new file mode 100644 index 0000000..0c3394c --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/cause-0.1/lib/cause.rb @@ -0,0 +1,12 @@ +class Exception + unless method_defined?(:cause) + attr_reader :cause + + alias old_initialize initialize + + def initialize(*a) + @cause = $! + old_initialize(*a) + end + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/.gitignore b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/.gitignore new file mode 100644 index 0000000..6a0a948 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/.gitignore @@ -0,0 +1,11 @@ +*.gem +.bundle +.rbenv-version +Gemfile.lock +bin/* +pkg/* +vendor/* + +/.ruby-gemset +/.ruby-version +/.rspec diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/.pryrc b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/.pryrc new file mode 100644 index 0000000..562c9c5 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/.pryrc @@ -0,0 +1,2 @@ +require "bundler" +Bundler.require diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/.travis.yml b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/.travis.yml new file mode 100644 index 0000000..45b8912 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/.travis.yml @@ -0,0 +1,13 @@ +language: ruby +sudo: false +rvm: + - 1.9.3 + - 2.0.0 + - 2.1.0 + - 2.1.1 + - 2.2.0 + - 2.2.1 + - 2.2.2 + - 2.2.3 + - 2.3.0 + - rbx-2 diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/CHANGELOG.md b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/CHANGELOG.md new file mode 100644 index 0000000..61f36cb --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/CHANGELOG.md @@ -0,0 +1,141 @@ +# Change Log + +## [v2.0.9] 2016-09-19 +- namespace tokenization errors +- automatically coerce arguments to string functions as strings +- selectively disable or clear AST cache + +## [v2.0.8] 2016-05-10 +- numeric input validations +- fail with gem-specific error for invalid arithmetic operands +- add `LEFT`, `RIGHT`, `MID`, `LEN`, `FIND`, `SUBSTITUTE`, and `CONCAT` string functions + +## [v2.0.7] 2016-02-25 +- fail with gem-specific error for parsing issues +- support NULL literals and nil variables +- keep reference to variable that caused failure when bulk-solving + +## [v2.0.6] 2016-01-26 +- support array parameters for external functions +- support case statements +- support precision for `ROUNDUP` and `ROUNDDOWN` functions +- prevent errors from corrupting calculator memory + +## [v2.0.5] 2015-09-03 +- fix bug with detecting unbound nodes +- silence warnings +- allow registration of custom token scanners + +## [v2.0.4] 2015-09-03 +- fix BigDecimal conversion bug +- add caching for bulk expression solving dependency order +- allow for custom configuration for token scanners + +## [v2.0.3] 2015-08-25 +- bug fixes +- performance enhancements +- code cleanup + +## [v2.0.1] 2015-08-15 +- add support for boolean literals +- implement basic parse-time type checking + +## [v2.0.0] 2015-08-07 +- shunting-yard parser for performance enhancement and AST generation +- AST caching for performance enhancement +- support comments in formulas +- support all functions from the Ruby Math module + +## [v1.2.6] 2015-05-30 +- support custom error handlers for systems of formulas + +## [v1.2.5] 2015-05-23 +- fix memory leak + +## [v1.2.2] 2014-12-19 +- performance enhancements +- unary minus bug fixes +- preserve provided hash keys for systems of formulas + +## [v1.2.0] 2014-10-21 +- add dependency resolution to automatically solve systems of formulas + +## [v1.1.0] 2014-07-30 +- add strict evaluation mode to raise `UnboundVariableError` if not all variable values are provided +- return division results as `BigDecimal` values + +## [v1.0.0] 2014-03-06 +- cleanup and 1.0 release + +## [v0.2.14] 2014-01-24 +- add modulo operator +- add unary percentage operator +- support registration of custom functions at runtime + +## [v0.2.10] 2012-12-10 +- return integer result for exact division, decimal otherwise + +## [v0.2.9] 2012-10-17 +- add `ROUNDUP` / `ROUNDDOWN` functions + +## [v0.2.8] 2012-09-30 +- make function name matching case-insensitive + +## [v0.2.7] 2012-09-26 +- support passing arbitrary expressions as function arguments + +## [v0.2.6] 2012-09-19 +- add `NOT` function + +## [v0.2.5] 2012-06-20 +- add exponent operator +- add support for digits in variable identifiers + +## [v0.2.4] 2012-02-29 +- add support for `min < x < max` syntax for inequality ranges + +## [v0.2.2] 2012-02-22 +- support `ROUND` to arbitrary decimal place on older Rubies +- ensure case is preserved for string values + +## [v0.2.1] 2012-02-12 +- add `ROUND` function + +## [v0.1.3] 2012-01-31 +- add support for string datatype + +## [v0.1.1] 2012-01-24 +- change from square bracket to parentheses for top-level evaluation +- add `IF` function + +## [v0.1.0] 2012-01-20 +- initial release + +[v2.0.9]: https://github.com/rubysolo/dentaku/compare/v2.0.8...v2.0.9 +[v2.0.8]: https://github.com/rubysolo/dentaku/compare/v2.0.7...v2.0.8 +[v2.0.7]: https://github.com/rubysolo/dentaku/compare/v2.0.6...v2.0.7 +[v2.0.6]: https://github.com/rubysolo/dentaku/compare/v2.0.5...v2.0.6 +[v2.0.5]: https://github.com/rubysolo/dentaku/compare/v2.0.4...v2.0.5 +[v2.0.4]: https://github.com/rubysolo/dentaku/compare/v2.0.3...v2.0.4 +[v2.0.3]: https://github.com/rubysolo/dentaku/compare/v2.0.1...v2.0.3 +[v2.0.1]: https://github.com/rubysolo/dentaku/compare/v2.0.0...v2.0.1 +[v2.0.0]: https://github.com/rubysolo/dentaku/compare/v1.2.6...v2.0.0 +[v1.2.6]: https://github.com/rubysolo/dentaku/compare/v1.2.5...v1.2.6 +[v1.2.5]: https://github.com/rubysolo/dentaku/compare/v1.2.2...v1.2.5 +[v1.2.2]: https://github.com/rubysolo/dentaku/compare/v1.2.0...v1.2.2 +[v1.2.0]: https://github.com/rubysolo/dentaku/compare/v1.1.0...v1.2.0 +[v1.1.0]: https://github.com/rubysolo/dentaku/compare/v1.0.0...v1.1.0 +[v1.0.0]: https://github.com/rubysolo/dentaku/compare/v0.2.14...v1.0.0 +[v0.2.14]: https://github.com/rubysolo/dentaku/compare/v0.2.10...v0.2.14 +[v0.2.10]: https://github.com/rubysolo/dentaku/compare/v0.2.9...v0.2.10 +[v0.2.9]: https://github.com/rubysolo/dentaku/compare/v0.2.8...v0.2.9 +[v0.2.8]: https://github.com/rubysolo/dentaku/compare/v0.2.7...v0.2.8 +[v0.2.7]: https://github.com/rubysolo/dentaku/compare/v0.2.6...v0.2.7 +[v0.2.6]: https://github.com/rubysolo/dentaku/compare/v0.2.5...v0.2.6 +[v0.2.5]: https://github.com/rubysolo/dentaku/compare/v0.2.4...v0.2.5 +[v0.2.4]: https://github.com/rubysolo/dentaku/compare/v0.2.2...v0.2.4 +[v0.2.2]: https://github.com/rubysolo/dentaku/compare/v0.2.1...v0.2.2 +[v0.2.1]: https://github.com/rubysolo/dentaku/compare/v0.1.3...v0.2.1 +[v0.1.3]: https://github.com/rubysolo/dentaku/compare/v0.1.1...v0.1.3 +[v0.1.1]: https://github.com/rubysolo/dentaku/compare/v0.1.0...v0.1.1 +[v0.1.0]: https://github.com/rubysolo/dentaku/commit/68724fd9c8fa637baf7b9d5515df0caa31e226bd diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/Gemfile b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/Gemfile new file mode 100644 index 0000000..5a20cac --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/Gemfile @@ -0,0 +1,9 @@ +source "http://rubygems.org" + +# Specify your gem's dependencies in dentaku.gemspec +gemspec + +if RUBY_VERSION.to_f >= 2.0 && RUBY_ENGINE == 'ruby' + gem 'pry-byebug' + gem 'pry-stack_explorer' +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/README.md b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/README.md new file mode 100644 index 0000000..b8c485e --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/README.md @@ -0,0 +1,297 @@ +Dentaku +======= + +[![Join the chat at https://gitter.im/rubysolo/dentaku](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/rubysolo/dentaku?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) +[![Gem Version](https://badge.fury.io/rb/dentaku.png)](http://badge.fury.io/rb/dentaku) +[![Build Status](https://travis-ci.org/rubysolo/dentaku.png?branch=master)](https://travis-ci.org/rubysolo/dentaku) +[![Code Climate](https://codeclimate.com/github/rubysolo/dentaku.png)](https://codeclimate.com/github/rubysolo/dentaku) +[![Hakiri](https://hakiri.io/github/rubysolo/dentaku/master.svg)](https://hakiri.io/github/rubysolo/dentaku) + +DESCRIPTION +----------- + +Dentaku is a parser and evaluator for a mathematical and logical formula +language that allows run-time binding of values to variables referenced in the +formulas. It is intended to safely evaluate untrusted expressions without +opening security holes. + +EXAMPLE +------- + +This is probably simplest to illustrate in code: + +```ruby +calculator = Dentaku::Calculator.new +calculator.evaluate('10 * 2') +#=> 20 +``` + +Okay, not terribly exciting. But what if you want to have a reference to a +variable, and evaluate it at run-time? Here's how that would look: + +```ruby +calculator.evaluate('kiwi + 5', kiwi: 2) +#=> 7 +``` + +You can also store the variable values in the calculator's memory and then +evaluate expressions against those stored values: + +```ruby +calculator.store(peaches: 15) +calculator.evaluate('peaches - 5') +#=> 10 +calculator.evaluate('peaches >= 15') +#=> true +``` + +For maximum CS geekery, `bind` is an alias of `store`. + +Dentaku understands precedence order and using parentheses to group expressions +to ensure proper evaluation: + +```ruby +calculator.evaluate('5 + 3 * 2') +#=> 11 +calculator.evaluate('(5 + 3) * 2') +#=> 16 +``` + +The `evaluate` method will return `nil` if there is an error in the formula. +If this is not the desired behavior, use `evaluate!`, which will raise an +exception. + +```ruby +calculator.evaluate('10 * x') +#=> nil +calculator.evaluate!('10 * x') +Dentaku::UnboundVariableError: Dentaku::UnboundVariableError +``` + +Dentaku has built-in functions (including `if`, `not`, `min`, `max`, and +`round`) and the ability to define custom functions (see below). Functions +generally work like their counterparts in Excel: + +```ruby +calculator.evaluate('if (pears < 10, 10, 20)', pears: 5) +#=> 10 +calculator.evaluate('if (pears < 10, 10, 20)', pears: 15) +#=> 20 +``` + +`round` can be called with or without the number of decimal places: + +```ruby +calculator.evaluate('round(8.2)') +#=> 8 +calculator.evaluate('round(8.2759, 2)') +#=> 8.28 +``` + +`round` follows rounding rules, while `roundup` and `rounddown` are `ceil` and +`floor`, respectively. + +If you're too lazy to be building calculator objects, there's a shortcut just +for you: + +```ruby +Dentaku('plums * 1.5', plums: 2) +#=> 3.0 +``` + +PERFORMANCE +----------- + +The flexibility and safety of Dentaku don't come without a price. Tokenizing a +string, parsing to an AST, and then evaluating that AST are about 2 orders of +magnitude slower than doing the same math in pure Ruby! + +The good news is that most of the time is spent in the tokenization and parsing +phases, so if performance is a concern, you can enable AST caching: + +```ruby +Dentaku.enable_ast_cache! +``` + +After this, Dentaku will cache the AST of each formula that it evaluates, so +subsequent evaluations (even with different values for variables) will be much +faster -- closer to 4x native Ruby speed. As usual, these benchmarks should be +considered rough estimates, and you should measure with representative formulas +from your application. Also, if new formulas are constantly introduced to your +application, AST caching will consume more memory with each new formula. + +BUILT-IN OPERATORS AND FUNCTIONS +--------------------------------- + +Math: `+`, `-`, `*`, `/`, `%` + +Logic: `<`, `>`, `<=`, `>=`, `<>`, `!=`, `=`, `AND`, `OR` + +Functions: `IF`, `NOT`, `MIN`, `MAX`, `ROUND`, `ROUNDDOWN`, `ROUNDUP` + +Selections: `CASE` (syntax see [spec](https://github.com/rubysolo/dentaku/blob/master/spec/calculator_spec.rb#L292)) + +Math: all functions from Ruby's Math module, including `SIN`, `COS`, `TAN`, etc. + +String: `LEFT`, `RIGHT`, `MID`, `LEN`, `FIND`, `SUBSTITUTE`, `CONCAT` + +RESOLVING DEPENDENCIES +---------------------- + +If your formulas rely on one another, they may need to be resolved in a +particular order. For example: + +```ruby +calc = Dentaku::Calculator.new +calc.store(monthly_income: 50) +need_to_compute = { + income_taxes: "annual_income / 5", + annual_income: "monthly_income * 12" +} +``` + +In the example, `annual_income` needs to be computed (and stored) before +`income_taxes`. + +Dentaku provides two methods to help resolve formulas in order: + +#### Calculator.dependencies +Pass a (string) expression to Dependencies and get back a list of variables (as +`:symbols`) that are required for the expression. `Dependencies` also takes +into account variables already (explicitly) stored into the calculator. + +```ruby +calc.dependencies("monthly_income * 12") +#=> [] +# (since monthly_income is in memory) + +calc.dependencies("annual_income / 5") +#=> [:annual_income] +``` + +#### Calculator.solve! / Calculator.solve +Have Dentaku figure out the order in which your formulas need to be evaluated. + +Pass in a hash of `{eventual_variable_name: "expression"}` to `solve!` and +have Dentaku resolve dependencies (using `TSort`) for you. + +Raises `TSort::Cyclic` when a valid expression order cannot be found. + +```ruby +calc = Dentaku::Calculator.new +calc.store(monthly_income: 50) +need_to_compute = { + income_taxes: "annual_income / 5", + annual_income: "monthly_income * 12" +} +calc.solve!(need_to_compute) +#=> {annual_income: 600, income_taxes: 120} + +calc.solve!( + make_money: "have_money", + have_money: "make_money" +} +#=> raises TSort::Cyclic +``` + +`solve!` will also raise an exception if any of the formulas in the set cannot +be evaluated (e.g. raise `ZeroDivisionError`). The non-bang `solve` method will +find as many solutions as possible and return the symbol `:undefined` for the +problem formulas. + +INLINE COMMENTS +--------------------------------- + +If your expressions grow long or complex, you may add inline comments for future +reference. This is particularly useful if you save your expressions in a model. + +```ruby +calculator.evaluate('kiwi + 5 /* This is a comment */', kiwi: 2) +#=> 7 +``` + +Comments can be single or multi-line. The following are also valid. + +``` +/* + * This is a multi-line comment + */ + +/* + This is another type of multi-line comment + */ +``` + +EXTERNAL FUNCTIONS +------------------ + +I don't know everything, so I might not have implemented all the functions you +need. Please implement your favorites and send a pull request! Okay, so maybe +that's not feasible because: + +1. You can't be bothered to share +1. You can't wait for me to respond to a pull request, you need it `NOW()` +1. The formula is the secret sauce for your startup + +Whatever your reasons, Dentaku supports adding functions at runtime. To add a +function, you'll need to specify a name, a return type, and a lambda that +accepts all function arguments and returns the result value. + +Here's an example of adding a function named `POW` that implements +exponentiation. + +```ruby +> c = Dentaku::Calculator.new +> c.add_function(:pow, :numeric, ->(mantissa, exponent) { mantissa ** exponent }) +> c.evaluate('POW(3,2)') +#=> 9 +> c.evaluate('POW(2,3)') +#=> 8 +``` + +Here's an example of adding a variadic function: + +```ruby +> c = Dentaku::Calculator.new +> c.add_function(:max, :numeric, ->(*args) { args.max }) +> c.evaluate 'MAX(8,6,7,5,3,0,9)' +#=> 9 +``` + +(However both of these are already built-in -- the `^` operator and the `MAX` +function) + +Functions can be added individually using Calculator#add_function, or en masse +using Calculator#add_functions. + +THANKS +------ + +Big thanks to [ElkStone Basements](http://www.elkstonebasements.com/) for +allowing me to extract and open source this code. Thanks also to all the +[contributors](https://github.com/rubysolo/dentaku/graphs/contributors)! + + +LICENSE +------- + +(The MIT License) + +Copyright © 2012-2016 Solomon White + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the ‘Software’), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/Rakefile b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/Rakefile new file mode 100644 index 0000000..dba88e6 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/Rakefile @@ -0,0 +1,28 @@ +require 'bundler/gem_tasks' +require 'rspec/core/rake_task' + +desc "Run specs" +task :spec do + RSpec::Core::RakeTask.new(:spec) do |t| + t.rspec_opts = %w{--colour --format progress} + t.pattern = 'spec/**/*_spec.rb' + end +end + +desc "Default: run specs." +task default: :spec + +task :console do + begin + require 'pry' + console = Pry + rescue LoadError + require 'irb' + require 'irb/completion' + console = IRB + end + + require 'dentaku' + ARGV.clear + console.start +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/dentaku.gemspec b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/dentaku.gemspec new file mode 100644 index 0000000..3cb51fc --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/dentaku.gemspec @@ -0,0 +1,27 @@ +# -*- encoding: utf-8 -*- +$:.push File.expand_path("../lib", __FILE__) +require "dentaku/version" + +Gem::Specification.new do |s| + s.name = "dentaku" + s.version = Dentaku::VERSION + s.authors = ["Solomon White"] + s.email = ["rubysolo@gmail.com"] + s.homepage = "http://github.com/rubysolo/dentaku" + s.licenses = %w(MIT) + s.summary = %q{A formula language parser and evaluator} + s.description = <<-DESC + Dentaku is a parser and evaluator for mathematical formulas + DESC + + s.rubyforge_project = "dentaku" + + s.add_development_dependency('rake') + s.add_development_dependency('rspec') + s.add_development_dependency('pry') + + s.files = `git ls-files`.split("\n") + s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") + s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } + s.require_paths = ["lib"] +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku.rb new file mode 100644 index 0000000..1b081b8 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku.rb @@ -0,0 +1,43 @@ +require "bigdecimal" +require "dentaku/calculator" +require "dentaku/version" + +module Dentaku + @enable_ast_caching = false + @enable_dependency_order_caching = false + + def self.evaluate(expression, data={}) + calculator.evaluate(expression, data) + end + + def self.enable_caching! + enable_ast_cache! + enable_dependency_order_cache! + end + + def self.enable_ast_cache! + @enable_ast_caching = true + end + + def self.cache_ast? + @enable_ast_caching + end + + def self.enable_dependency_order_cache! + @enable_dependency_order_caching = true + end + + def self.cache_dependency_order? + @enable_dependency_order_caching + end + + private + + def self.calculator + @calculator ||= Dentaku::Calculator.new + end +end + +def Dentaku(expression, data={}) + Dentaku.evaluate(expression, data) +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast.rb new file mode 100644 index 0000000..95cd512 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast.rb @@ -0,0 +1,21 @@ +require_relative './ast/node' +require_relative './ast/nil' +require_relative './ast/numeric' +require_relative './ast/logical' +require_relative './ast/string' +require_relative './ast/identifier' +require_relative './ast/arithmetic' +require_relative './ast/negation' +require_relative './ast/comparators' +require_relative './ast/combinators' +require_relative './ast/grouping' +require_relative './ast/case' +require_relative './ast/functions/if' +require_relative './ast/functions/max' +require_relative './ast/functions/min' +require_relative './ast/functions/not' +require_relative './ast/functions/round' +require_relative './ast/functions/roundup' +require_relative './ast/functions/rounddown' +require_relative './ast/functions/ruby_math' +require_relative './ast/functions/string_functions' diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/arithmetic.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/arithmetic.rb new file mode 100644 index 0000000..74ac064 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/arithmetic.rb @@ -0,0 +1,129 @@ +require_relative './operation' +require 'bigdecimal' +require 'bigdecimal/util' + +module Dentaku + module AST + class Arithmetic < Operation + def initialize(*) + super + unless valid_node?(left) && valid_node?(right) + fail ParseError, "#{ self.class } requires numeric operands" + end + end + + def type + :numeric + end + + def value(context={}) + l = cast(left.value(context)) + r = cast(right.value(context)) + l.public_send(operator, r) + end + + private + + def cast(value, prefer_integer=true) + validate_numeric(value) + v = BigDecimal.new(value, Float::DIG+1) + v = v.to_i if prefer_integer && v.frac.zero? + v + end + + def valid_node?(node) + node && (node.dependencies.any? || node.type == :numeric) + end + + def validate_numeric(value) + Float(value) + rescue ::ArgumentError, ::TypeError + fail Dentaku::ArgumentError, "#{ self.class } requires numeric operands" + end + end + + class Addition < Arithmetic + def operator + :+ + end + + def self.precedence + 10 + end + end + + class Subtraction < Arithmetic + def operator + :- + end + + def self.precedence + 10 + end + end + + class Multiplication < Arithmetic + def operator + :* + end + + def self.precedence + 20 + end + end + + class Division < Arithmetic + def value(context={}) + r = cast(right.value(context), false) + raise Dentaku::ZeroDivisionError if r.zero? + + cast(cast(left.value(context)) / r) + end + + def self.precedence + 20 + end + end + + class Modulo < Arithmetic + def initialize(left, right) + @left = left + @right = right + + unless (valid_node?(left) || left.nil?) && valid_node?(right) + fail ParseError, "#{ self.class } requires numeric operands" + end + end + + def percent? + left.nil? + end + + def value(context={}) + if percent? + cast(right.value(context)) * 0.01 + else + super + end + end + + def operator + :% + end + + def self.precedence + 20 + end + end + + class Exponentiation < Arithmetic + def operator + :** + end + + def self.precedence + 30 + end + end + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/case.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/case.rb new file mode 100644 index 0000000..449fd67 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/case.rb @@ -0,0 +1,52 @@ +require_relative './case/case_conditional' +require_relative './case/case_when' +require_relative './case/case_then' +require_relative './case/case_switch_variable' +require_relative './case/case_else' + +module Dentaku + module AST + class Case < Node + def initialize(*nodes) + @switch = nodes.shift + + unless @switch.is_a?(AST::CaseSwitchVariable) + raise 'Case missing switch variable' + end + + @conditions = nodes + + @else = @conditions.pop if @conditions.last.is_a?(AST::CaseElse) + + @conditions.each do |condition| + unless condition.is_a?(AST::CaseConditional) + raise "#{condition} is not a CaseConditional" + end + end + end + + def value(context={}) + switch_value = @switch.value(context) + @conditions.each do |condition| + if condition.when.value(context) == switch_value + return condition.then.value(context) + end + end + + if @else + return @else.value(context) + else + raise "No block matched the switch value '#{switch_value}'" + end + end + + def dependencies(context={}) + # TODO: should short-circuit + @switch.dependencies(context) + + @conditions.flat_map do |condition| + condition.dependencies(context) + end + end + end + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/case/case_conditional.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/case/case_conditional.rb new file mode 100644 index 0000000..846590f --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/case/case_conditional.rb @@ -0,0 +1,23 @@ +module Dentaku + module AST + class CaseConditional < Node + attr_reader :when, + :then + + def initialize(when_statement, then_statement) + @when = when_statement + unless @when.is_a?(AST::CaseWhen) + raise 'Expected first argument to be a CaseWhen' + end + @then = then_statement + unless @then.is_a?(AST::CaseThen) + raise 'Expected second argument to be a CaseThen' + end + end + + def dependencies(context={}) + @when.dependencies(context) + @then.dependencies(context) + end + end + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/case/case_else.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/case/case_else.rb new file mode 100644 index 0000000..bc069de --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/case/case_else.rb @@ -0,0 +1,21 @@ +module Dentaku + module AST + class CaseElse < Node + def self.arity + 1 + end + + def initialize(node) + @node = node + end + + def value(context={}) + @node.value(context) + end + + def dependencies(context={}) + @node.dependencies(context) + end + end + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/case/case_switch_variable.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/case/case_switch_variable.rb new file mode 100644 index 0000000..bc07b89 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/case/case_switch_variable.rb @@ -0,0 +1,21 @@ +module Dentaku + module AST + class CaseSwitchVariable < Node + def initialize(node) + @node = node + end + + def value(context={}) + @node.value(context) + end + + def dependencies(context={}) + @node.dependencies(context) + end + + def self.arity + 1 + end + end + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/case/case_then.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/case/case_then.rb new file mode 100644 index 0000000..4c2d5d5 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/case/case_then.rb @@ -0,0 +1,21 @@ +module Dentaku + module AST + class CaseThen < Node + def self.arity + 1 + end + + def initialize(node) + @node = node + end + + def value(context={}) + @node.value(context) + end + + def dependencies(context={}) + @node.dependencies(context) + end + end + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/case/case_when.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/case/case_when.rb new file mode 100644 index 0000000..c4079ae --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/case/case_when.rb @@ -0,0 +1,21 @@ +module Dentaku + module AST + class CaseWhen < Operation + def self.arity + 1 + end + + def initialize(node) + @node = node + end + + def value(context={}) + @node.value(context) + end + + def dependencies(context={}) + @node.dependencies(context) + end + end + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/combinators.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/combinators.rb new file mode 100644 index 0000000..a02fd58 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/combinators.rb @@ -0,0 +1,36 @@ +require_relative './operation' + +module Dentaku + module AST + class Combinator < Operation + def initialize(*) + super + unless valid_node?(left) && valid_node?(right) + fail ParseError, "#{ self.class } requires logical operands" + end + end + + def type + :logical + end + + private + + def valid_node?(node) + node.dependencies.any? || node.type == :logical + end + end + + class And < Combinator + def value(context={}) + left.value(context) && right.value(context) + end + end + + class Or < Combinator + def value(context={}) + left.value(context) || right.value(context) + end + end + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/comparators.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/comparators.rb new file mode 100644 index 0000000..c7c9ee0 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/comparators.rb @@ -0,0 +1,51 @@ +require_relative './operation' + +module Dentaku + module AST + class Comparator < Operation + def self.precedence + 5 + end + + def type + :logical + end + end + + class LessThan < Comparator + def value(context={}) + left.value(context) < right.value(context) + end + end + + class LessThanOrEqual < Comparator + def value(context={}) + left.value(context) <= right.value(context) + end + end + + class GreaterThan < Comparator + def value(context={}) + left.value(context) > right.value(context) + end + end + + class GreaterThanOrEqual < Comparator + def value(context={}) + left.value(context) >= right.value(context) + end + end + + class NotEqual < Comparator + def value(context={}) + left.value(context) != right.value(context) + end + end + + class Equal < Comparator + def value(context={}) + left.value(context) == right.value(context) + end + end + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/function.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/function.rb new file mode 100644 index 0000000..2f1b82a --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/function.rb @@ -0,0 +1,73 @@ +require_relative 'node' + +module Dentaku + module AST + class Function < Node + def initialize(*args) + @args = args + end + + def dependencies(context={}) + @args.flat_map { |a| a.dependencies(context) } + end + + def self.get(name) + registry.fetch(function_name(name)) { + fail ParseError, "Undefined function #{ name }" + } + end + + def self.register(name, type, implementation) + function = Class.new(self) do + def self.implementation=(impl) + @implementation = impl + end + + def self.implementation + @implementation + end + + def self.type=(type) + @type = type + end + + def self.type + @type + end + + def value(context={}) + args = @args.map { |a| a.value(context) } + self.class.implementation.call(*args) + end + + def type + self.class.type + end + end + + function_class = name.to_s.capitalize + Dentaku::AST.send(:remove_const, function_class) if Dentaku::AST.const_defined?(function_class) + Dentaku::AST.const_set(function_class, function) + + function.implementation = implementation + function.type = type + + registry[function_name(name)] = function + end + + def self.register_class(name, function_class) + registry[function_name(name)] = function_class + end + + private + + def self.function_name(name) + name.to_s.downcase + end + + def self.registry + @registry ||= {} + end + end + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/if.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/if.rb new file mode 100644 index 0000000..6fb240e --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/if.rb @@ -0,0 +1,30 @@ +require_relative '../function' + +module Dentaku + module AST + class If < Function + attr_reader :predicate, :left, :right + + def initialize(predicate, left, right) + @predicate = predicate + @left = left + @right = right + end + + def value(context={}) + predicate.value(context) ? left.value(context) : right.value(context) + end + + def type + left.type + end + + def dependencies(context={}) + # TODO : short-circuit? + (predicate.dependencies(context) + left.dependencies(context) + right.dependencies(context)).uniq + end + end + end +end + +Dentaku::AST::Function.register_class(:if, Dentaku::AST::If) diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/max.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/max.rb new file mode 100644 index 0000000..5d6db1d --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/max.rb @@ -0,0 +1,5 @@ +require_relative '../function' + +Dentaku::AST::Function.register(:max, :numeric, ->(*args) { + args.max +}) diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/min.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/min.rb new file mode 100644 index 0000000..b3841b3 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/min.rb @@ -0,0 +1,5 @@ +require_relative '../function' + +Dentaku::AST::Function.register(:min, :numeric, ->(*args) { + args.min +}) diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/not.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/not.rb new file mode 100644 index 0000000..35df345 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/not.rb @@ -0,0 +1,5 @@ +require_relative '../function' + +Dentaku::AST::Function.register(:not, :logical, ->(logical) { + ! logical +}) diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/round.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/round.rb new file mode 100644 index 0000000..95c329a --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/round.rb @@ -0,0 +1,5 @@ +require_relative '../function' + +Dentaku::AST::Function.register(:round, :numeric, ->(numeric, places=nil) { + numeric.round(places || 0) +}) diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/rounddown.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/rounddown.rb new file mode 100644 index 0000000..4b2625d --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/rounddown.rb @@ -0,0 +1,7 @@ +require_relative '../function' + +Dentaku::AST::Function.register(:rounddown, :numeric, ->(numeric, precision=0) { + tens = 10.0**precision + result = (numeric * tens).floor / tens + precision <= 0 ? result.to_i : result +}) diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/roundup.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/roundup.rb new file mode 100644 index 0000000..5714682 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/roundup.rb @@ -0,0 +1,7 @@ +require_relative '../function' + +Dentaku::AST::Function.register(:roundup, :numeric, ->(numeric, precision=0) { + tens = 10.0**precision + result = (numeric * tens).ceil / tens + precision <= 0 ? result.to_i : result +}) diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/ruby_math.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/ruby_math.rb new file mode 100644 index 0000000..65f4387 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/ruby_math.rb @@ -0,0 +1,8 @@ +# import all functions from Ruby's Math module +require_relative "../function" + +Math.methods(false).each do |method| + Dentaku::AST::Function.register(method, :numeric, ->(*args) { + Math.send(method, *args) + }) +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/string_functions.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/string_functions.rb new file mode 100644 index 0000000..2133c35 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/string_functions.rb @@ -0,0 +1,111 @@ +require_relative '../function' + +module Dentaku + module AST + module StringFunctions + class Left < Function + def initialize(string, length) + @string = string + @length = length + end + + def value(context={}) + string = @string.value(context).to_s + length = @length.value(context) + string[0, length] + end + end + + class Right < Function + def initialize(string, length) + @string = string + @length = length + end + + def value(context={}) + string = @string.value(context).to_s + length = @length.value(context) + string[length * -1, length] || string + end + end + + class Mid < Function + def initialize(string, offset, length) + @string = string + @offset = offset + @length = length + end + + def value(context={}) + string = @string.value(context).to_s + offset = @offset.value(context) + length = @length.value(context) + string[offset - 1, length].to_s + end + end + + class Len < Function + def initialize(string) + @string = string + end + + def value(context={}) + string = @string.value(context).to_s + string.length + end + end + + class Find < Function + def initialize(needle, haystack) + @needle = needle + @haystack = haystack + end + + def value(context={}) + needle = @needle.value(context) + needle = needle.to_s unless needle.is_a?(Regexp) + haystack = @haystack.value(context).to_s + pos = haystack.index(needle) + pos && pos + 1 + end + end + + class Substitute < Function + def initialize(original, search, replacement) + @original = original + @search = search + @replacement = replacement + end + + def value(context={}) + original = @original.value(context).to_s + search = @search.value(context) + search = search.to_s unless search.is_a?(Regexp) + replacement = @replacement.value(context).to_s + original.sub(search, replacement) + end + end + + class Concat < Function + def initialize(left, right) + @left = left + @right = right + end + + def value(context={}) + left = @left.value(context).to_s + right = @right.value(context).to_s + left + right + end + end + end + end +end + +Dentaku::AST::Function.register_class(:left, Dentaku::AST::StringFunctions::Left) +Dentaku::AST::Function.register_class(:right, Dentaku::AST::StringFunctions::Right) +Dentaku::AST::Function.register_class(:mid, Dentaku::AST::StringFunctions::Mid) +Dentaku::AST::Function.register_class(:len, Dentaku::AST::StringFunctions::Len) +Dentaku::AST::Function.register_class(:find, Dentaku::AST::StringFunctions::Find) +Dentaku::AST::Function.register_class(:substitute, Dentaku::AST::StringFunctions::Substitute) +Dentaku::AST::Function.register_class(:concat, Dentaku::AST::StringFunctions::Concat) diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/grouping.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/grouping.rb new file mode 100644 index 0000000..e319caa --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/grouping.rb @@ -0,0 +1,21 @@ +module Dentaku + module AST + class Grouping + def initialize(node) + @node = node + end + + def value(context={}) + @node.value(context) + end + + def type + @node.type + end + + def dependencies(context={}) + @node.dependencies(context) + end + end + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/identifier.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/identifier.rb new file mode 100644 index 0000000..05a87a9 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/identifier.rb @@ -0,0 +1,36 @@ +require_relative '../exceptions' + +module Dentaku + module AST + class Identifier < Node + attr_reader :identifier + + def initialize(token) + @identifier = token.value.downcase + end + + def value(context={}) + v = context.fetch(identifier) do + raise UnboundVariableError.new([identifier]) + end + + case v + when Node + v.value(context) + else + v + end + end + + def dependencies(context={}) + context.has_key?(identifier) ? dependencies_of(context[identifier]) : [identifier] + end + + private + + def dependencies_of(node) + node.respond_to?(:dependencies) ? node.dependencies : [] + end + end + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/literal.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/literal.rb new file mode 100644 index 0000000..b7d8003 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/literal.rb @@ -0,0 +1,20 @@ +module Dentaku + module AST + class Literal < Node + attr_reader :type + + def initialize(token) + @value = token.value + @type = token.category + end + + def value(*) + @value + end + + def dependencies(*) + [] + end + end + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/logical.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/logical.rb new file mode 100644 index 0000000..287cdf6 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/logical.rb @@ -0,0 +1,8 @@ +require_relative "./literal" + +module Dentaku + module AST + class Logical < Literal + end + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/negation.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/negation.rb new file mode 100644 index 0000000..bb281b2 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/negation.rb @@ -0,0 +1,40 @@ +module Dentaku + module AST + class Negation < Operation + def initialize(node) + @node = node + fail ParseError, "Negation requires numeric operand" unless valid_node?(node) + end + + def value(context={}) + @node.value(context) * -1 + end + + def type + :numeric + end + + def self.arity + 1 + end + + def self.right_associative? + true + end + + def self.precedence + 40 + end + + def dependencies(context={}) + @node.dependencies(context) + end + + private + + def valid_node?(node) + node && (node.dependencies.any? || node.type == :numeric) + end + end + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/nil.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/nil.rb new file mode 100644 index 0000000..15ccc0f --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/nil.rb @@ -0,0 +1,9 @@ +module Dentaku + module AST + class Nil < Node + def value(*) + nil + end + end + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/node.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/node.rb new file mode 100644 index 0000000..a26c201 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/node.rb @@ -0,0 +1,17 @@ +module Dentaku + module AST + class Node + def self.precedence + 0 + end + + def self.arity + nil + end + + def dependencies(context={}) + [] + end + end + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/numeric.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/numeric.rb new file mode 100644 index 0000000..8774cfb --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/numeric.rb @@ -0,0 +1,8 @@ +require_relative "./literal" + +module Dentaku + module AST + class Numeric < Literal + end + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/operation.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/operation.rb new file mode 100644 index 0000000..2f4c2cd --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/operation.rb @@ -0,0 +1,22 @@ +require_relative './node' + +module Dentaku + module AST + class Operation < Node + attr_reader :left, :right + + def initialize(left, right) + @left = left + @right = right + end + + def dependencies(context={}) + (left.dependencies(context) + right.dependencies(context)).uniq + end + + def self.right_associative? + false + end + end + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/string.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/string.rb new file mode 100644 index 0000000..1f833ad --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/string.rb @@ -0,0 +1,8 @@ +require_relative "./literal" + +module Dentaku + module AST + class String < Literal + end + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/bulk_expression_solver.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/bulk_expression_solver.rb new file mode 100644 index 0000000..aa8c7e4 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/bulk_expression_solver.rb @@ -0,0 +1,99 @@ +require 'dentaku/calculator' +require 'dentaku/dependency_resolver' +require 'dentaku/exceptions' +require 'dentaku/parser' +require 'dentaku/tokenizer' + +module Dentaku + class BulkExpressionSolver + def initialize(expression_hash, calculator) + self.expression_hash = expression_hash + self.calculator = calculator + end + + def solve! + solve(&raise_exception_handler) + end + + def solve(&block) + error_handler = block || return_undefined_handler + results = load_results(&error_handler) + + expression_hash.each_with_object({}) do |(k, _), r| + r[k] = results[k.to_s] + end + end + + private + + def self.dependency_cache + @dep_cache ||= {} + end + + attr_accessor :expression_hash, :calculator + + def return_undefined_handler + ->(*) { :undefined } + end + + def raise_exception_handler + ->(ex) { raise ex } + end + + def load_results(&block) + variables_in_resolve_order.each_with_object({}) do |var_name, r| + begin + value_from_memory = calculator.memory[var_name] + + if value_from_memory.nil? && + expressions[var_name].nil? && + !calculator.memory.has_key?(var_name) + next + end + + value = value_from_memory || + evaluate!(expressions[var_name], expressions.merge(r)) + + r[var_name] = value + rescue Dentaku::UnboundVariableError, ZeroDivisionError => ex + ex.recipient_variable = var_name + r[var_name] = block.call(ex) + end + end + end + + def expressions + @expressions ||= Hash[expression_hash.map { |k,v| [k.to_s, v] }] + end + + def expression_dependencies + Hash[expressions.map { |var, expr| [var, calculator.dependencies(expr)] }].tap do |d| + d.values.each do |deps| + unresolved = deps.reject { |ud| d.has_key?(ud) } + unresolved.each { |u| add_dependencies(d, u) } + end + end + end + + def add_dependencies(current_dependencies, variable) + node = calculator.memory[variable] + if node.respond_to?(:dependencies) + current_dependencies[variable] = node.dependencies + node.dependencies.each { |d| add_dependencies(current_dependencies, d) } + end + end + + def variables_in_resolve_order + cache_key = expressions.keys.map(&:to_s).sort.join("|") + @ordered_deps ||= self.class.dependency_cache.fetch(cache_key) { + DependencyResolver.find_resolve_order(expression_dependencies).tap do |d| + self.class.dependency_cache[cache_key] = d if Dentaku.cache_dependency_order? + end + } + end + + def evaluate!(expression, results) + calculator.evaluate!(expression, results) + end + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/calculator.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/calculator.rb new file mode 100644 index 0000000..26f8810 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/calculator.rb @@ -0,0 +1,124 @@ +require 'dentaku/bulk_expression_solver' +require 'dentaku/exceptions' +require 'dentaku/token' +require 'dentaku/dependency_resolver' +require 'dentaku/parser' + +module Dentaku + class Calculator + attr_reader :result, :memory, :tokenizer + + def initialize + clear + @tokenizer = Tokenizer.new + @ast_cache = {} + @disable_ast_cache = false + end + + def add_function(name, type, body) + Dentaku::AST::Function.register(name, type, body) + self + end + + def add_functions(fns) + fns.each { |(name, type, body)| add_function(name, type, body) } + self + end + + def disable_cache + @disable_ast_cache = true + yield(self) if block_given? + ensure + @disable_ast_cache = false + end + + def evaluate(expression, data={}) + evaluate!(expression, data) + rescue UnboundVariableError, ArgumentError + yield expression if block_given? + end + + def evaluate!(expression, data={}) + store(data) do + node = expression + node = ast(node) unless node.is_a?(AST::Node) + node.value(memory) + end + end + + def solve!(expression_hash) + BulkExpressionSolver.new(expression_hash, self).solve! + end + + def solve(expression_hash, &block) + BulkExpressionSolver.new(expression_hash, self).solve(&block) + end + + def dependencies(expression) + ast(expression).dependencies(memory) + end + + def ast(expression) + @ast_cache.fetch(expression) { + Parser.new(tokenizer.tokenize(expression)).parse.tap do |node| + @ast_cache[expression] = node if cache_ast? + end + } + end + + def clear_cache(pattern=:all) + case pattern + when :all + @ast_cache = {} + when String + @ast_cache.delete(pattern) + when Regexp + @ast_cache.delete_if { |k,_| k =~ pattern } + else + fail Dentaku::ArgumentError + end + end + + def store(key_or_hash, value=nil) + restore = Hash[memory] + + if value.nil? + key_or_hash.each do |key, val| + memory[key.to_s.downcase] = val + end + else + memory[key_or_hash.to_s.downcase] = value + end + + if block_given? + begin + result = yield + @memory = restore + return result + rescue => e + @memory = restore + raise e + end + end + + self + end + alias_method :bind, :store + + def store_formula(key, formula) + store(key, ast(formula)) + end + + def clear + @memory = {} + end + + def empty? + memory.empty? + end + + def cache_ast? + Dentaku.cache_ast? && !@disable_ast_cache + end + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/dependency_resolver.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/dependency_resolver.rb new file mode 100644 index 0000000..0d74b3c --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/dependency_resolver.rb @@ -0,0 +1,24 @@ +require 'tsort' + +module Dentaku + class DependencyResolver + include TSort + + def self.find_resolve_order(vars_to_dependencies_hash) + self.new(vars_to_dependencies_hash).tsort + end + + def initialize(vars_to_dependencies_hash) + # ensure variables are strings + @vars_to_deps = Hash[vars_to_dependencies_hash.map { |k, v| [k.to_s, v]}] + end + + def tsort_each_node(&block) + @vars_to_deps.each_key(&block) + end + + def tsort_each_child(node, &block) + @vars_to_deps.fetch(node.to_s, []).each(&block) + end + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/exceptions.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/exceptions.rb new file mode 100644 index 0000000..7deab2c --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/exceptions.rb @@ -0,0 +1,25 @@ +module Dentaku + class UnboundVariableError < StandardError + attr_accessor :recipient_variable + + attr_reader :unbound_variables + + def initialize(unbound_variables) + @unbound_variables = unbound_variables + super("no value provided for variables: #{ unbound_variables.join(', ') }") + end + end + + class ParseError < StandardError + end + + class TokenizerError < StandardError + end + + class ArgumentError < ::ArgumentError + end + + class ZeroDivisionError < ::ZeroDivisionError + attr_accessor :recipient_variable + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/parser.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/parser.rb new file mode 100644 index 0000000..bba4c41 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/parser.rb @@ -0,0 +1,222 @@ +require_relative './ast' + +module Dentaku + class Parser + attr_reader :input, :output, :operations, :arities + + def initialize(tokens, options={}) + @input = tokens.dup + @output = [] + @operations = options.fetch(:operations, []) + @arities = options.fetch(:arities, []) + end + + def get_args(count) + Array.new(count) { output.pop }.reverse + end + + def consume(count=2) + operator = operations.pop + output.push operator.new(*get_args(operator.arity || count)) + end + + def parse + return AST::Nil.new if input.empty? + + while token = input.shift + case token.category + when :numeric + output.push AST::Numeric.new(token) + + when :logical + output.push AST::Logical.new(token) + + when :string + output.push AST::String.new(token) + + when :identifier + output.push AST::Identifier.new(token) + + when :operator, :comparator, :combinator + op_class = operation(token) + + if op_class.right_associative? + while operations.last && operations.last < AST::Operation && op_class.precedence < operations.last.precedence + consume + end + + operations.push op_class + else + while operations.last && operations.last < AST::Operation && op_class.precedence <= operations.last.precedence + consume + end + + operations.push op_class + end + + when :null + output.push AST::Nil.new + + when :function + arities.push 0 + operations.push function(token) + + when :case + case token.value + when :open + # special handling for case nesting: strip out inner case + # statements and parse their AST segments recursively + if operations.include?(AST::Case) + last_case_close_index = nil + first_nested_case_close_index = nil + input.each_with_index do |token, index| + first_nested_case_close_index = last_case_close_index + if token.category == :case && token.value == :close + last_case_close_index = index + end + end + inner_case_inputs = input.slice!(0..first_nested_case_close_index) + subparser = Parser.new( + inner_case_inputs, + operations: [AST::Case], + arities: [0] + ) + subparser.parse + output.concat(subparser.output) + else + operations.push AST::Case + arities.push(0) + end + when :close + if operations[1] == AST::CaseThen + while operations.last != AST::Case + consume + end + + operations.push(AST::CaseConditional) + consume(2) + arities[-1] += 1 + elsif operations[1] == AST::CaseElse + while operations.last != AST::Case + consume + end + + arities[-1] += 1 + end + + unless operations.count == 1 && operations.last == AST::Case + fail ParseError, "Unprocessed token #{ token.value }" + end + consume(arities.pop.succ) + when :when + if operations[1] == AST::CaseThen + while ![AST::CaseWhen, AST::Case].include?(operations.last) + consume + end + operations.push(AST::CaseConditional) + consume(2) + arities[-1] += 1 + elsif operations.last == AST::Case + operations.push(AST::CaseSwitchVariable) + consume + end + + operations.push(AST::CaseWhen) + when :then + if operations[1] == AST::CaseWhen + while ![AST::CaseThen, AST::Case].include?(operations.last) + consume + end + end + operations.push(AST::CaseThen) + when :else + if operations[1] == AST::CaseThen + while operations.last != AST::Case + consume + end + + operations.push(AST::CaseConditional) + consume(2) + arities[-1] += 1 + end + + operations.push(AST::CaseElse) + else + fail ParseError, "Unknown case token #{ token.value }" + end + + when :grouping + case token.value + when :open + if input.first && input.first.value == :close + input.shift + consume(0) + else + operations.push AST::Grouping + end + + when :close + while operations.any? && operations.last != AST::Grouping + consume + end + + lparen = operations.pop + fail ParseError, "Unbalanced parenthesis" unless lparen == AST::Grouping + + if operations.last && operations.last < AST::Function + consume(arities.pop.succ) + end + + when :comma + arities[-1] += 1 + while operations.any? && operations.last != AST::Grouping + consume + end + + else + fail ParseError, "Unknown grouping token #{ token.value }" + end + + else + fail ParseError, "Not implemented for tokens of category #{ token.category }" + end + end + + while operations.any? + consume + end + + unless output.count == 1 + fail ParseError, "Invalid statement" + end + + output.first + end + + def operation(token) + { + add: AST::Addition, + subtract: AST::Subtraction, + multiply: AST::Multiplication, + divide: AST::Division, + pow: AST::Exponentiation, + negate: AST::Negation, + mod: AST::Modulo, + + lt: AST::LessThan, + gt: AST::GreaterThan, + le: AST::LessThanOrEqual, + ge: AST::GreaterThanOrEqual, + ne: AST::NotEqual, + eq: AST::Equal, + + and: AST::And, + or: AST::Or, + }.fetch(token.value) + end + + def function(token) + Dentaku::AST::Function.get(token.value) + end + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/token.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/token.rb new file mode 100644 index 0000000..093c46d --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/token.rb @@ -0,0 +1,32 @@ +module Dentaku + class Token + attr_reader :category, :raw_value, :value + + def initialize(category, value, raw_value=nil) + @category = category + @value = value + @raw_value = raw_value + end + + def to_s + raw_value || value + end + + def length + raw_value.to_s.length + end + + def grouping? + is?(:grouping) + end + + def is?(c) + category == c + end + + def ==(other) + (category.nil? || other.category.nil? || category == other.category) && + (value.nil? || other.value.nil? || value == other.value) + end + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/token_matcher.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/token_matcher.rb new file mode 100644 index 0000000..d58d52f --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/token_matcher.rb @@ -0,0 +1,137 @@ +require 'dentaku/token' + +module Dentaku + class TokenMatcher + attr_reader :children, :categories, :values + + def initialize(categories=nil, values=nil, children=[]) + # store categories and values as hash to optimize key lookup, h/t @jan-mangs + @categories = [categories].compact.flatten.each_with_object({}) { |c,h| h[c] = 1 } + @values = [values].compact.flatten.each_with_object({}) { |v,h| h[v] = 1 } + @children = children.compact + @invert = false + + @min = 1 + @max = 1 + @range = (@min..@max) + end + + def | (other_matcher) + self.class.new(:nomatch, :nomatch, leaf_matchers + other_matcher.leaf_matchers) + end + + def invert + @invert = ! @invert + self + end + + def ==(token) + leaf_matcher? ? matches_token?(token) : any_child_matches_token?(token) + end + + def match(token_stream, offset=0) + matched_tokens = [] + matched = false + + while self == token_stream[matched_tokens.length + offset] && matched_tokens.length < @max + matched_tokens << token_stream[matched_tokens.length + offset] + end + + if @range.cover?(matched_tokens.length) + matched = true + end + + [matched, matched_tokens] + end + + def caret + @caret = true + self + end + + def caret? + @caret + end + + def star + @min = 0 + @max = Float::INFINITY + @range = (@min..@max) + self + end + + def plus + @max = Float::INFINITY + @range = (@min..@max) + self + end + + def leaf_matcher? + children.empty? + end + + def leaf_matchers + leaf_matcher? ? [self] : children + end + + private + + def any_child_matches_token?(token) + children.any? { |child| child == token } + end + + def matches_token?(token) + return false if token.nil? + (category_match(token.category) && value_match(token.value)) ^ @invert + end + + def category_match(category) + @categories.empty? || @categories.key?(category) + end + + def value_match(value) + @values.empty? || @values.key?(value) + end + + def self.numeric; new(:numeric); end + def self.string; new(:string); end + def self.logical; new(:logical); end + def self.value + new(:numeric) | new(:string) | new(:logical) + end + + def self.addsub; new(:operator, [:add, :subtract]); end + def self.subtract; new(:operator, :subtract); end + def self.anchored_minus; new(:operator, :subtract).caret; end + def self.muldiv; new(:operator, [:multiply, :divide]); end + def self.pow; new(:operator, :pow); end + def self.mod; new(:operator, :mod); end + def self.combinator; new(:combinator); end + + def self.comparator; new(:comparator); end + def self.comp_gt; new(:comparator, [:gt, :ge]); end + def self.comp_lt; new(:comparator, [:lt, :le]); end + + def self.open; new(:grouping, :open); end + def self.close; new(:grouping, :close); end + def self.comma; new(:grouping, :comma); end + def self.non_group; new(:grouping).invert; end + def self.non_group_star; new(:grouping).invert.star; end + def self.non_close_plus; new(:grouping, :close).invert.plus; end + def self.arguments; (value | comma).plus; end + + def self.if; new(:function, :if); end + def self.round; new(:function, :round); end + def self.roundup; new(:function, :roundup); end + def self.rounddown; new(:function, :rounddown); end + def self.not; new(:function, :not); end + + def self.method_missing(name, *args, &block) + new(:function, name) + end + + def self.respond_to_missing?(name, include_priv) + true + end + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/token_matchers.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/token_matchers.rb new file mode 100644 index 0000000..be4db96 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/token_matchers.rb @@ -0,0 +1,29 @@ +module Dentaku + module TokenMatchers + def self.token_matchers(*symbols) + symbols.map { |s| matcher(s) } + end + + def self.function_token_matchers(function_name, *symbols) + token_matchers(:open, *symbols, :close).unshift( + TokenMatcher.send(function_name) + ) + end + + def self.matcher(symbol) + @matchers ||= [ + :numeric, :string, :addsub, :subtract, :muldiv, :pow, :mod, + :comparator, :comp_gt, :comp_lt, :open, :close, :comma, + :non_close_plus, :non_group, :non_group_star, :arguments, + :logical, :combinator, :if, :round, :roundup, :rounddown, :not, + :anchored_minus, :math_neg_pow, :math_neg_mul + ].each_with_object({}) do |name, matchers| + matchers[name] = TokenMatcher.send(name) + end + + @matchers.fetch(symbol) do + raise "Unknown token symbol #{ symbol }" + end + end + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/token_scanner.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/token_scanner.rb new file mode 100644 index 0000000..0c6774f --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/token_scanner.rb @@ -0,0 +1,142 @@ +require 'bigdecimal' +require 'dentaku/token' + +module Dentaku + class TokenScanner + def initialize(category, regexp, converter=nil, condition=nil) + @category = category + @regexp = %r{\A(#{ regexp })}i + @converter = converter + @condition = condition || ->(*) { true } + end + + def scan(string, last_token=nil) + if (m = @regexp.match(string)) && @condition.call(last_token) + value = raw = m.to_s + value = @converter.call(raw) if @converter + + return Array(value).map do |v| + Token === v ? v : Token.new(@category, v, raw) + end + end + + false + end + + class << self + def available_scanners + [ + :null, + :whitespace, + :numeric, + :double_quoted_string, + :single_quoted_string, + :negate, + :operator, + :grouping, + :case_statement, + :comparator, + :combinator, + :boolean, + :function, + :identifier + ] + end + + def register_default_scanners + register_scanners(available_scanners) + end + + def register_scanners(scanner_ids) + @scanners = scanner_ids.each_with_object({}) do |id, scanners| + scanners[id] = self.send(id) + end + end + + def register_scanner(id, scanner) + @scanners[id] = scanner + end + + def scanners=(scanner_ids) + @scanners.select! { |k,v| scanner_ids.include?(k) } + end + + def scanners + @scanners.values + end + + def whitespace + new(:whitespace, '\s+') + end + + def null + new(:null, 'null\b') + end + + def numeric + new(:numeric, '(\d+(\.\d+)?|\.\d+)\b', lambda { |raw| raw =~ /\./ ? BigDecimal.new(raw) : raw.to_i }) + end + + def double_quoted_string + new(:string, '"[^"]*"', lambda { |raw| raw.gsub(/^"|"$/, '') }) + end + + def single_quoted_string + new(:string, "'[^']*'", lambda { |raw| raw.gsub(/^'|'$/, '') }) + end + + def negate + new(:operator, '-', lambda { |raw| :negate }, lambda { |last_token| + last_token.nil? || + last_token.is?(:operator) || + last_token.is?(:comparator) || + last_token.is?(:combinator) || + last_token.value == :open || + last_token.value == :comma + }) + end + + def operator + names = { pow: '^', add: '+', subtract: '-', multiply: '*', divide: '/', mod: '%' }.invert + new(:operator, '\^|\+|-|\*|\/|%', lambda { |raw| names[raw] }) + end + + def grouping + names = { open: '(', close: ')', comma: ',' }.invert + new(:grouping, '\(|\)|,', lambda { |raw| names[raw] }) + end + + def case_statement + names = { open: 'case', close: 'end', then: 'then', when: 'when', else: 'else' }.invert + new(:case, '(case|end|then|when|else)\b', lambda { |raw| names[raw.downcase] }) + end + + def comparator + names = { le: '<=', ge: '>=', ne: '!=', lt: '<', gt: '>', eq: '=' }.invert + alternate = { ne: '<>', eq: '==' }.invert + new(:comparator, '<=|>=|!=|<>|<|>|==|=', lambda { |raw| names[raw] || alternate[raw] }) + end + + def combinator + new(:combinator, '(and|or)\b', lambda { |raw| raw.strip.downcase.to_sym }) + end + + def boolean + new(:logical, '(true|false)\b', lambda { |raw| raw.strip.downcase == 'true' }) + end + + def function + new(:function, '\w+\s*\(', lambda do |raw| + function_name = raw.gsub('(', '') + [Token.new(:function, function_name.strip.downcase.to_sym, function_name), Token.new(:grouping, :open, '(')] + end) + end + + def identifier + new(:identifier, '\w+\b', lambda { |raw| raw.strip.downcase }) + end + end + + register_default_scanners + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/tokenizer.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/tokenizer.rb new file mode 100644 index 0000000..60a17a0 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/tokenizer.rb @@ -0,0 +1,54 @@ +require 'dentaku/token' +require 'dentaku/token_matcher' +require 'dentaku/token_scanner' + +module Dentaku + class Tokenizer + LPAREN = TokenMatcher.new(:grouping, :open) + RPAREN = TokenMatcher.new(:grouping, :close) + + def tokenize(string) + @nesting = 0 + @tokens = [] + input = strip_comments(string.to_s.dup) + + until input.empty? + fail TokenizerError, "parse error at: '#{ input }'" unless TokenScanner.scanners.any? do |scanner| + scanned, input = scan(input, scanner) + scanned + end + end + + fail TokenizerError, "too many opening parentheses" if @nesting > 0 + + @tokens + end + + def last_token + @tokens.last + end + + def scan(string, scanner) + if tokens = scanner.scan(string, last_token) + tokens.each do |token| + fail TokenizerError, "unexpected zero-width match (:#{ token.category }) at '#{ string }'" if token.length == 0 + + @nesting += 1 if LPAREN == token + @nesting -= 1 if RPAREN == token + fail TokenizerError, "too many closing parentheses" if @nesting < 0 + + @tokens << token unless token.is?(:whitespace) + end + + match_length = tokens.map(&:length).reduce(:+) + [true, string[match_length..-1]] + else + [false, string] + end + end + + def strip_comments(input) + input.gsub(/\/\*[^*]*\*+(?:[^*\/][^*]*\*+)*\//, '') + end + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/version.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/version.rb new file mode 100644 index 0000000..e202ccb --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/version.rb @@ -0,0 +1,3 @@ +module Dentaku + VERSION = "2.0.9" +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/ast/addition_spec.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/ast/addition_spec.rb new file mode 100644 index 0000000..90e2b21 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/ast/addition_spec.rb @@ -0,0 +1,29 @@ +require 'spec_helper' +require 'dentaku/ast/arithmetic' + +require 'dentaku/token' + +describe Dentaku::AST::Addition do + let(:five) { Dentaku::AST::Logical.new Dentaku::Token.new(:numeric, 5) } + let(:six) { Dentaku::AST::Logical.new Dentaku::Token.new(:numeric, 6) } + + let(:t) { Dentaku::AST::Numeric.new Dentaku::Token.new(:logical, true) } + + it 'performs addition' do + node = described_class.new(five, six) + expect(node.value).to eq 11 + end + + it 'requires numeric operands' do + expect { + described_class.new(five, t) + }.to raise_error(Dentaku::ParseError, /requires numeric operands/) + + expression = Dentaku::AST::Multiplication.new(five, five) + group = Dentaku::AST::Grouping.new(expression) + + expect { + described_class.new(group, five) + }.not_to raise_error + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/ast/and_spec.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/ast/and_spec.rb new file mode 100644 index 0000000..75e2da0 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/ast/and_spec.rb @@ -0,0 +1,32 @@ +require 'spec_helper' +require 'dentaku/ast/combinators' + +require 'dentaku/token' + +describe Dentaku::AST::And do + let(:t) { Dentaku::AST::Logical.new Dentaku::Token.new(:logical, true) } + let(:f) { Dentaku::AST::Logical.new Dentaku::Token.new(:logical, false) } + + let(:five) { Dentaku::AST::Numeric.new Dentaku::Token.new(:numeric, 5) } + + it 'performs logical AND' do + node = described_class.new(t, f) + expect(node.value).to eq false + end + + it 'requires logical operands' do + expect { + described_class.new(t, five) + }.to raise_error(Dentaku::ParseError, /requires logical operands/) + + expression = Dentaku::AST::LessThanOrEqual.new(five, five) + expect { + described_class.new(t, expression) + }.not_to raise_error + + expression = Dentaku::AST::Or.new(t, f) + expect { + described_class.new(t, expression) + }.not_to raise_error + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/ast/case_spec.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/ast/case_spec.rb new file mode 100644 index 0000000..3f88ec8 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/ast/case_spec.rb @@ -0,0 +1,80 @@ +require 'spec_helper' +require 'dentaku/ast/operation' +require 'dentaku/ast/logical' +require 'dentaku/ast/identifier' +require 'dentaku/ast/arithmetic' +require 'dentaku/ast/case' + +require 'dentaku/token' + +describe Dentaku::AST::Case do + let!(:one) { Dentaku::AST::Logical.new Dentaku::Token.new(:numeric, 1) } + let!(:two) { Dentaku::AST::Logical.new Dentaku::Token.new(:numeric, 2) } + let!(:apple) do + Dentaku::AST::Logical.new Dentaku::Token.new(:string, 'apple') + end + let!(:banana) do + Dentaku::AST::Logical.new Dentaku::Token.new(:string, 'banana') + end + let!(:identifier) do + Dentaku::AST::Identifier.new(Dentaku::Token.new(:identifier, :fruit)) + end + let!(:switch) { Dentaku::AST::CaseSwitchVariable.new(identifier) } + + let!(:when1) { Dentaku::AST::CaseWhen.new(apple) } + let!(:then1) { Dentaku::AST::CaseThen.new(one) } + let!(:conditional1) { Dentaku::AST::CaseConditional.new(when1, then1) } + + let!(:when2) { Dentaku::AST::CaseWhen.new(banana) } + let!(:then2) { Dentaku::AST::CaseThen.new(two) } + let!(:conditional2) { Dentaku::AST::CaseConditional.new(when2, then2) } + + describe '#value' do + it 'raises an exception if there is no switch variable' do + expect { described_class.new(conditional1, conditional2) } + .to raise_error('Case missing switch variable') + end + + it 'raises an exception if a non-conditional is passed' do + expect { described_class.new(switch, conditional1, when2) } + .to raise_error(/is not a CaseConditional/) + end + + it 'tests each conditional against the switch variable' do + node = described_class.new(switch, conditional1, conditional2) + expect(node.value(fruit: 'banana')).to eq(2) + end + + it 'raises an exception if the conditional is not matched' do + node = described_class.new(switch, conditional1, conditional2) + expect { node.value(fruit: 'orange') } + .to raise_error("No block matched the switch value 'orange'") + end + + it 'uses the else value if provided and conditional is not matched' do + three = Dentaku::AST::Logical.new Dentaku::Token.new(:numeric, 3) + else_statement = Dentaku::AST::CaseElse.new(three) + node = described_class.new( + switch, + conditional1, + conditional2, + else_statement) + expect(node.value(fruit: 'orange')).to eq(3) + end + end + + describe '#dependencies' do + let!(:tax) do + Dentaku::AST::Identifier.new(Dentaku::Token.new(:identifier, :tax)) + end + let!(:addition) { Dentaku::AST::Addition.new(two, tax) } + let!(:when2) { Dentaku::AST::CaseWhen.new(banana) } + let!(:then2) { Dentaku::AST::CaseThen.new(addition) } + let!(:conditional2) { Dentaku::AST::CaseConditional.new(when2, then2) } + + it 'gathers dependencies from switch and conditionals' do + node = described_class.new(switch, conditional1, conditional2) + expect(node.dependencies).to eq([:fruit, :tax]) + end + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/ast/division_spec.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/ast/division_spec.rb new file mode 100644 index 0000000..2f532b0 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/ast/division_spec.rb @@ -0,0 +1,29 @@ +require 'spec_helper' +require 'dentaku/ast/arithmetic' + +require 'dentaku/token' + +describe Dentaku::AST::Division do + let(:five) { Dentaku::AST::Logical.new Dentaku::Token.new(:numeric, 5) } + let(:six) { Dentaku::AST::Logical.new Dentaku::Token.new(:numeric, 6) } + + let(:t) { Dentaku::AST::Numeric.new Dentaku::Token.new(:logical, true) } + + it 'performs division' do + node = described_class.new(five, six) + expect(node.value.round(4)).to eq 0.8333 + end + + it 'requires numeric operands' do + expect { + described_class.new(five, t) + }.to raise_error(Dentaku::ParseError, /requires numeric operands/) + + expression = Dentaku::AST::Multiplication.new(five, five) + group = Dentaku::AST::Grouping.new(expression) + + expect { + described_class.new(group, five) + }.not_to raise_error + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/ast/function_spec.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/ast/function_spec.rb new file mode 100644 index 0000000..0f10665 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/ast/function_spec.rb @@ -0,0 +1,21 @@ +require 'spec_helper' +require 'dentaku/ast/function' + +describe Dentaku::AST::Function do + it 'maintains a function registry' do + expect(described_class).to respond_to(:get) + end + + it 'raises an exception when trying to access an undefined function' do + expect { + described_class.get("flarble") + }.to raise_error(Dentaku::ParseError, /undefined function/i) + end + + it 'registers a custom function' do + described_class.register("flarble", :string, -> { "flarble" }) + expect { described_class.get("flarble") }.not_to raise_error + function = described_class.get("flarble").new + expect(function.value).to eq "flarble" + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/ast/node_spec.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/ast/node_spec.rb new file mode 100644 index 0000000..d596628 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/ast/node_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' +require 'dentaku/ast/node' +require 'dentaku/tokenizer' +require 'dentaku/parser' + +describe Dentaku::AST::Node do + it 'returns list of dependencies' do + node = make_node('x + 5') + expect(node.dependencies).to eq ['x'] + + node = make_node('5 < x') + expect(node.dependencies).to eq ['x'] + + node = make_node('5 < 7') + expect(node.dependencies).to eq [] + + node = make_node('(y * 7)') + expect(node.dependencies).to eq ['y'] + + node = make_node('if(x > 5, y, z)') + expect(node.dependencies).to eq ['x', 'y', 'z'] + + node = make_node('if(x > 5, y, z)') + expect(node.dependencies('x' => 7)).to eq ['y', 'z'] + + node = make_node('') + expect(node.dependencies).to eq [] + end + + it 'returns unique list of dependencies' do + node = make_node('x + x') + expect(node.dependencies).to eq ['x'] + end + + private + + def make_node(expression) + Dentaku::Parser.new(Dentaku::Tokenizer.new.tokenize(expression)).parse + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/ast/numeric_spec.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/ast/numeric_spec.rb new file mode 100644 index 0000000..c25e56e --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/ast/numeric_spec.rb @@ -0,0 +1,16 @@ +require 'spec_helper' +require 'dentaku/ast/numeric' + +require 'dentaku/token' + +describe Dentaku::AST::Numeric do + subject { described_class.new(Dentaku::Token.new(:numeric, 5)) } + + it 'has numeric type' do + expect(subject.type).to eq :numeric + end + + it 'has no dependencies' do + expect(subject.dependencies).to be_empty + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/ast/string_functions_spec.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/ast/string_functions_spec.rb new file mode 100644 index 0000000..ec2b25f --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/ast/string_functions_spec.rb @@ -0,0 +1,135 @@ +require 'spec_helper' +require 'dentaku/ast/functions/string_functions' + +describe Dentaku::AST::StringFunctions::Left do + let(:string) { identifier('string') } + let(:length) { identifier('length') } + + subject { described_class.new(string, length) } + + it 'returns the left N characters of the string' do + expect(subject.value('string' => 'ABCDEFG', 'length' => 4)).to eq 'ABCD' + end + + it 'works correctly with literals' do + left = literal('ABCD') + len = literal(2) + fn = described_class.new(left, len) + expect(fn.value).to eq 'AB' + end + + it 'handles an empty string correctly' do + expect(subject.value('string' => '', 'length' => 4)).to eq '' + end + + it 'handles size greater than input string length correctly' do + expect(subject.value('string' => 'abcdefg', 'length' => 40)).to eq 'abcdefg' + end +end + +describe Dentaku::AST::StringFunctions::Right do + it 'returns the right N characters of the string' do + subject = described_class.new(literal('ABCDEFG'), literal(4)) + expect(subject.value).to eq 'DEFG' + end + + it 'handles an empty string correctly' do + subject = described_class.new(literal(''), literal(4)) + expect(subject.value).to eq '' + end + + it 'handles size greater than input string length correctly' do + subject = described_class.new(literal('abcdefg'), literal(40)) + expect(subject.value).to eq 'abcdefg' + end +end + +describe Dentaku::AST::StringFunctions::Mid do + it 'returns a substring from the middle of the string' do + subject = described_class.new(literal('ABCDEFG'), literal(4), literal(2)) + expect(subject.value).to eq 'DE' + end + + it 'handles an empty string correctly' do + subject = described_class.new(literal(''), literal(4), literal(2)) + expect(subject.value).to eq '' + end + + it 'handles offset greater than input string length correctly' do + subject = described_class.new(literal('abcdefg'), literal(40), literal(4)) + expect(subject.value).to eq '' + end + + it 'handles size greater than input string length correctly' do + subject = described_class.new(literal('abcdefg'), literal(4), literal(40)) + expect(subject.value).to eq 'defg' + end +end + +describe Dentaku::AST::StringFunctions::Len do + it 'returns the length of a string' do + subject = described_class.new(literal('ABCDEFG')) + expect(subject.value).to eq 7 + end + + it 'handles an empty string correctly' do + subject = described_class.new(literal('')) + expect(subject.value).to eq 0 + end +end + +describe Dentaku::AST::StringFunctions::Find do + it 'returns the position of a substring within a string' do + subject = described_class.new(literal('DE'), literal('ABCDEFG')) + expect(subject.value).to eq 4 + end + + it 'handles an empty substring correctly' do + subject = described_class.new(literal(''), literal('ABCDEFG')) + expect(subject.value).to eq 1 + end + + it 'handles an empty string correctly' do + subject = described_class.new(literal('DE'), literal('')) + expect(subject.value).to be_nil + end +end + +describe Dentaku::AST::StringFunctions::Substitute do + it 'replaces a substring within a string' do + subject = described_class.new(literal('ABCDEFG'), literal('DE'), literal('xy')) + expect(subject.value).to eq 'ABCxyFG' + end + + it 'handles an empty search string correctly' do + subject = described_class.new(literal('ABCDEFG'), literal(''), literal('xy')) + expect(subject.value).to eq 'xyABCDEFG' + end + + it 'handles an empty replacement string correctly' do + subject = described_class.new(literal('ABCDEFG'), literal('DE'), literal('')) + expect(subject.value).to eq 'ABCFG' + end +end + +describe Dentaku::AST::StringFunctions::Concat do + it 'concatenates two strings' do + subject = described_class.new(literal('ABC'), literal('DEF')) + expect(subject.value).to eq 'ABCDEF' + end + + it 'concatenates a string onto an empty string' do + subject = described_class.new(literal(''), literal('ABC')) + expect(subject.value).to eq 'ABC' + end + + it 'concatenates an empty string onto a string' do + subject = described_class.new(literal('ABC'), literal('')) + expect(subject.value).to eq 'ABC' + end + + it 'concatenates two empty strings' do + subject = described_class.new(literal(''), literal('')) + expect(subject.value).to eq '' + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/benchmark.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/benchmark.rb new file mode 100644 index 0000000..2fbbe2d --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/benchmark.rb @@ -0,0 +1,70 @@ +#!/usr/bin/env ruby + +require 'dentaku' +require 'allocation_stats' +require 'benchmark' + +puts "Dentaku version #{Dentaku::VERSION}" +puts "Ruby version #{RUBY_VERSION}" + +with_duplicate_variables = [ + "R1+R2+R3+R4+R5+R6", + {"R1"=>100000, "R2"=>0, "R3"=>200000, "R4"=>0, "R5"=>500000, "R6"=>0, "r1"=>100000, "r2"=>0, "r3"=>200000, "r4"=>0, "r5"=>500000, "r6"=>0} +] + +without_duplicate_variables = [ + "R1+R2+R3+R4+R5+R6", + {"R1"=>100000, "R2"=>0, "R3"=>200000, "R4"=>0, "R5"=>500000, "R6"=>0} +] + +def test(args, custom_function: true) + calls = [ args ] * 100 + + 10.times do |i| + + stats = nil + bm = Benchmark.measure do + stats = AllocationStats.trace do + + calls.each do |formula, bound| + + calculator = Dentaku::Calculator.new + + if custom_function + calculator.add_function( + :sum, + :numeric, + ->(numbers) { numbers.inject(:+) } + ) + end + + calculator.evaluate(formula, bound) + end + end + end + + puts " run #{i}: #{bm.total}" + puts stats.allocations(alias_paths: true).group_by(:sourcefile, :class).to_text + end +end + +case ARGV[0] +when '1' + puts "with duplicate (downcased) variables, with a custom function:" + test(with_duplicate_variables, custom_function: true) + +when '2' + puts "with duplicate (downcased) variables, without a custom function:" + test(with_duplicate_variables, custom_function: false) + +when '3' + puts "without duplicate (downcased) variables, with a custom function:" + test(without_duplicate_variables, custom_function: true) + +when '4' + puts "with duplicate (downcased) variables, without a custom function:" + test(without_duplicate_variables, custom_function: false) + +else + puts "select a run option (1-4)" +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/bulk_expression_solver_spec.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/bulk_expression_solver_spec.rb new file mode 100644 index 0000000..0f5cd05 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/bulk_expression_solver_spec.rb @@ -0,0 +1,77 @@ +require 'spec_helper' +require 'dentaku/bulk_expression_solver' + +RSpec.describe Dentaku::BulkExpressionSolver do + let(:calculator) { Dentaku::Calculator.new } + + describe "#solve!" do + it "evaluates properly with variables, even if some in memory" do + expressions = { + weekly_fruit_budget: "weekly_apple_budget + pear * 4", + weekly_apple_budget: "apples * 7", + pear: "1" + } + solver = described_class.new(expressions, calculator.store(apples: 3)) + expect(solver.solve!) + .to eq(pear: 1, weekly_apple_budget: 21, weekly_fruit_budget: 25) + end + + it "lets you know if a variable is unbound" do + expressions = {more_apples: "apples + 1"} + expect { + described_class.new(expressions, calculator).solve! + }.to raise_error(Dentaku::UnboundVariableError) + end + + it "lets you know if the result is a div/0 error" do + expressions = {more_apples: "1/0"} + expect { + described_class.new(expressions, calculator).solve! + }.to raise_error(Dentaku::ZeroDivisionError) + end + + it "does not require keys to be parseable" do + expressions = { "the value of x, incremented" => "x + 1" } + solver = described_class.new(expressions, calculator.store("x" => 3)) + expect(solver.solve!).to eq({ "the value of x, incremented" => 4 }) + end + end + + describe "#solve" do + it "returns :undefined when variables are unbound" do + expressions = {more_apples: "apples + 1"} + expect(described_class.new(expressions, calculator).solve) + .to eq(more_apples: :undefined) + end + + it "allows passing in a custom value to an error handler when a variable is unbound" do + expressions = {more_apples: "apples + 1"} + expect(described_class.new(expressions, calculator).solve { :foo }) + .to eq(more_apples: :foo) + end + + it "allows passing in a custom value to an error handler when there is a div/0 error" do + expressions = {more_apples: "1/0"} + expect(described_class.new(expressions, calculator).solve { :foo }) + .to eq(more_apples: :foo) + end + + it 'stores the recipient variable on the exception when there is a div/0 error' do + expressions = {more_apples: "1/0"} + exception = nil + described_class.new(expressions, calculator).solve do |ex| + exception = ex + end + expect(exception.recipient_variable).to eq('more_apples') + end + + it 'stores the recipient variable on the exception when there is an unbound variable' do + expressions = {more_apples: "apples + 1"} + exception = nil + described_class.new(expressions, calculator).solve do |ex| + exception = ex + end + expect(exception.recipient_variable).to eq('more_apples') + end + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/calculator_spec.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/calculator_spec.rb new file mode 100644 index 0000000..041574c --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/calculator_spec.rb @@ -0,0 +1,450 @@ +require 'spec_helper' +require 'dentaku/calculator' + +describe Dentaku::Calculator do + let(:calculator) { described_class.new } + let(:with_memory) { described_class.new.store(apples: 3) } + + it 'evaluates an expression' do + expect(calculator.evaluate('7+3')).to eq(10) + expect(calculator.evaluate('2 -1')).to eq(1) + expect(calculator.evaluate('-1 + 2')).to eq(1) + expect(calculator.evaluate('1 - 2')).to eq(-1) + expect(calculator.evaluate('1 - - 2')).to eq(3) + expect(calculator.evaluate('-1 - - 2')).to eq(1) + expect(calculator.evaluate('1 - - - 2')).to eq(-1) + expect(calculator.evaluate('(-1 + 2)')).to eq(1) + expect(calculator.evaluate('-(1 + 2)')).to eq(-3) + expect(calculator.evaluate('2 ^ - 1')).to eq(0.5) + expect(calculator.evaluate('2 ^ -(3 - 2)')).to eq(0.5) + expect(calculator.evaluate('(2 + 3) - 1')).to eq(4) + expect(calculator.evaluate('(-2 + 3) - 1')).to eq(0) + expect(calculator.evaluate('(-2 - 3) - 1')).to eq(-6) + expect(calculator.evaluate('1 + -(2 ^ 2)')).to eq(-3) + expect(calculator.evaluate('3 + -num', num: 2)).to eq(1) + expect(calculator.evaluate('-num + 3', num: 2)).to eq(1) + expect(calculator.evaluate('10 ^ 2')).to eq(100) + expect(calculator.evaluate('0 * 10 ^ -5')).to eq(0) + expect(calculator.evaluate('3 + 0 * -3')).to eq(3) + expect(calculator.evaluate('3 + 0 / -3')).to eq(3) + expect(calculator.evaluate('15 % 8')).to eq(7) + expect(calculator.evaluate('(((695759/735000)^(1/(1981-1991)))-1)*1000').round(4)).to eq(5.5018) + expect(calculator.evaluate('0.253/0.253')).to eq(1) + expect(calculator.evaluate('0.253/d', d: 0.253)).to eq(1) + expect(calculator.evaluate('10 + x', x: 'abc')).to be_nil + end + + describe 'memory' do + it { expect(calculator).to be_empty } + it { expect(with_memory).not_to be_empty } + it { expect(with_memory.clear).to be_empty } + + it 'discards local values' do + expect(calculator.evaluate('pears * 2', pears: 5)).to eq(10) + expect(calculator).to be_empty + end + + it 'can store the value `false`' do + calculator.store('i_am_false', false) + expect(calculator.evaluate!('i_am_false')).to eq false + end + + it 'can store multiple values' do + calculator.store(first: 1, second: 2) + expect(calculator.evaluate!('first')).to eq 1 + expect(calculator.evaluate!('second')).to eq 2 + end + + it 'stores formulas' do + calculator.store_formula('area', 'length * width') + expect(calculator.evaluate!('area', length: 5, width: 5)).to eq 25 + end + end + + describe 'dependencies' do + it "finds dependencies in a generic statement" do + expect(calculator.dependencies("bob + dole / 3")).to eq(['bob', 'dole']) + end + + it "doesn't consider variables in memory as dependencies" do + expect(with_memory.dependencies("apples + oranges")).to eq(['oranges']) + end + end + + describe 'solve!' do + it "evaluates properly with variables, even if some in memory" do + expect(with_memory.solve!( + weekly_fruit_budget: "weekly_apple_budget + pear * 4", + weekly_apple_budget: "apples * 7", + pear: "1" + )).to eq(pear: 1, weekly_apple_budget: 21, weekly_fruit_budget: 25) + end + + it "preserves hash keys" do + expect(calculator.solve!( + 'meaning_of_life' => 'age + kids', + 'age' => 40, + 'kids' => 2 + )).to eq('age' => 40, 'kids' => 2, 'meaning_of_life' => 42) + end + + it "lets you know about a cycle if one occurs" do + expect do + calculator.solve!(health: "happiness", happiness: "health") + end.to raise_error(TSort::Cyclic) + end + + it 'is case-insensitive' do + result = with_memory.solve!(total_fruit: "Apples + pears", pears: 10) + expect(result[:total_fruit]).to eq 13 + end + + it "lets you know if a variable is unbound" do + expect { + calculator.solve!(more_apples: "apples + 1") + }.to raise_error(Dentaku::UnboundVariableError) + end + + it 'can reference stored formulas' do + calculator.store_formula("base_area", "length * width") + calculator.store_formula("volume", "base_area * height") + + result = calculator.solve!( + weight: "volume * 5.432", + height: "3", + length: "2", + width: "length * 2", + ) + + expect(result[:weight]).to eq 130.368 + end + end + + describe 'solve' do + it "returns :undefined when variables are unbound" do + expressions = {more_apples: "apples + 1"} + expect(calculator.solve(expressions)).to eq(more_apples: :undefined) + end + + it "allows passing in a custom value to an error handler" do + expressions = {more_apples: "apples + 1"} + expect(calculator.solve(expressions) { :foo }) + .to eq(more_apples: :foo) + end + + it "solves remainder of expressions with unbound variable" do + calculator.store(peaches: 1, oranges: 1) + expressions = { more_apples: "apples + 1", more_peaches: "peaches + 1" } + result = calculator.solve(expressions) + expect(calculator.memory).to eq("peaches" => 1, "oranges" => 1) + expect(result).to eq( + more_apples: :undefined, + more_peaches: 2 + ) + end + + it "solves remainder of expressions when one cannot be evaluated" do + result = calculator.solve( + conditional: "IF(d != 0, ratio, 0)", + ratio: "10/d", + d: 0, + ) + + expect(result).to eq( + conditional: 0, + ratio: :undefined, + d: 0, + ) + end + end + + it 'evaluates a statement with no variables' do + expect(calculator.evaluate('5+3')).to eq(8) + expect(calculator.evaluate('(1+1+1)/3*100')).to eq(100) + end + + it 'fails to evaluate unbound statements' do + unbound = 'foo * 1.5' + expect { calculator.evaluate!(unbound) }.to raise_error(Dentaku::UnboundVariableError) + expect { calculator.evaluate!(unbound) }.to raise_error do |error| + expect(error.unbound_variables).to eq ['foo'] + end + expect(calculator.evaluate(unbound)).to be_nil + expect(calculator.evaluate(unbound) { :bar }).to eq :bar + expect(calculator.evaluate(unbound) { |e| e }).to eq unbound + end + + it 'evaluates unbound statements given a binding in memory' do + expect(calculator.evaluate('foo * 1.5', foo: 2)).to eq(3) + expect(calculator.bind(monkeys: 3).evaluate('monkeys < 7')).to be_truthy + expect(calculator.evaluate('monkeys / 1.5')).to eq(2) + end + + it 'rebinds for each evaluation' do + expect(calculator.evaluate('foo * 2', foo: 2)).to eq(4) + expect(calculator.evaluate('foo * 2', foo: 4)).to eq(8) + end + + it 'accepts strings or symbols for binding keys' do + expect(calculator.evaluate('foo * 2', foo: 2)).to eq(4) + expect(calculator.evaluate('foo * 2', 'foo' => 4)).to eq(8) + end + + it 'accepts digits in identifiers' do + expect(calculator.evaluate('foo1 * 2', foo1: 2)).to eq(4) + expect(calculator.evaluate('foo1 * 2', 'foo1' => 4)).to eq(8) + expect(calculator.evaluate('1foo * 2', '1foo' => 2)).to eq(4) + expect(calculator.evaluate('fo1o * 2', fo1o: 4)).to eq(8) + end + + it 'compares string literals with string variables' do + expect(calculator.evaluate('fruit = "apple"', fruit: 'apple')).to be_truthy + expect(calculator.evaluate('fruit = "apple"', fruit: 'pear')).to be_falsey + end + + it 'performs case-sensitive comparison' do + expect(calculator.evaluate('fruit = "Apple"', fruit: 'apple')).to be_falsey + expect(calculator.evaluate('fruit = "Apple"', fruit: 'Apple')).to be_truthy + end + + it 'allows binding logical values' do + expect(calculator.evaluate('some_boolean AND 7 > 5', some_boolean: true)).to be_truthy + expect(calculator.evaluate('some_boolean AND 7 < 5', some_boolean: true)).to be_falsey + expect(calculator.evaluate('some_boolean AND 7 > 5', some_boolean: false)).to be_falsey + + expect(calculator.evaluate('some_boolean OR 7 > 5', some_boolean: true)).to be_truthy + expect(calculator.evaluate('some_boolean OR 7 < 5', some_boolean: true)).to be_truthy + expect(calculator.evaluate('some_boolean OR 7 < 5', some_boolean: false)).to be_falsey + end + + describe 'functions' do + it 'include IF' do + expect(calculator.evaluate('if(foo < 8, 10, 20)', foo: 2)).to eq(10) + expect(calculator.evaluate('if(foo < 8, 10, 20)', foo: 9)).to eq(20) + expect(calculator.evaluate('if (foo < 8, 10, 20)', foo: 2)).to eq(10) + expect(calculator.evaluate('if (foo < 8, 10, 20)', foo: 9)).to eq(20) + end + + it 'include ROUND' do + expect(calculator.evaluate('round(8.2)')).to eq(8) + expect(calculator.evaluate('round(8.8)')).to eq(9) + expect(calculator.evaluate('round(8.75, 1)')).to eq(BigDecimal.new('8.8')) + + expect(calculator.evaluate('ROUND(apples * 0.93)', { apples: 10 })).to eq(9) + end + + it 'include NOT' do + expect(calculator.evaluate('NOT(some_boolean)', some_boolean: true)).to be_falsey + expect(calculator.evaluate('NOT(some_boolean)', some_boolean: false)).to be_truthy + + expect(calculator.evaluate('NOT(some_boolean) AND 7 > 5', some_boolean: true)).to be_falsey + expect(calculator.evaluate('NOT(some_boolean) OR 7 < 5', some_boolean: false)).to be_truthy + end + + it 'evaluates functions with negative numbers' do + expect(calculator.evaluate('if (-1 < 5, -1, 5)')).to eq(-1) + expect(calculator.evaluate('if (-1 = -1, -1, 5)')).to eq(-1) + expect(calculator.evaluate('round(-1.23, 1)')).to eq(BigDecimal.new('-1.2')) + expect(calculator.evaluate('NOT(some_boolean) AND -1 > 3', some_boolean: true)).to be_falsey + end + + it 'evaluates functions with stored variables' do + calculator.store("multi_color" => true, "number_of_sheets" => 5000, "sheets_per_minute_black" => 2000, "sheets_per_minute_color" => 1000) + result = calculator.evaluate('number_of_sheets / if(multi_color, sheets_per_minute_color, sheets_per_minute_black)') + expect(result).to eq(5) + end + + describe 'roundup' do + it 'should work with one argument' do + expect(calculator.evaluate('roundup(1.234)')).to eq(2) + end + + it 'should accept second precision argument like in Office formula' do + expect(calculator.evaluate('roundup(1.234, 2)')).to eq(1.24) + end + end + + describe 'rounddown' do + it 'should work with one argument' do + expect(calculator.evaluate('rounddown(1.234)')).to eq(1) + end + + it 'should accept second precision argument like in Office formula' do + expect(calculator.evaluate('rounddown(1.234, 2)')).to eq(1.23) + end + end + end + + describe 'explicit NULL' do + it 'can be used in IF statements' do + expect(calculator.evaluate('IF(null, 1, 2)')).to eq(2) + end + + it 'can be used in IF statements when passed in' do + expect(calculator.evaluate('IF(foo, 1, 2)', foo: nil)).to eq(2) + end + + it 'nil values are carried across middle terms' do + results = calculator.solve!( + choice: 'IF(bar, 1, 2)', + bar: 'foo', + foo: nil) + expect(results).to eq( + choice: 2, + bar: nil, + foo: nil + ) + end + + it 'raises errors when used in arithmetic operation' do + expect { + calculator.solve!(more_apples: "apples + 1", apples: nil) + }.to raise_error(Dentaku::ArgumentError) + end + end + + describe 'case statements' do + it 'handles complex then statements' do + formula = <<-FORMULA + CASE fruit + WHEN 'apple' + THEN (1 * quantity) + WHEN 'banana' + THEN (2 * quantity) + END + FORMULA + expect(calculator.evaluate(formula, quantity: 3, fruit: 'apple')).to eq(3) + expect(calculator.evaluate(formula, quantity: 3, fruit: 'banana')).to eq(6) + end + + it 'handles complex when statements' do + formula = <<-FORMULA + CASE number + WHEN (2 * 2) + THEN 1 + WHEN (2 * 3) + THEN 2 + END + FORMULA + expect(calculator.evaluate(formula, number: 4)).to eq(1) + expect(calculator.evaluate(formula, number: 6)).to eq(2) + end + + it 'throws an exception when no match and there is no default value' do + formula = <<-FORMULA + CASE number + WHEN 42 + THEN 1 + END + FORMULA + expect { calculator.evaluate(formula, number: 2) } + .to raise_error("No block matched the switch value '2'") + end + + it 'handles a default else statement' do + formula = <<-FORMULA + CASE fruit + WHEN 'apple' + THEN 1 * quantity + WHEN 'banana' + THEN 2 * quantity + ELSE + 3 * quantity + END + FORMULA + expect(calculator.evaluate(formula, quantity: 1, fruit: 'banana')).to eq(2) + expect(calculator.evaluate(formula, quantity: 1, fruit: 'orange')).to eq(3) + end + + it 'handles nested case statements' do + formula = <<-FORMULA + CASE fruit + WHEN 'apple' + THEN 1 * quantity + WHEN 'banana' + THEN + CASE quantity + WHEN 1 THEN 2 + WHEN 10 THEN + CASE type + WHEN 'organic' THEN 5 + END + END + END + FORMULA + value = calculator.evaluate( + formula, + type: 'organic', + quantity: 10, + fruit: 'banana') + expect(value).to eq(5) + end + end + + describe 'math functions' do + Math.methods(false).each do |method| + it method do + if Math.method(method).arity == 2 + expect(calculator.evaluate("#{method}(1,2)")).to eq Math.send(method, 1, 2) + else + expect(calculator.evaluate("#{method}(1)")).to eq Math.send(method, 1) + end + end + end + end + + describe 'disable_cache' do + before do + allow(Dentaku).to receive(:cache_ast?) { true } + end + + it 'disables the AST cache' do + expect(calculator.disable_cache{ |c| c.cache_ast? }).to be false + end + + it 'calculates normally' do + expect(calculator.disable_cache{ |c| c.evaluate("2 + 2") }).to eq(4) + end + end + + describe 'clear_cache' do + before do + allow(Dentaku).to receive(:cache_ast?) { true } + + calculator.ast("1+1") + calculator.ast("pineapples * 5") + calculator.ast("pi * radius ^ 2") + + def calculator.ast_cache + @ast_cache + end + end + + it 'clears all items from cache' do + expect(calculator.ast_cache.length).to eq 3 + calculator.clear_cache + expect(calculator.ast_cache.keys).to be_empty + end + + it 'clears one item from cache' do + calculator.clear_cache("1+1") + expect(calculator.ast_cache.keys.sort).to eq([ + 'pi * radius ^ 2', + 'pineapples * 5', + ]) + end + + it 'clears items matching regex from cache' do + calculator.clear_cache(/^pi/) + expect(calculator.ast_cache.keys.sort).to eq(['1+1']) + end + end + + describe 'string functions' do + it 'concatenates two strings' do + expect( + calculator.evaluate('CONCAT(s1, s2)', 's1' => 'abc', 's2' => 'def') + ).to eq 'abcdef' + end + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/dentaku_spec.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/dentaku_spec.rb new file mode 100644 index 0000000..3704a7b --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/dentaku_spec.rb @@ -0,0 +1,22 @@ +require 'dentaku' + +describe Dentaku do + it 'evaulates an expression' do + expect(Dentaku('5+3')).to eql(8) + end + + it 'binds values to variables' do + expect(Dentaku('oranges > 7', oranges: 10)).to be_truthy + end + + it 'evaulates a nested function' do + expect(Dentaku('roundup(roundup(3 * cherries) + raspberries)', cherries: 1.5, raspberries: 0.9)).to eql(6) + end + + it 'treats variables as case-insensitive' do + expect(Dentaku('40 + N', 'n' => 2)).to eql(42) + expect(Dentaku('40 + N', 'N' => 2)).to eql(42) + expect(Dentaku('40 + n', 'N' => 2)).to eql(42) + expect(Dentaku('40 + n', 'n' => 2)).to eql(42) + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/exceptions_spec.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/exceptions_spec.rb new file mode 100644 index 0000000..4af3d4a --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/exceptions_spec.rb @@ -0,0 +1,9 @@ +require 'spec_helper' +require 'dentaku/exceptions' + +describe Dentaku::UnboundVariableError do + it 'includes variable name(s) in message' do + exception = described_class.new(['length']) + expect(exception.message).to match /length/ + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/external_function_spec.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/external_function_spec.rb new file mode 100644 index 0000000..3b8797d --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/external_function_spec.rb @@ -0,0 +1,56 @@ +require 'spec_helper' +require 'dentaku/calculator' + +describe Dentaku::Calculator do + describe 'functions' do + describe 'external functions' do + + let(:with_external_funcs) do + c = described_class.new + + c.add_function(:now, :string, -> { Time.now.to_s }) + + fns = [ + [:pow, :numeric, ->(mantissa, exponent) { mantissa ** exponent }], + [:biggest, :numeric, ->(*args) { args.max }], + [:smallest, :numeric, ->(*args) { args.min }], + ] + + c.add_functions(fns) + end + + it 'includes NOW' do + now = with_external_funcs.evaluate('NOW()') + expect(now).not_to be_nil + expect(now).not_to be_empty + end + + it 'includes POW' do + expect(with_external_funcs.evaluate('POW(2,3)')).to eq(8) + expect(with_external_funcs.evaluate('POW(3,2)')).to eq(9) + expect(with_external_funcs.evaluate('POW(mantissa,exponent)', mantissa: 2, exponent: 4)).to eq(16) + end + + it 'includes BIGGEST' do + expect(with_external_funcs.evaluate('BIGGEST(8,6,7,5,3,0,9)')).to eq(9) + end + + it 'includes SMALLEST' do + expect(with_external_funcs.evaluate('SMALLEST(8,6,7,5,3,0,9)')).to eq(0) + end + + it 'supports array parameters' do + calculator = described_class.new + calculator.add_function( + :includes, + :logical, + ->(haystack, needle) { + haystack.include?(needle) + } + ) + + expect(calculator.evaluate("INCLUDES(list, 2)", list: [1,2,3])).to eq(true) + end + end + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/parser_spec.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/parser_spec.rb new file mode 100644 index 0000000..fc567d6 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/parser_spec.rb @@ -0,0 +1,150 @@ +require 'spec_helper' +require 'dentaku/token' +require 'dentaku/parser' + +describe Dentaku::Parser do + it 'is constructed from a token' do + token = Dentaku::Token.new(:numeric, 5) + node = described_class.new([token]).parse + expect(node.value).to eq 5 + end + + it 'performs simple addition' do + five = Dentaku::Token.new(:numeric, 5) + plus = Dentaku::Token.new(:operator, :add) + four = Dentaku::Token.new(:numeric, 4) + + node = described_class.new([five, plus, four]).parse + expect(node.value).to eq 9 + end + + it 'compares two numbers' do + five = Dentaku::Token.new(:numeric, 5) + lt = Dentaku::Token.new(:comparator, :lt) + four = Dentaku::Token.new(:numeric, 4) + + node = described_class.new([five, lt, four]).parse + expect(node.value).to eq false + end + + it 'calculates unary percentage' do + five = Dentaku::Token.new(:numeric, 5) + mod = Dentaku::Token.new(:operator, :mod) + + node = described_class.new([five, mod]).parse + expect(node.value).to eq 0.05 + end + + it 'performs multiple operations in one stream' do + five = Dentaku::Token.new(:numeric, 5) + plus = Dentaku::Token.new(:operator, :add) + four = Dentaku::Token.new(:numeric, 4) + times = Dentaku::Token.new(:operator, :multiply) + three = Dentaku::Token.new(:numeric, 3) + + node = described_class.new([five, plus, four, times, three]).parse + expect(node.value).to eq 17 + end + + it 'respects order of operations' do + five = Dentaku::Token.new(:numeric, 5) + times = Dentaku::Token.new(:operator, :multiply) + four = Dentaku::Token.new(:numeric, 4) + plus = Dentaku::Token.new(:operator, :add) + three = Dentaku::Token.new(:numeric, 3) + + node = described_class.new([five, times, four, plus, three]).parse + expect(node.value).to eq 23 + end + + it 'respects grouping by parenthesis' do + lpar = Dentaku::Token.new(:grouping, :open) + five = Dentaku::Token.new(:numeric, 5) + plus = Dentaku::Token.new(:operator, :add) + four = Dentaku::Token.new(:numeric, 4) + rpar = Dentaku::Token.new(:grouping, :close) + times = Dentaku::Token.new(:operator, :multiply) + three = Dentaku::Token.new(:numeric, 3) + + node = described_class.new([lpar, five, plus, four, rpar, times, three]).parse + expect(node.value).to eq 27 + end + + it 'evaluates functions' do + fn = Dentaku::Token.new(:function, :if) + fopen = Dentaku::Token.new(:grouping, :open) + five = Dentaku::Token.new(:numeric, 5) + lt = Dentaku::Token.new(:comparator, :lt) + four = Dentaku::Token.new(:numeric, 4) + comma = Dentaku::Token.new(:grouping, :comma) + three = Dentaku::Token.new(:numeric, 3) + two = Dentaku::Token.new(:numeric, 2) + rpar = Dentaku::Token.new(:grouping, :close) + + node = described_class.new([fn, fopen, five, lt, four, comma, three, comma, two, rpar]).parse + expect(node.value).to eq 2 + end + + it 'represents formulas with variables' do + five = Dentaku::Token.new(:numeric, 5) + times = Dentaku::Token.new(:operator, :multiply) + x = Dentaku::Token.new(:identifier, :x) + + node = described_class.new([five, times, x]).parse + expect { node.value }.to raise_error(Dentaku::UnboundVariableError) + expect(node.value(x: 3)).to eq 15 + end + + it 'evaluates boolean expressions' do + d_true = Dentaku::Token.new(:logical, true) + d_and = Dentaku::Token.new(:combinator, :and) + d_false = Dentaku::Token.new(:logical, false) + + node = described_class.new([d_true, d_and, d_false]).parse + expect(node.value).to eq false + end + + it 'evaluates a case statement' do + case_start = Dentaku::Token.new(:case, :open) + x = Dentaku::Token.new(:identifier, :x) + case_when1 = Dentaku::Token.new(:case, :when) + one = Dentaku::Token.new(:numeric, 1) + case_then1 = Dentaku::Token.new(:case, :then) + two = Dentaku::Token.new(:numeric, 2) + case_when2 = Dentaku::Token.new(:case, :when) + three = Dentaku::Token.new(:numeric, 3) + case_then2 = Dentaku::Token.new(:case, :then) + four = Dentaku::Token.new(:numeric, 4) + case_close = Dentaku::Token.new(:case, :close) + + node = described_class.new( + [case_start, + x, + case_when1, + one, + case_then1, + two, + case_when2, + three, + case_then2, + four, + case_close]).parse + expect(node.value(x: 3)).to eq(4) + end + + it 'raises an error on parse failure' do + five = Dentaku::Token.new(:numeric, 5) + times = Dentaku::Token.new(:operator, :multiply) + minus = Dentaku::Token.new(:operator, :subtract) + + expect { + described_class.new([five, times, minus]).parse + }.to raise_error(Dentaku::ParseError) + end + + it "evaluates explicit 'NULL' as a Nil" do + null = Dentaku::Token.new(:null, nil) + node = described_class.new([null]).parse + expect(node.value).to eq(nil) + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/spec_helper.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/spec_helper.rb new file mode 100644 index 0000000..90f8f0a --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/spec_helper.rb @@ -0,0 +1,41 @@ +require 'pry' + +# automatically create a token stream from bare values +def token_stream(*args) + args.map do |value| + type = type_for(value) + Dentaku::Token.new(type, value) + end +end + +# make a (hopefully intelligent) guess about type +def type_for(value) + case value + when Numeric + :numeric + when String + :string + when true, false + :logical + when :add, :subtract, :multiply, :divide, :mod, :pow + :operator + when :open, :close, :comma + :grouping + when :le, :ge, :ne, :ne, :lt, :gt, :eq + :comparator + when :and, :or + :combinator + when :if, :round, :roundup, :rounddown, :not + :function + else + :identifier + end +end + +def identifier(name) + Dentaku::AST::Identifier.new(Dentaku::Token.new(:identifier, name)) +end + +def literal(value) + Dentaku::AST::Literal.new(Dentaku::Token.new(type_for(value), value)) +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/token_matcher_spec.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/token_matcher_spec.rb new file mode 100644 index 0000000..cf9f9b6 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/token_matcher_spec.rb @@ -0,0 +1,135 @@ +require 'spec_helper' +require 'dentaku/token_matcher' + +describe Dentaku::TokenMatcher do + it 'with single category matches token category' do + matcher = described_class.new(:numeric) + token = Dentaku::Token.new(:numeric, 5) + + expect(matcher).to eq(token) + end + + it 'with multiple categories matches any included token category' do + matcher = described_class.new([:comparator, :operator]) + numeric = Dentaku::Token.new(:numeric, 5) + comparator = Dentaku::Token.new(:comparator, :lt) + operator = Dentaku::Token.new(:operator, :add) + + expect(matcher).to eq(comparator) + expect(matcher).to eq(operator) + expect(matcher).not_to eq(numeric) + end + + it 'with single category and value matches token category and value' do + matcher = described_class.new(:operator, :add) + addition = Dentaku::Token.new(:operator, :add) + subtraction = Dentaku::Token.new(:operator, :subtract) + + expect(matcher).to eq(addition) + expect(matcher).not_to eq(subtraction) + end + + it 'with multiple values matches any included token value' do + matcher = described_class.new(:operator, [:add, :subtract]) + add = Dentaku::Token.new(:operator, :add) + sub = Dentaku::Token.new(:operator, :subtract) + mul = Dentaku::Token.new(:operator, :multiply) + div = Dentaku::Token.new(:operator, :divide) + + expect(matcher).to eq(add) + expect(matcher).to eq(sub) + expect(matcher).not_to eq(mul) + expect(matcher).not_to eq(div) + end + + it 'is invertible' do + matcher = described_class.new(:operator, [:add, :subtract]).invert + add = Dentaku::Token.new(:operator, :add) + mul = Dentaku::Token.new(:operator, :multiply) + cmp = Dentaku::Token.new(:comparator, :lt) + + expect(matcher).not_to eq(add) + expect(matcher).to eq(mul) + expect(matcher).to eq(cmp) + end + + describe 'combining multiple tokens' do + let(:numeric) { described_class.new(:numeric) } + let(:string) { described_class.new(:string) } + + it 'matches either' do + either = numeric | string + expect(either).to eq(Dentaku::Token.new(:numeric, 5)) + expect(either).to eq(Dentaku::Token.new(:string, 'rhubarb')) + end + + it 'matches any value' do + value = described_class.value + expect(value).to eq(Dentaku::Token.new(:numeric, 8)) + expect(value).to eq(Dentaku::Token.new(:string, 'apricot')) + expect(value).to eq(Dentaku::Token.new(:logical, false)) + expect(value).not_to eq(Dentaku::Token.new(:function, :round)) + expect(value).not_to eq(Dentaku::Token.new(:identifier, :hello)) + end + end + + describe 'stream matching' do + let(:stream) { token_stream(5, 11, 9, 24, :hello, 8) } + + describe 'standard' do + let(:standard) { described_class.new(:numeric) } + + it 'matches zero or more occurrences in a token stream' do + matched, substream = standard.match(stream) + expect(matched).to be_truthy + expect(substream.length).to eq 1 + expect(substream.map(&:value)).to eq [5] + + matched, substream = standard.match(stream, 4) + expect(substream).to be_empty + expect(matched).not_to be_truthy + end + end + + describe 'star' do + let(:star) { described_class.new(:numeric).star } + + it 'matches zero or more occurrences in a token stream' do + matched, substream = star.match(stream) + expect(matched).to be_truthy + expect(substream.length).to eq 4 + expect(substream.map(&:value)).to eq [5, 11, 9, 24] + + matched, substream = star.match(stream, 4) + expect(substream).to be_empty + expect(matched).to be_truthy + end + end + + describe 'plus' do + let(:plus) { described_class.new(:numeric).plus } + + it 'matches one or more occurrences in a token stream' do + matched, substream = plus.match(stream) + expect(matched).to be_truthy + expect(substream.length).to eq 4 + expect(substream.map(&:value)).to eq [5, 11, 9, 24] + + matched, substream = plus.match(stream, 4) + expect(substream).to be_empty + expect(matched).not_to be_truthy + end + end + + describe 'arguments' do + it 'matches comma-separated values' do + stream = token_stream(1, :comma, 2, :comma, true, :comma, 'olive', :comma, :'(') + matched, substream = described_class.arguments.match(stream) + expect(matched).to be_truthy + expect(substream.length).to eq 8 + expect(substream.map(&:value)).to eq [1, :comma, 2, :comma, true, :comma, 'olive', :comma] + end + end + end +end + diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/token_scanner_spec.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/token_scanner_spec.rb new file mode 100644 index 0000000..27b51db --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/token_scanner_spec.rb @@ -0,0 +1,53 @@ +require 'dentaku/token_scanner' + +describe Dentaku::TokenScanner do + let(:whitespace) { described_class.new(:whitespace, '\s') } + let(:numeric) { described_class.new(:numeric, '(\d+(\.\d+)?|\.\d+)', + ->(raw) { raw =~ /\./ ? BigDecimal.new(raw) : raw.to_i }) + } + let(:custom) { described_class.new(:identifier, '#\w+\b', + ->(raw) { raw.gsub('#', '').to_sym }) + } + + after { described_class.register_default_scanners } + + it 'returns a token for a matching string' do + token = whitespace.scan(' ').first + expect(token.category).to eq(:whitespace) + expect(token.value).to eq(' ') + end + + it 'returns falsy for a non-matching string' do + expect(whitespace.scan('A')).not_to be + end + + it 'performs raw value conversion' do + token = numeric.scan('5').first + expect(token.category).to eq(:numeric) + expect(token.value).to eq(5) + end + + it 'returns a list of all configured scanners' do + expect(described_class.scanners.length).to eq 14 + end + + it 'allows customizing available scanners' do + described_class.scanners = [:whitespace, :numeric] + expect(described_class.scanners.length).to eq 2 + end + + it 'ignores invalid scanners' do + described_class.scanners = [:whitespace, :numeric, :fake] + expect(described_class.scanners.length).to eq 2 + end + + it 'uses a custom scanner' do + described_class.scanners = [:whitespace, :numeric] + described_class.register_scanner(:custom, custom) + expect(described_class.scanners.length).to eq 3 + + token = custom.scan('#apple + #pear').first + expect(token.category).to eq(:identifier) + expect(token.value).to eq(:apple) + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/token_spec.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/token_spec.rb new file mode 100644 index 0000000..01e385c --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/token_spec.rb @@ -0,0 +1,10 @@ +require 'dentaku/token' + +describe Dentaku::Token do + it 'has a category and a value' do + token = Dentaku::Token.new(:numeric, 5) + expect(token.category).to eq(:numeric) + expect(token.value).to eq(5) + expect(token.is?(:numeric)).to be_truthy + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/tokenizer_spec.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/tokenizer_spec.rb new file mode 100644 index 0000000..315bbc1 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/tokenizer_spec.rb @@ -0,0 +1,212 @@ +require 'dentaku/tokenizer' + +describe Dentaku::Tokenizer do + let(:tokenizer) { described_class.new } + + it 'handles an empty expression' do + expect(tokenizer.tokenize('')).to be_empty + end + + it 'tokenizes addition' do + tokens = tokenizer.tokenize('1+1') + expect(tokens.map(&:category)).to eq([:numeric, :operator, :numeric]) + expect(tokens.map(&:value)).to eq([1, :add, 1]) + end + + it 'tokenizes unary minus' do + tokens = tokenizer.tokenize('-5') + expect(tokens.map(&:category)).to eq([:operator, :numeric]) + expect(tokens.map(&:value)).to eq([:negate, 5]) + + tokens = tokenizer.tokenize('(-5)') + expect(tokens.map(&:category)).to eq([:grouping, :operator, :numeric, :grouping]) + expect(tokens.map(&:value)).to eq([:open, :negate, 5, :close]) + + tokens = tokenizer.tokenize('if(-5 > x, -7, -8) - 9') + expect(tokens.map(&:category)).to eq([ + :function, :grouping, # if( + :operator, :numeric, :comparator, :identifier, :grouping, # -5 > x, + :operator, :numeric, :grouping, # -7, + :operator, :numeric, :grouping, # -8) + :operator, :numeric # - 9 + ]) + expect(tokens.map(&:value)).to eq([ + :if, :open, # if( + :negate, 5, :gt, 'x', :comma, # -5 > x, + :negate, 7, :comma, # -7, + :negate, 8, :close, # -8) + :subtract, 9 # - 9 + ]) + end + + it 'tokenizes comparison with =' do + tokens = tokenizer.tokenize('number = 5') + expect(tokens.map(&:category)).to eq([:identifier, :comparator, :numeric]) + expect(tokens.map(&:value)).to eq(['number', :eq, 5]) + end + + it 'tokenizes comparison with =' do + tokens = tokenizer.tokenize('number = 5') + expect(tokens.map(&:category)).to eq([:identifier, :comparator, :numeric]) + expect(tokens.map(&:value)).to eq(['number', :eq, 5]) + end + + it 'tokenizes comparison with alternate ==' do + tokens = tokenizer.tokenize('number == 5') + expect(tokens.map(&:category)).to eq([:identifier, :comparator, :numeric]) + expect(tokens.map(&:value)).to eq(['number', :eq, 5]) + end + + it 'ignores whitespace' do + tokens = tokenizer.tokenize('1 / 1 ') + expect(tokens.map(&:category)).to eq([:numeric, :operator, :numeric]) + expect(tokens.map(&:value)).to eq([1, :divide, 1]) + end + + it 'tokenizes power operations' do + tokens = tokenizer.tokenize('10 ^ 2') + expect(tokens.map(&:category)).to eq([:numeric, :operator, :numeric]) + expect(tokens.map(&:value)).to eq([10, :pow, 2]) + end + + it 'tokenizes power operations' do + tokens = tokenizer.tokenize('0 * 10 ^ -5') + expect(tokens.map(&:category)).to eq([:numeric, :operator, :numeric, :operator, :operator, :numeric]) + expect(tokens.map(&:value)).to eq([0, :multiply, 10, :pow, :negate, 5]) + end + + it 'handles floating point' do + tokens = tokenizer.tokenize('1.5 * 3.7') + expect(tokens.map(&:category)).to eq([:numeric, :operator, :numeric]) + expect(tokens.map(&:value)).to eq([1.5, :multiply, 3.7]) + end + + it 'does not require leading zero' do + tokens = tokenizer.tokenize('.5 * 3.7') + expect(tokens.map(&:category)).to eq([:numeric, :operator, :numeric]) + expect(tokens.map(&:value)).to eq([0.5, :multiply, 3.7]) + end + + it 'accepts arbitrary identifiers' do + tokens = tokenizer.tokenize('sea_monkeys > 1500') + expect(tokens.map(&:category)).to eq([:identifier, :comparator, :numeric]) + expect(tokens.map(&:value)).to eq(['sea_monkeys', :gt, 1500]) + end + + it 'recognizes double-quoted strings' do + tokens = tokenizer.tokenize('animal = "giraffe"') + expect(tokens.map(&:category)).to eq([:identifier, :comparator, :string]) + expect(tokens.map(&:value)).to eq(['animal', :eq, 'giraffe']) + end + + it 'recognizes single-quoted strings' do + tokens = tokenizer.tokenize("animal = 'giraffe'") + expect(tokens.map(&:category)).to eq([:identifier, :comparator, :string]) + expect(tokens.map(&:value)).to eq(['animal', :eq, 'giraffe']) + end + + it 'recognizes binary minus operator' do + tokens = tokenizer.tokenize('2 - 3') + expect(tokens.map(&:category)).to eq([:numeric, :operator, :numeric]) + expect(tokens.map(&:value)).to eq([2, :subtract, 3]) + end + + it 'recognizes unary minus operator' do + tokens = tokenizer.tokenize('-2 + 3') + expect(tokens.map(&:category)).to eq([:operator, :numeric, :operator, :numeric]) + expect(tokens.map(&:value)).to eq([:negate, 2, :add, 3]) + end + + it 'recognizes unary minus operator' do + tokens = tokenizer.tokenize('2 - -3') + expect(tokens.map(&:category)).to eq([:numeric, :operator, :operator, :numeric]) + expect(tokens.map(&:value)).to eq([2, :subtract, :negate, 3]) + end + + it 'matches "<=" before "<"' do + tokens = tokenizer.tokenize('perimeter <= 7500') + expect(tokens.map(&:category)).to eq([:identifier, :comparator, :numeric]) + expect(tokens.map(&:value)).to eq(['perimeter', :le, 7500]) + end + + it 'matches "and" for logical expressions' do + tokens = tokenizer.tokenize('octopi <= 7500 AND sharks > 1500') + expect(tokens.map(&:category)).to eq([:identifier, :comparator, :numeric, :combinator, :identifier, :comparator, :numeric]) + expect(tokens.map(&:value)).to eq(['octopi', :le, 7500, :and, 'sharks', :gt, 1500]) + end + + it 'matches "or" for logical expressions' do + tokens = tokenizer.tokenize('size < 3 or admin = 1') + expect(tokens.map(&:category)).to eq([:identifier, :comparator, :numeric, :combinator, :identifier, :comparator, :numeric]) + expect(tokens.map(&:value)).to eq(['size', :lt, 3, :or, 'admin', :eq, 1]) + end + + it 'detects unbalanced parentheses' do + expect { tokenizer.tokenize('(5+3') }.to raise_error(Dentaku::TokenizerError, /too many opening parentheses/) + expect { tokenizer.tokenize(')') }.to raise_error(Dentaku::TokenizerError, /too many closing parentheses/) + end + + it 'recognizes identifiers that share initial substrings with combinators' do + tokens = tokenizer.tokenize('andover < 10') + expect(tokens.length).to eq(3) + expect(tokens.map(&:category)).to eq([:identifier, :comparator, :numeric]) + expect(tokens.map(&:value)).to eq(['andover', :lt, 10]) + end + + it 'tokenizes TRUE and FALSE literals' do + tokens = tokenizer.tokenize('true and false') + expect(tokens.length).to eq(3) + expect(tokens.map(&:category)).to eq([:logical, :combinator, :logical]) + expect(tokens.map(&:value)).to eq([true, :and, false]) + + tokens = tokenizer.tokenize('true_lies and falsehoods') + expect(tokens.length).to eq(3) + expect(tokens.map(&:category)).to eq([:identifier, :combinator, :identifier]) + expect(tokens.map(&:value)).to eq(['true_lies', :and, 'falsehoods']) + end + + describe 'functions' do + it 'include IF' do + tokens = tokenizer.tokenize('if(x < 10, y, z)') + expect(tokens.length).to eq(10) + expect(tokens.map(&:category)).to eq([:function, :grouping, :identifier, :comparator, :numeric, :grouping, :identifier, :grouping, :identifier, :grouping]) + expect(tokens.map(&:value)).to eq([:if, :open, 'x', :lt, 10, :comma, 'y', :comma, 'z', :close]) + end + + it 'include ROUND/UP/DOWN' do + tokens = tokenizer.tokenize('round(8.2)') + expect(tokens.length).to eq(4) + expect(tokens.map(&:category)).to eq([:function, :grouping, :numeric, :grouping]) + expect(tokens.map(&:value)).to eq([:round, :open, BigDecimal.new('8.2'), :close]) + + tokens = tokenizer.tokenize('round(8.75, 1)') + expect(tokens.length).to eq(6) + expect(tokens.map(&:category)).to eq([:function, :grouping, :numeric, :grouping, :numeric, :grouping]) + expect(tokens.map(&:value)).to eq([:round, :open, BigDecimal.new('8.75'), :comma, 1, :close]) + + tokens = tokenizer.tokenize('ROUNDUP(8.2)') + expect(tokens.length).to eq(4) + expect(tokens.map(&:category)).to eq([:function, :grouping, :numeric, :grouping]) + expect(tokens.map(&:value)).to eq([:roundup, :open, BigDecimal.new('8.2'), :close]) + + tokens = tokenizer.tokenize('RoundDown(8.2)') + expect(tokens.length).to eq(4) + expect(tokens.map(&:category)).to eq([:function, :grouping, :numeric, :grouping]) + expect(tokens.map(&:value)).to eq([:rounddown, :open, BigDecimal.new('8.2'), :close]) + end + + it 'include NOT' do + tokens = tokenizer.tokenize('not(8 < 5)') + expect(tokens.length).to eq(6) + expect(tokens.map(&:category)).to eq([:function, :grouping, :numeric, :comparator, :numeric, :grouping]) + expect(tokens.map(&:value)).to eq([:not, :open, 8, :lt, 5, :close]) + end + + it 'handles whitespace after function name' do + tokens = tokenizer.tokenize('not (8 < 5)') + expect(tokens.length).to eq(6) + expect(tokens.map(&:category)).to eq([:function, :grouping, :numeric, :comparator, :numeric, :grouping]) + expect(tokens.map(&:value)).to eq([:not, :open, 8, :lt, 5, :close]) + end + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/.gitignore b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/.gitignore new file mode 100644 index 0000000..864ca44 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/.gitignore @@ -0,0 +1,23 @@ +*.gem +*.rbc +.bundle +.config +coverage +InstalledFiles +lib/bundler/man +pkg +rdoc +spec/reports +test/tmp +test/version_tmp +tmp +Gemfile.lock +.rvmrc +.ruby-version +.ruby-gemset + +# YARD artifacts +.yardoc +_yardoc +doc/ +*.local diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/.rubocop.yml b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/.rubocop.yml new file mode 100644 index 0000000..f808b97 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/.rubocop.yml @@ -0,0 +1,35 @@ +AllCops: + Include: + - 'Rakefile' + - '*.gemspec' + - 'lib/**/*.rb' + - 'spec/**/*.rb' + Exclude: + - 'bin/**/*' + - 'smoke/**/*' + DisplayCopNames: true + StyleGuideCopsOnly: false + +Rails: + Enabled: false + +Style/FrozenStringLiteralComment: + Enabled: false + +Style/NumericPredicate: + Enabled: false + +Style/StringLiterals: + Enabled: false + +Style/RescueModifier: + Enabled: false + +Metrics/LineLength: + Max: 100 + Exclude: + - 'spec/**/*.rb' + +Metrics/ModuleLength: + CountComments: false # count full line comments? + Max: 120 diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/.travis.yml b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/.travis.yml new file mode 100644 index 0000000..ca87afc --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/.travis.yml @@ -0,0 +1,52 @@ +sudo: required +dist: trusty +language: ruby +before_install: + - gem install bundler + - gem update bundler + - smoke/provision.sh +rvm: + - 1.9.3 + - 2.0.0 + - 2.1.10 + - 2.2.4 + - 2.3.1 + - ruby-head +env: + - TEST_TASK=spec + +matrix: + allow_failures: + - rvm: jruby-head + - rvm: ruby-head + - rvm: jruby-9.0.5.0 + - rvm: 2.3.1 + env: TEST_TASK=smoke influx_version=nightly channel=nightlies + include: + - rvm: 2.3.1 + env: TEST_TASK=rubocop + - rvm: jruby-9.0.5.0 + env: JRUBY_OPTS='--client -J-XX:+TieredCompilation -J-XX:TieredStopAtLevel=1 -J-Xss2m -J-Xmx256M' + - rvm: jruby-head + env: JRUBY_OPTS='--client -J-XX:+TieredCompilation -J-XX:TieredStopAtLevel=1 -J-Xss2m -J-Xmx256M' + - rvm: 2.3.1 + env: TEST_TASK=smoke influx_version=0.10.3-1 pkghash=96244557d9bb7485ddc9d084ff7ce783 + - rvm: 2.3.1 + env: TEST_TASK=smoke influx_version=0.11.1-1 pkghash=f4cf8363125038dff038ced6b16bcafd + - rvm: 2.3.1 + env: TEST_TASK=smoke influx_version=0.12.2-1 pkghash=f28bb1c57d52dc1593dca45b86be5913 + - rvm: 2.3.1 + env: TEST_TASK=smoke influx_version=0.13.0 pkghash=4f0aa76fee22cf4c18e2a0779ba4f462 + - rvm: 2.3.1 + env: TEST_TASK=smoke influx_version=1.0.2 pkghash=3e4c349cb57507913d9abda1459bdbed + - rvm: 2.3.1 + env: TEST_TASK=smoke influx_version=1.1.0 pkghash=682904c350ecfc2a60ec9c6c08453ef2 + - rvm: 2.3.1 + env: TEST_TASK=smoke influx_version=nightly channel=nightlies + fail_fast: true +addons: + apt: + packages: + - haveged + - libgmp-dev +script: bundle exec rake $TEST_TASK diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/CHANGELOG.md b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/CHANGELOG.md new file mode 100644 index 0000000..7714956 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/CHANGELOG.md @@ -0,0 +1,125 @@ +# Changelog + +For the full commit log, [see here](https://github.com/influxdata/influxdb-ruby/commits/master). + +## Unreleased changes + +- None. + +## v0.3.13, released 2016-11-23 + +- You can now `InfluxDB::Client#query`, `#write_points`, `#write_point` and + `#write` now accept an additional parameter to override the database on + invokation time (#173, #176, @jfragoulis). + + +## v0.3.12, released 2016-11-15 + +- Bugfix for broken Unicode support (regression introduced in #169). + Please note, this is only properly tested on Ruby 2.1+ (#171). + +## v0.3.11, released 2016-10-12 + +- Bugfix/Enhancement in `PointValue#escape`. Input strings are now scrubbed + of invalid UTF byte sequences (#169, @ton31337). + +## v0.3.10, released 2016-10-03 + +- Bugfix in `Query::Builder#quote` (#168, @cthulhu666). + +## v0.3.9, released 2016-09-20 + +- Changed retry behaviour slightly. When the server responds with an incomplete + response, we now assume a major server-side problem (insufficient resources, + e.g. out-of-memory) and cancel any retry attempts (#165, #166). + +## v0.3.8, released 2016-08-31 + +- Added support for named and positional query parameters (#160, @retorquere). + +## v0.3.7, released 2016-08-14 + +- Fixed `prefix` handling for `#ping` and `#version` (#157, @dimiii). + +## v0.3.6, released 2016-07-24 + +- Added feature for JSON streaming response, via `"chunk_size"` parameter + (#155, @mhodson-qxbranch). + +## v0.3.5, released 2016-06-09 + +- Reintroduced full dependency on "cause" (for Ruby 1.9 compat). +- Extended `Client#create_database` and `#delete_database` to fallback on `config.database` (#153, #154, @anthonator). + +## v0.3.4, released 2016-06-07 + +- Added resample options to `Client#create_continuous_query` (#149). +- Fixed resample options to be Ruby 1.9 compatible (#150, @SebastianCoetzee). +- Mentioned in README, that 0.3.x series is the last one to support Ruby 1.9. + +## v0.3.3, released 2016-06-06 (yanked) + +- Added resample options to `Client#create_continuous_query` (#149). + +## v0.3.2, released 2016-06-02 + +- Added config option to authenticate without credentials (#146, @pmenglund). + +## v0.3.1, released 2016-05-26 + +- Fixed #130 (again). Integer values are now really written as Integers to InfluxDB. + +## v0.3.0, released 2016-04-24 + +- Write queries are now checked against 204 No Content responses, in accordance with the official documentation (#128). +- Async options are now configurabe (#107). + +## v0.2.6, released 2016-04-14 + +- Empty tag keys/values are now omitted (#124). + +## v0.2.5, released 2016-04-14 + +- Async writer now behaves when stopping the client (#73). +- Update development dependencies and started enforcing Rubocop styles. + +## v0.2.4, released 2016-04-12 + +- Added `InfluxDB::Client#version`, returning the server version (#117). +- Fixed escaping issues (#119, #121, #135). +- Integer values are now written as Integer, not as Float value (#131). +- Return all result series when querying multiple selects (#134). +- Made host cycling thread safe (#136). + +## v0.2.3, released 2015-10-27 + +- Added `epoch` option to client constructor and write methods (#104). +- Added `#list_user_grants` (#111), `#grant_user_admin_privileges` (#112) and `#alter_retention_policy` (#114) methods. + +## v0.2.2, released 2015-07-29 + +- Fixed issues with Async client (#101) +- Avoid usage of `gsub!` (#102) + +## v0.2.1, released 2015-07-25 + +- Fix double quote tags escaping (#98) + +## v0.2.0, released 2015-07-20 + +- Large library refactoring (#88, #90) + - Extract config from client + - Extract HTTP functionality to separate module + - Extract InfluxDB management functions to separate modules + - Add writer concept + - Refactor specs (add cases) + - Add 'denormalize' option to config + - Recognize SeriesNotFound error + - Update README + - Add Rubocop config + - Break support for Ruby < 2 +- Added support for InfluxDB 0.9+ (#92) + +## v0.1.9, released 2015-07-04 + +- last version to support InfluxDB 0.8.x diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/Gemfile b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/Gemfile new file mode 100644 index 0000000..8ec2bb9 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/Gemfile @@ -0,0 +1,14 @@ +source "https://rubygems.org" + +if RUBY_ENGINE != "jruby" && RUBY_VERSION < "2.0" + gem "json", "~> 1.8.3" + gem "public_suffix", "< 1.5" +end + +gemspec + +local_gemfile = 'Gemfile.local' + +if File.exist?(local_gemfile) + eval(File.read(local_gemfile)) # rubocop:disable Lint/Eval +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/LICENSE.txt b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/LICENSE.txt new file mode 100644 index 0000000..7c471a7 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/LICENSE.txt @@ -0,0 +1,22 @@ +Copyright (c) 2013 Todd Persen + +MIT License + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/README.md b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/README.md new file mode 100644 index 0000000..9ed858f --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/README.md @@ -0,0 +1,687 @@ +# influxdb-ruby + +[![Build Status](https://travis-ci.org/influxdata/influxdb-ruby.svg?branch=master)](https://travis-ci.org/influxdata/influxdb-ruby) + +The official Ruby client library for [InfluxDB](https://influxdata.com/time-series-platform/influxdb/). +Maintained by [@toddboom](https://github.com/toddboom) and [@dmke](https://github.com/dmke). + +## Contents + +- [Platform support](#platform-support) +- [Ruby support](#ruby-support) +- [Installation](#installation) +- [Usage](#usage) + - [Creating a client](#creating-a-client) + - [Administrative tasks](#administrative-tasks) + - [Continuous queries](#continuous-queries) + - [Retention policies](#retention-policies) + - [Writing data](#writing-data) + - [Reading data](#reading-data) + - [Querying](#querying) + - [De-normalization](#de--normalization) + - [Streaming response](#streaming-response) + - [Retry](#retry) + - [Testing](#testing) + - [Contributing](#contributing) + +## Platform support + +> **Support for InfluxDB v0.8.x is now deprecated**. The final version of this +> library that will support the older InfluxDB interface is `v0.1.9`, which is +> available as a gem and tagged on this repository. +> +> If you're reading this message, then you should only expect support for +> InfluxDB v0.9.1 and higher. + +## Ruby support + +This gem should work with Ruby 1.9+, but starting with v0.4, we'll likely drop +Ruby 1.9 support. + +Please note that for Ruby 1.9, you'll need to install the JSON gem in version +1.8.x yourself, for example by pinning the version in your `Gemfile` (i.e. +`gem "json", "~> 1.8.3"`). + +## Installation + +``` +$ [sudo] gem install influxdb +``` + +Or add it to your `Gemfile`, and run `bundle install`. + +## Usage + +### Creating a client + +Connecting to a single host: + +``` ruby +require 'influxdb' + +influxdb = InfluxDB::Client.new host: "influxdb.domain.com" +# or +influxdb = InfluxDB::Client.new # no host given defaults connecting to localhost +``` + +Connecting to multiple hosts (with built-in load balancing and failover): + +``` ruby +require 'influxdb' + +influxdb = InfluxDB::Client.new hosts: ["influxdb1.domain.com", "influxdb2.domain.com"] +``` + +### Administrative tasks + +Create a database: + +``` ruby +database = 'site_development' + +influxdb.create_database(database) +``` + +Delete a database: + +``` ruby +database = 'site_development' + +influxdb.delete_database(database) +``` + +List databases: + +``` ruby +influxdb.list_databases +``` + +Create a user for a database: + +``` ruby +database = 'site_development' +new_username = 'foo' +new_password = 'bar' +permission = :write + +# with all permissions +influxdb.create_database_user(database, new_username, new_password) + +# with specified permission - options are: :read, :write, :all +influxdb.create_database_user(database, new_username, new_password, permissions: permission) +``` + +Update a user password: + +``` ruby +username = 'foo' +new_password = 'bar' + +influxdb.update_user_password(username, new_password) +``` + +Grant user privileges on database: + +``` ruby +username = 'foobar' +database = 'foo' +permission = :read # options are :read, :write, :all + +influxdb.grant_user_privileges(username, database, permission) +``` + +Revoke user privileges from database: + +``` ruby +username = 'foobar' +database = 'foo' +permission = :write # options are :read, :write, :all + +influxdb.revoke_user_privileges(username, database, permission) +``` +Delete a user: + +``` ruby +username = 'foobar' + +influxdb.delete_user(username) +``` + +List users: + +``` ruby +influxdb.list_users +``` + +Create cluster admin: + +``` ruby +username = 'foobar' +password = 'pwd' + +influxdb.create_cluster_admin(username, password) +``` + +List cluster admins: + +``` ruby +influxdb.list_cluster_admins +``` + +Revoke cluster admin privileges from user: + +``` ruby +username = 'foobar' + +influxdb.revoke_cluster_admin_privileges(username) +``` + +### Continuous Queries + +List continuous queries of a database: + +``` ruby +database = 'foo' + +influxdb.list_continuous_queries(database) +``` + +Create a continuous query for a database: + +``` ruby +database = 'foo' +name = 'clicks_count' +query = 'SELECT COUNT(name) INTO clicksCount_1h FROM clicks GROUP BY time(1h)' + +influxdb.create_continuous_query(name, database, query) +``` + +Additionally, you can specify the resample interval and the time range over +which the CQ runs: + +``` ruby +influxdb.create_continuous_query(name, database, query, resample_every: "10m", resample_for: "65m") +``` + +Delete a continuous query from a database: + +``` ruby +database = 'foo' +name = 'clicks_count' + +influxdb.delete_continuous_query(name, database) +``` + +### Retention Policies + +List retention policies of a database: + +``` ruby +database = 'foo' + +influxdb.list_retention_policies(database) +``` + +Create a retention policy for a database: + +``` ruby +database = 'foo' +name = '1h.cpu' +duration = '10m' +replication = 2 + +influxdb.create_retention_policy(name, database, duration, replication) +``` + +Delete a retention policy from a database: + +``` ruby +database = 'foo' +name = '1h.cpu' + +influxdb.delete_retention_policy(name, database) +``` + +Alter a retention policy for a database: + +``` ruby +database = 'foo' +name = '1h.cpu' +duration = '10m' +replication = 2 + +influxdb.alter_retention_policy(name, database, duration, replication) +``` + +### Writing data + +Write some data: + +``` ruby +username = 'foo' +password = 'bar' +database = 'site_development' +name = 'foobar' + +influxdb = InfluxDB::Client.new database, username: username, password: password + +# Enumerator that emits a sine wave +Value = (0..360).to_a.map {|i| Math.send(:sin, i / 10.0) * 10 }.each + +loop do + data = { + values: { value: Value.next }, + tags: { wave: 'sine' } # tags are optional + } + + influxdb.write_point(name, data) + + sleep 1 +end +``` + +Write data with time precision (precision can be set in 2 ways): + +``` ruby +require 'influxdb' + +username = 'foo' +password = 'bar' +database = 'site_development' +name = 'foobar' +time_precision = 's' + +# either in the client initialization: +influxdb = InfluxDB::Client.new database, + username: username, + password: password, + time_precision: time_precision + +data = { + values: { value: 0 }, + timestamp: Time.now.to_i # timestamp is optional, if not provided point will be saved with current time +} + +influxdb.write_point(name, data) + +# or in a method call: +influxdb.write_point(name, data, time_precision) + +``` + +Write data with a specific retention policy: + +``` ruby +require 'influxdb' + +username = 'foo' +password = 'bar' +database = 'site_development' +name = 'foobar' +precision = 's' +retention = '1h.cpu' + +influxdb = InfluxDB::Client.new database, + username: username, + password: password + +data = { + values: { value: 0 }, + tags: { foo: 'bar', bar: 'baz' } + timestamp: Time.now.to_i +} + +influxdb.write_point(name, data, precision, retention) +``` + +Write data while choosing the database: + +``` ruby +require 'influxdb' + +username = 'foo' +password = 'bar' +database = 'site_development' +name = 'foobar' +precision = 's' +retention = '1h.cpu' + +influxdb = InfluxDB::Client.new { + username: username, + password: password +} + +data = { + values: { value: 0 }, + tags: { foo: 'bar', bar: 'baz' } + timestamp: Time.now.to_i +} + +influxdb.write_point(name, data, precision, retention, database) +``` + +Write multiple points in a batch (performance boost): + +``` ruby + +data = [ + { + series: 'cpu', + tags: { host: 'server_1', region: 'us' }, + values: { internal: 5, external: 0.453345 } + }, + { + series: 'gpu', + values: { value: 0.9999 }, + } +] + +influxdb.write_points(data) + +# you can also specify precision in method call + +precision = 'm' +influxdb.write_points(data, precision) +``` + +Write multiple points in a batch with a specific retention policy: + +``` ruby +data = [ + { + series: 'cpu', + tags: { host: 'server_1', region: 'us' }, + values: { internal: 5, external: 0.453345 } + }, + { + series: 'gpu', + values: { value: 0.9999 }, + } +] + +precision = 'm' +retention = '1h.cpu' +influxdb.write_points(data, precision, retention) + +``` + +Write asynchronously (note that a retention policy cannot be specified for asynchronous writes): + +``` ruby +require 'influxdb' + +username = 'foo' +password = 'bar' +database = 'site_development' +name = 'foobar' + +influxdb = InfluxDB::Client.new database, + username: username, + password: password, + async: true + +data = { + values: { value: 0 }, + tags: { foo: 'bar', bar: 'baz' }, + timestamp: Time.now.to_i +} + +influxdb.write_point(name, data) +``` + +Using `async: true` is a shortcut for the following: + +``` ruby +async_options = { + # number of points to write to the server at once + max_post_points: 1000, + # queue capacity + max_queue_size: 10_000, + # number of threads + num_worker_threads: 3, + # max. time (in seconds) a thread sleeps before + # checking if there are new jobs in the queue + sleep_interval: 5 +} + +influxdb = InfluxDB::Client.new database, + username: username, + password: password, + async: async_options +``` + + +Write data via UDP (note that a retention policy cannot be specified for UDP writes): + +``` ruby +require 'influxdb' +host = '127.0.0.1' +port = 4444 + +influxdb = InfluxDB::Client.new udp: { host: host, port: port } + +name = 'hitchhiker' + +data = { + values: { value: 666 }, + tags: { foo: 'bar', bar: 'baz' } +} + +influxdb.write_point(name, data) +``` + +### Reading data + +#### Querying + +``` ruby +username = 'foo' +password = 'bar' +database = 'site_development' + +influxdb = InfluxDB::Client.new database, + username: username, + password: password + +# without a block: +influxdb.query 'select * from time_series_1 group by region' + +# results are grouped by name, but also their tags: +# +# [ +# { +# "name"=>"time_series_1", +# "tags"=>{"region"=>"uk"}, +# "values"=>[ +# {"time"=>"2015-07-09T09:03:31Z", "count"=>32, "value"=>0.9673}, +# {"time"=>"2015-07-09T09:03:49Z", "count"=>122, "value"=>0.4444} +# ] +# }, +# { +# "name"=>"time_series_1", +# "tags"=>{"region"=>"us"}, +# "values"=>[ +# {"time"=>"2015-07-09T09:02:54Z", "count"=>55, "value"=>0.4343} +# ] +# } +# ] + +# with a block: +influxdb.query 'select * from time_series_1 group by region' do |name, tags, points| + puts "#{name} [ #{tags.inspect} ]" + points.each do |pt| + puts " -> #{pt.inspect}" + end +end + +# result: +# time_series_1 [ {"region"=>"uk"} ] +# -> {"time"=>"2015-07-09T09:03:31Z", "count"=>32, "value"=>0.9673} +# -> {"time"=>"2015-07-09T09:03:49Z", "count"=>122, "value"=>0.4444}] +# time_series_1 [ {"region"=>"us"} ] +# -> {"time"=>"2015-07-09T09:02:54Z", "count"=>55, "value"=>0.4343} +``` + +If you would rather receive points with integer timestamp, it's possible to set +`epoch` parameter: + +``` ruby +# globally, on client initialization: +influxdb = InfluxDB::Client.new database, epoch: 's' + +influxdb.query 'select * from time_series group by region' +# [ +# { +# "name"=>"time_series", +# "tags"=>{"region"=>"uk"}, +# "values"=>[ +# {"time"=>1438411376, "count"=>32, "value"=>0.9673} +# ] +# } +# ] + +# or for a specific query call: +influxdb.query 'select * from time_series group by region', epoch: 'ms' +# [ +# { +# "name"=>"time_series", +# "tags"=>{"region"=>"uk"}, +# "values"=>[ +# {"time"=>1438411376000, "count"=>32, "value"=>0.9673} +# ] +# } +# ] +``` + +Working with parameterized query strings works as expected: + +``` ruby +influxdb = InfluxDB::Client.new database + +named_parameter_query = "select * from time_series_0 where time > %{min_time}" +influxdb.query named_parameter_query, params: { min_time: 0 } +# compiles to: +# select * from time_series_0 where time > 0 + +positional_params_query = "select * from time_series_0 where f = %{1} and i < %{2}" +influxdb.query positional_params_query, params: ["foobar", 42] +# compiles to (note the automatic escaping): +# select * from time_series_0 where f = 'foobar' and i < 42 +``` + + +#### (De-) Normalization + +By default, InfluxDB::Client will denormalize points (received from InfluxDB as +columns and rows). If you want to get *raw* data add `denormalize: false` to +the initialization options or to query itself: + +``` ruby +influxdb.query 'select * from time_series_1 group by region', denormalize: false + +# [ +# { +# "name"=>"time_series_1", +# "tags"=>{"region"=>"uk"}, +# "columns"=>["time", "count", "value"], +# "values"=>[ +# ["2015-07-09T09:03:31Z", 32, 0.9673], +# ["2015-07-09T09:03:49Z", 122, 0.4444] +# ] +# }, +# { +# "name"=>"time_series_1", +# "tags"=>{"region"=>"us"}, +# "columns"=>["time", "count", "value"], +# "values"=>[ +# ["2015-07-09T09:02:54Z", 55, 0.4343] +# ] +# } +# ] + + +influxdb.query 'select * from time_series_1 group by region', denormalize: false do |name, tags, points| + puts "#{name} [ #{tags.inspect} ]" + points.each do |key, values| + puts " #{key.inspect} -> #{values.inspect}" + end +end + + +# time_series_1 [ {"region"=>"uk"} ] +# columns -> ["time", "count", "value"] +# values -> [["2015-07-09T09:03:31Z", 32, 0.9673], ["2015-07-09T09:03:49Z", 122, 0.4444]]} +# time_series_1 [ {"region"=>"us"} ] +# columns -> ["time", "count", "value"] +# values -> [["2015-07-09T09:02:54Z", 55, 0.4343]]} +``` + +You can also pick the database to query from: + +``` +influxdb.query 'select * from time_series_1', database: 'database' +``` + +#### Streaming response + +If you expect large quantities of data in a response, you may want to enable +JSON streaming by setting a `chunk_size`: + +``` ruby +influxdb = InfluxDB::Client.new database, + username: username, + password: password, + chunk_size: 10000 +``` + +See the [official documentation](http://docs.influxdata.com/influxdb/v0.13/guides/querying_data/#chunking) +for more details. + + +#### Retry + +By default, InfluxDB::Client will keep trying (with exponential fall-off) to +connect to the database until it gets a connection. If you want to retry only +a finite number of times (or disable retries altogether), you can pass the +`:retry` option. + +`:retry` can be either `true`, `false` or an `Integer` to retry infinite times, +disable retries or retry a finite number of times, respectively. Passing `0` is +equivalent to `false` and `-1` is equivalent to `true`. + +``` +$ irb -r influxdb +> influxdb = InfluxDB::Client.new 'database', retry: 8 +=> # + +> influxdb.query 'select * from serie limit 1' +E, [2016-08-31T23:55:18.287947 #23476] ERROR -- InfluxDB: Failed to contact host localhost: # - retrying in 0.01s. +E, [2016-08-31T23:55:18.298455 #23476] ERROR -- InfluxDB: Failed to contact host localhost: # - retrying in 0.02s. +E, [2016-08-31T23:55:18.319122 #23476] ERROR -- InfluxDB: Failed to contact host localhost: # - retrying in 0.04s. +E, [2016-08-31T23:55:18.359785 #23476] ERROR -- InfluxDB: Failed to contact host localhost: # - retrying in 0.08s. +E, [2016-08-31T23:55:18.440422 #23476] ERROR -- InfluxDB: Failed to contact host localhost: # - retrying in 0.16s. +E, [2016-08-31T23:55:18.600936 #23476] ERROR -- InfluxDB: Failed to contact host localhost: # - retrying in 0.32s. +E, [2016-08-31T23:55:18.921740 #23476] ERROR -- InfluxDB: Failed to contact host localhost: # - retrying in 0.64s. +E, [2016-08-31T23:55:19.562428 #23476] ERROR -- InfluxDB: Failed to contact host localhost: # - retrying in 1.28s. +InfluxDB::ConnectionError: Tried 8 times to reconnect but failed. +``` + +## Testing + +``` +git clone git@github.com:influxdata/influxdb-ruby.git +cd influxdb-ruby +bundle +bundle exec rake +``` + +## Contributing + +- Fork this repository on GitHub. +- Make your changes. + - Add tests. + - Add an entry in the `CHANGELOG.md` in the "unreleased" section on top. +- Run the tests: `bundle exec rake`. +- Send a pull request. + - Please rebase against the master branch. +- If your changes look good, we'll merge them. diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/Rakefile b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/Rakefile new file mode 100644 index 0000000..712881f --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/Rakefile @@ -0,0 +1,51 @@ +require "rake/testtask" +require "bundler/gem_tasks" +require "rubocop/rake_task" + +RuboCop::RakeTask.new + +targeted_files = ARGV.drop(1) +file_pattern = targeted_files.empty? ? "spec/**/*_spec.rb" : targeted_files + +require "rspec/core" +require "rspec/core/rake_task" + +RSpec::Core::RakeTask.new(:spec) do |t| + t.pattern = FileList[file_pattern] +end + +Rake::TestTask.new(:smoke) do |t| + t.test_files = FileList["smoke/*.rb"] +end + +task default: [:spec, :rubocop] + +task :console do + lib = File.expand_path("../lib", __FILE__) + $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) + require "influxdb" + + begin + require "pry-byebug" + Pry.start + rescue LoadError + puts <<-TEXT.gsub(/^\s{6}([^ ])/, "\1"), "" + Could not load pry-byebug. Create a file Gemfile.local with + the following line, if you want to get rid of this message: + + \tgem "pry-byebug" + + (don't forget to run bundle afterwards). Falling back to IRB. + TEXT + + require "irb" + ARGV.clear + IRB.start + end +end + +if !ENV.key?("influx_version") || ENV["influx_version"] == "" + task default: :spec +elsif ENV["TRAVIS"] == "true" + task default: :smoke +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/influxdb.gemspec b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/influxdb.gemspec new file mode 100644 index 0000000..13bde9f --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/influxdb.gemspec @@ -0,0 +1,30 @@ +# coding: utf-8 +lib = File.expand_path('../lib', __FILE__) +$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) +require 'influxdb/version' + +# rubocop:disable Style/SpecialGlobalVars +Gem::Specification.new do |spec| + spec.name = "influxdb" + spec.version = InfluxDB::VERSION + spec.authors = ["Todd Persen"] + spec.email = ["influxdb@googlegroups.com"] + spec.description = "This is the official Ruby library for InfluxDB." + spec.summary = "Ruby library for InfluxDB." + spec.homepage = "http://influxdb.org" + spec.license = "MIT" + + spec.files = `git ls-files`.split($/) + spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } + spec.test_files = spec.files.grep(%r{^(test|spec|features|smoke)/}) + spec.require_paths = ["lib"] + + spec.add_runtime_dependency "json" + spec.add_runtime_dependency "cause" + + spec.add_development_dependency "rake" + spec.add_development_dependency "bundler", "~> 1.3" + spec.add_development_dependency "rspec", "~> 3.5.0" + spec.add_development_dependency "webmock", "~> 2.1.0" + spec.add_development_dependency "rubocop", "~> 0.41.2" +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb.rb new file mode 100644 index 0000000..f2594f0 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb.rb @@ -0,0 +1,19 @@ +require "influxdb/version" +require "influxdb/errors" +require "influxdb/logging" +require "influxdb/max_queue" +require "influxdb/point_value" +require "influxdb/config" + +require "influxdb/writer/async" +require "influxdb/writer/udp" + +require "influxdb/query/core" +require "influxdb/query/cluster" +require "influxdb/query/database" +require "influxdb/query/user" +require "influxdb/query/continuous_query" +require "influxdb/query/retention_policy" + +require "influxdb/client/http" +require "influxdb/client" diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/client.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/client.rb new file mode 100644 index 0000000..1a4eff0 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/client.rb @@ -0,0 +1,82 @@ +require 'json' +require 'cause' unless Exception.instance_methods.include?(:cause) +require 'thread' + +module InfluxDB + # InfluxDB client class + class Client + attr_reader :config, :writer + + include InfluxDB::Logging + include InfluxDB::HTTP + include InfluxDB::Query::Core + include InfluxDB::Query::Cluster + include InfluxDB::Query::Database + include InfluxDB::Query::User + include InfluxDB::Query::ContinuousQuery + include InfluxDB::Query::RetentionPolicy + + # Initializes a new InfluxDB client + # + # === Examples: + # + # # connect to localhost using root/root + # # as the credentials and doesn't connect to a db + # + # InfluxDB::Client.new + # + # # connect to localhost using root/root + # # as the credentials and 'db' as the db name + # + # InfluxDB::Client.new 'db' + # + # # override username, other defaults remain unchanged + # + # InfluxDB::Client.new username: 'username' + # + # # override username, use 'db' as the db name + # Influxdb::Client.new 'db', username: 'username' + # + # === Valid options in hash + # + # +:host+:: the hostname to connect to + # +:port+:: the port to connect to + # +:prefix+:: the specified path prefix when building the url e.g.: /prefix/db/dbname... + # +:username+:: the username to use when executing commands + # +:password+:: the password associated with the username + # +:use_ssl+:: use ssl to connect + # +:verify_ssl+:: verify ssl server certificate? + # +:ssl_ca_cert+:: ssl CA certificate, chainfile or CA path. + # The system CA path is automatically included + def initialize(*args) + opts = args.last.is_a?(Hash) ? args.last : {} + opts[:database] = args.first if args.first.is_a? String + @config = InfluxDB::Config.new(opts) + @stopped = false + @writer = find_writer + + at_exit { stop! } if config.retry > 0 + end + + def stop! + writer.worker.stop! if config.async? + @stopped = true + end + + def stopped? + @stopped + end + + private + + def find_writer + if config.async? + InfluxDB::Writer::Async.new(self, config.async) + elsif config.udp? + InfluxDB::Writer::UDP.new(self, config.udp) + else + self + end + end + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/client/http.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/client/http.rb new file mode 100644 index 0000000..bbf0f56 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/client/http.rb @@ -0,0 +1,134 @@ +require 'uri' +require 'cgi' +require 'net/http' +require 'net/https' + +module InfluxDB + # rubocop:disable Metrics/MethodLength + # rubocop:disable Metrics/AbcSize + module HTTP # :nodoc: + def get(url, options = {}) + connect_with_retry do |http| + response = do_request http, Net::HTTP::Get.new(url) + case response + when Net::HTTPSuccess + handle_successful_response(response, options) + when Net::HTTPUnauthorized + raise InfluxDB::AuthenticationError, response.body + else + resolve_error(response.body) + end + end + end + + def post(url, data) + headers = { "Content-Type" => "application/octet-stream" } + connect_with_retry do |http| + response = do_request http, Net::HTTP::Post.new(url, headers), data + + case response + when Net::HTTPNoContent + return response + when Net::HTTPUnauthorized + raise InfluxDB::AuthenticationError, response.body + else + resolve_error(response.body) + end + end + end + + private + + def connect_with_retry + host = config.next_host + delay = config.initial_delay + retry_count = 0 + + begin + http = Net::HTTP.new(host, config.port) + http.open_timeout = config.open_timeout + http.read_timeout = config.read_timeout + + http = setup_ssl(http) + yield http + + rescue *InfluxDB::NON_RECOVERABLE_EXCEPTIONS => e + raise InfluxDB::ConnectionError, InfluxDB::NON_RECOVERABLE_MESSAGE + rescue Timeout::Error, *InfluxDB::RECOVERABLE_EXCEPTIONS => e + retry_count += 1 + unless (config.retry == -1 || retry_count <= config.retry) && !stopped? + raise InfluxDB::ConnectionError, "Tried #{retry_count - 1} times to reconnect but failed." + end + log :error, "Failed to contact host #{host}: #{e.inspect} - retrying in #{delay}s." + sleep delay + delay = [config.max_delay, delay * 2].min + retry + ensure + http.finish if http.started? + end + end + + def do_request(http, req, data = nil) + req.basic_auth config.username, config.password if basic_auth? + req.body = data if data + http.request(req) + end + + def basic_auth? + config.auth_method == 'basic_auth' + end + + def resolve_error(response) + if response =~ /Couldn\'t find series/ + raise InfluxDB::SeriesNotFound, response + end + raise InfluxDB::Error, response + end + + def handle_successful_response(response, options) + if options.fetch(:json_streaming, false) + parsed_response = response.body.each_line.with_object({}) do |line, parsed| + parsed.merge!(JSON.parse(line)) { |_key, oldval, newval| oldval + newval } + end + elsif response.body + parsed_response = JSON.parse(response.body) + end + + errors = errors_from_response(parsed_response) + + raise InfluxDB::QueryError, errors if errors + options.fetch(:parse, false) ? parsed_response : response + end + + def errors_from_response(parsed_resp) + return unless parsed_resp.is_a?(Hash) + parsed_resp + .fetch('results', []) + .fetch(0, {}) + .fetch('error', nil) + end + + def setup_ssl(http) + http.use_ssl = config.use_ssl + http.verify_mode = OpenSSL::SSL::VERIFY_NONE unless config.verify_ssl + + return http unless config.use_ssl + + http.cert_store = generate_cert_store + http + end + + def generate_cert_store + store = OpenSSL::X509::Store.new + store.set_default_paths + if config.ssl_ca_cert + if File.directory?(config.ssl_ca_cert) + store.add_path(config.ssl_ca_cert) + else + store.add_file(config.ssl_ca_cert) + end + end + store + end + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/config.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/config.rb new file mode 100644 index 0000000..b40a629 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/config.rb @@ -0,0 +1,120 @@ +require 'thread' + +module InfluxDB + # InfluxDB client configuration + class Config + AUTH_METHODS = ["params".freeze, "basic_auth".freeze, "none".freeze].freeze + + attr_accessor :port, + :username, + :password, + :database, + :time_precision, + :use_ssl, + :verify_ssl, + :ssl_ca_cert, + :auth_method, + :initial_delay, + :max_delay, + :open_timeout, + :read_timeout, + :retry, + :prefix, + :chunk_size, + :denormalize, + :epoch + + attr_reader :async, :udp + + def initialize(opts = {}) + extract_http_options!(opts) + extract_ssl_options!(opts) + extract_database_options!(opts) + extract_writer_options!(opts) + extract_query_options!(opts) + + configure_retry! opts.fetch(:retry, nil) + configure_hosts! opts[:hosts] || opts[:host] || "localhost".freeze + end + + def udp? + udp != false + end + + def async? + async != false + end + + def next_host + host = @hosts_queue.pop + @hosts_queue.push(host) + host + end + + def hosts + Array.new(@hosts_queue.length) do + host = @hosts_queue.pop + @hosts_queue.push(host) + host + end + end + + private + + # rubocop:disable Metrics/AbcSize + def extract_http_options!(opts) + @port = opts.fetch :port, 8086 + @prefix = opts.fetch :prefix, "".freeze + @username = opts.fetch :username, "root".freeze + @password = opts.fetch :password, "root".freeze + @open_timeout = opts.fetch :write_timeout, 5 + @read_timeout = opts.fetch :read_timeout, 300 + @max_delay = opts.fetch :max_delay, 30 + @initial_delay = opts.fetch :initial_delay, 0.01 + auth = opts[:auth_method] + @auth_method = AUTH_METHODS.include?(auth) ? auth : "params".freeze + end + + def extract_ssl_options!(opts) + @use_ssl = opts.fetch :use_ssl, false + @verify_ssl = opts.fetch :verify_ssl, true + @ssl_ca_cert = opts.fetch :ssl_ca_cert, false + end + + # normalize retry option + def configure_retry!(value) + case value + when Integer + @retry = value + when true, nil + @retry = -1 + when false + @retry = 0 + end + end + + # load the hosts into a Queue for thread safety + def configure_hosts!(hosts) + @hosts_queue = Queue.new + Array(hosts).each do |host| + @hosts_queue.push(host) + end + end + + def extract_database_options!(opts) + @database = opts[:database] + @time_precision = opts.fetch :time_precision, "s".freeze + @denormalize = opts.fetch :denormalize, true + @epoch = opts.fetch :epoch, false + end + + def extract_writer_options!(opts) + @async = opts.fetch :async, false + @udp = opts.fetch :udp, false + end + + def extract_query_options!(opts) + @chunk_size = opts.fetch :chunk_size, nil + end + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/errors.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/errors.rb new file mode 100644 index 0000000..a5f95bb --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/errors.rb @@ -0,0 +1,52 @@ +require "net/http" +require "zlib" + +module InfluxDB # :nodoc: + class Error < StandardError + end + + class AuthenticationError < Error + end + + class ConnectionError < Error + end + + class SeriesNotFound < Error + end + + class JSONParserError < Error + end + + class QueryError < Error + end + + # When executing queries via HTTP, some errors can more or less safely + # be ignored and we can retry the query again. This following + # exception classes shall be deemed as "safe". + # + # Taken from: https://github.com/lostisland/faraday/blob/master/lib/faraday/adapter/net_http.rb + RECOVERABLE_EXCEPTIONS = [ + Errno::ECONNABORTED, + Errno::ECONNREFUSED, + Errno::ECONNRESET, + Errno::EHOSTUNREACH, + Errno::EINVAL, + Errno::ENETUNREACH, + Net::HTTPBadResponse, + Net::HTTPHeaderSyntaxError, + Net::ProtocolError, + SocketError, + (OpenSSL::SSL::SSLError if defined?(OpenSSL)) + ].compact.freeze + + # Exception classes which hint to a larger problem on the server side, + # like insuffient resources. If we encouter on of the following, wo + # _don't_ retry a query but escalate it upwards. + NON_RECOVERABLE_EXCEPTIONS = [ + EOFError, + Zlib::Error + ].freeze + + NON_RECOVERABLE_MESSAGE = "The server has sent incomplete data" \ + " (insufficient resources are a possible cause).".freeze +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/logging.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/logging.rb new file mode 100644 index 0000000..7ac1767 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/logging.rb @@ -0,0 +1,23 @@ +require 'logger' + +module InfluxDB + module Logging # :nodoc: + PREFIX = "InfluxDB".freeze + + class << self + attr_writer :logger + end + + def self.logger + return false if @logger == false + @logger ||= ::Logger.new(STDERR).tap { |logger| logger.level = Logger::INFO } + end + + private + + def log(level, message) + return unless InfluxDB::Logging.logger + InfluxDB::Logging.logger.send(level.to_sym, PREFIX) { message } + end + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/max_queue.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/max_queue.rb new file mode 100644 index 0000000..bbc33ec --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/max_queue.rb @@ -0,0 +1,18 @@ +require "thread" + +module InfluxDB + # Queue with max length limit + class MaxQueue < Queue + attr_reader :max + + def initialize(max = 10_000) + raise ArgumentError, "queue size must be positive" if max <= 0 + @max = max + super() + end + + def push(obj) + super if length < @max + end + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/point_value.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/point_value.rb new file mode 100644 index 0000000..08d3bf3 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/point_value.rb @@ -0,0 +1,77 @@ +module InfluxDB + # Convert data point to string using Line protocol + class PointValue + attr_reader :series, :values, :tags, :timestamp + + def initialize(data) + @series = escape data[:series], :measurement + @values = escape_values data[:values] + @tags = escape_tags data[:tags] + + @timestamp = data[:timestamp] + end + + def dump + dump = @series.dup + dump << ",#{@tags}" if @tags + dump << " #{@values}" + dump << " #{@timestamp}" if @timestamp + dump + end + + private + + ESCAPES = { + measurement: [' '.freeze, ','.freeze], + tag_key: ['='.freeze, ' '.freeze, ','.freeze], + tag_value: ['='.freeze, ' '.freeze, ','.freeze], + field_key: ['='.freeze, ' '.freeze, ','.freeze, '"'.freeze], + field_value: ['"'.freeze] + }.freeze + + def escape(s, type) + # rubocop:disable Style/AlignParameters + s = s.encode "UTF-8".freeze, "UTF-8".freeze, + invalid: :replace, + undef: :replace, + replace: "".freeze + + ESCAPES[type].each do |ch| + s = s.gsub(ch) { "\\#{ch}" } + end + s + end + + def escape_values(values) + return if values.nil? + values.map do |k, v| + key = escape(k.to_s, :field_key) + val = escape_value(v) + "#{key}=#{val}" + end.join(",") + end + + def escape_value(value) + if value.is_a?(String) + '"' + escape(value, :field_value) + '"' + elsif value.is_a?(Integer) + "#{value}i" + else + value.to_s + end + end + + def escape_tags(tags) + return if tags.nil? + + tags = tags.map do |k, v| + key = escape(k.to_s, :tag_key) + val = escape(v.to_s, :tag_value) + + "#{key}=#{val}" unless key == "" || val == "" + end.compact + + tags.join(",") unless tags.empty? + end + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/query/builder.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/query/builder.rb new file mode 100644 index 0000000..36dd550 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/query/builder.rb @@ -0,0 +1,44 @@ +module InfluxDB + module Query # :nodoc: all + class Builder + def build(query, params) + case params + when Array then params = params_from_array(params) + when Hash then params = params_from_hash(params) + when NilClass then params = {} + else raise ArgumentError, "Unsupported #{params.class} params" + end + + query % params + + rescue KeyError => e + raise ArgumentError, e.message + end + + def quote(param) + case param + when String, Symbol + "'" + param.to_s.gsub(/['"\\\x0]/, '\\\\\0') + "'" + when Integer, Float, TrueClass, FalseClass + param.to_s + else + raise ArgumentError, "Unexpected parameter type #{param.class} (#{param.inspect})" + end + end + + private + + def params_from_hash(params) + params.each_with_object({}) do |(k, v), hash| + hash[k.to_sym] = quote(v) + end + end + + def params_from_array(params) + params.each_with_object({}).with_index do |(param, hash), i| + hash[(i + 1).to_s.to_sym] = quote(param) + end + end + end + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/query/cluster.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/query/cluster.rb new file mode 100644 index 0000000..e230a15 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/query/cluster.rb @@ -0,0 +1,17 @@ +module InfluxDB + module Query + module Cluster # :nodoc: + def create_cluster_admin(username, password) + execute("CREATE USER #{username} WITH PASSWORD '#{password}' WITH ALL PRIVILEGES") + end + + def list_cluster_admins + list_users.select { |u| u['admin'] }.map { |u| u['username'] } + end + + def revoke_cluster_admin_privileges(username) + execute("REVOKE ALL PRIVILEGES FROM #{username}") + end + end + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/query/continuous_query.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/query/continuous_query.rb new file mode 100644 index 0000000..ae6e1fb --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/query/continuous_query.rb @@ -0,0 +1,31 @@ +module InfluxDB + module Query + module ContinuousQuery # :nodoc: + def list_continuous_queries(database) + resp = execute("SHOW CONTINUOUS QUERIES", parse: true) + fetch_series(resp) + .select { |v| v['name'] == database } + .fetch(0, {}) + .fetch('values', []) + .map { |v| { 'name' => v.first, 'query' => v.last } } + end + + def create_continuous_query(name, database, query, options = {}) + clause = ["CREATE CONTINUOUS QUERY", name, "ON", database] + + if options[:resample_every] || options[:resample_for] + clause << "RESAMPLE" + clause << "EVERY #{options[:resample_every]}" if options[:resample_every] + clause << "FOR #{options[:resample_for]}" if options[:resample_for] + end + + clause = clause.join(" ") << " BEGIN\n" << query << "\nEND" + execute(clause) + end + + def delete_continuous_query(name, database) + execute("DROP CONTINUOUS QUERY #{name} ON #{database}") + end + end + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/query/core.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/query/core.rb new file mode 100644 index 0000000..37cc29a --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/query/core.rb @@ -0,0 +1,149 @@ +require_relative 'builder' + +module InfluxDB + module Query # :nodoc: all + # rubocop:disable Metrics/AbcSize + module Core + def builder + @builder ||= Builder.new + end + + def ping + url = URI::Generic.build(path: File.join(config.prefix, '/ping')).to_s + get url + end + + def version + ping.header['x-influxdb-version'] + end + + # rubocop:disable Metrics/MethodLength + def query(query, opts = {}) + query = builder.build(query, opts[:params]) + denormalize = opts.fetch(:denormalize, config.denormalize) + json_streaming = !opts.fetch(:chunk_size, config.chunk_size).nil? + + params = query_params(query, opts) + url = full_url("/query".freeze, params) + series = fetch_series(get(url, parse: true, json_streaming: json_streaming)) + + if block_given? + series.each do |s| + values = denormalize ? denormalize_series(s) : raw_values(s) + yield s['name'.freeze], s['tags'.freeze], values + end + else + denormalize ? denormalized_series_list(series) : series + end + end + # rubocop:enable Metrics/MethodLength + + # Example: + # write_points([ + # { + # series: 'cpu', + # tags: { host: 'server_nl', regios: 'us' }, + # values: {internal: 5, external: 6}, + # timestamp: 1422568543702900257 + # }, + # { + # series: 'gpu', + # values: {value: 0.9999}, + # } + # ]) + def write_points(data, precision = nil, retention_policy = nil, database = nil) + data = data.is_a?(Array) ? data : [data] + payload = generate_payload(data) + writer.write(payload, precision, retention_policy, database) + end + + # Example: + # write_point('cpu', tags: {region: 'us'}, values: {internal: 60}) + def write_point(series, data, precision = nil, retention_policy = nil, database = nil) + write_points(data.merge(series: series), precision, retention_policy, database) + end + + def write(data, precision, retention_policy = nil, database = nil) + params = { + db: database || config.database, + precision: precision || config.time_precision + } + + params[:rp] = retention_policy if retention_policy + url = full_url("/write", params) + post(url, data) + end + + private + + # rubocop:disable Metrics/MethodLength + def query_params(query, opts) + precision = opts.fetch(:precision, config.time_precision) + epoch = opts.fetch(:epoch, config.epoch) + chunk_size = opts.fetch(:chunk_size, config.chunk_size) + database = opts.fetch(:database, config.database) + + params = { q: query, db: database, precision: precision } + params[:epoch] = epoch if epoch + + if chunk_size + params[:chunked] = 'true' + params[:chunk_size] = chunk_size + end + + params + end + # rubocop:enable Metrics/MethodLength + + def denormalized_series_list(series) + series.map do |s| + { + "name" => s["name".freeze], + "tags" => s["tags".freeze], + "values" => denormalize_series(s) + } + end + end + + def fetch_series(response) + response.fetch('results'.freeze, []).flat_map do |result| + result.fetch('series'.freeze, []) + end + end + + def generate_payload(data) + data.map do |point| + InfluxDB::PointValue.new(point).dump + end.join("\n".freeze) + end + + def execute(query, options = {}) + url = full_url("/query", q: query) + get(url, options) + end + + def denormalize_series(series) + Array(series["values".freeze]).map do |values| + Hash[series["columns".freeze].zip(values)] + end + end + + def raw_values(series) + series.select { |k, _| %w(columns values).include?(k) } + end + + def full_url(path, params = {}) + if config.auth_method == "params".freeze + params[:u] = config.username + params[:p] = config.password + end + + query = params.map do |k, v| + [CGI.escape(k.to_s), "=".freeze, CGI.escape(v.to_s)].join + end.join("&".freeze) + + URI::Generic.build(path: File.join(config.prefix, path), query: query).to_s + end + end + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/query/database.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/query/database.rb new file mode 100644 index 0000000..284d7a5 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/query/database.rb @@ -0,0 +1,22 @@ +module InfluxDB + module Query + module Database # :nodoc: + def create_database(name = nil) + execute("CREATE DATABASE #{name || config.database}") + end + + def delete_database(name = nil) + execute("DROP DATABASE #{name || config.database}") + end + + def list_databases + resp = execute("SHOW DATABASES".freeze, parse: true) + fetch_series(resp) + .fetch(0, {}) + .fetch('values', []) + .flatten + .map { |v| { 'name' => v } } + end + end + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/query/retention_policy.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/query/retention_policy.rb new file mode 100644 index 0000000..37e3845 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/query/retention_policy.rb @@ -0,0 +1,34 @@ +module InfluxDB + module Query + module RetentionPolicy # :nodoc: + def create_retention_policy(name, database, duration, replication, default = false) + execute( + "CREATE RETENTION POLICY \"#{name}\" ON #{database} " \ + "DURATION #{duration} REPLICATION #{replication}#{default ? ' DEFAULT' : ''}" + ) + end + + def list_retention_policies(database) + resp = execute("SHOW RETENTION POLICIES ON \"#{database}\"", parse: true) + data = fetch_series(resp).fetch(0) + + data['values'.freeze].map do |policy| + policy.each.with_index.inject({}) do |hash, (value, index)| + hash.tap { |h| h[data['columns'.freeze][index]] = value } + end + end + end + + def delete_retention_policy(name, database) + execute("DROP RETENTION POLICY \"#{name}\" ON #{database}") + end + + def alter_retention_policy(name, database, duration, replication, default = false) + execute( + "ALTER RETENTION POLICY \"#{name}\" ON #{database} " \ + "DURATION #{duration} REPLICATION #{replication}#{default ? ' DEFAULT' : ''}" + ) + end + end + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/query/user.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/query/user.rb new file mode 100644 index 0000000..ced54a5 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/query/user.rb @@ -0,0 +1,51 @@ +module InfluxDB + module Query + module User # :nodoc: + # create_database_user('testdb', 'user', 'pass') - grants all privileges by default + # create_database_user('testdb', 'user', 'pass', permissions: :read) - use [:read|:write|:all] + def create_database_user(database, username, password, options = {}) + permissions = options.fetch(:permissions, :all) + execute( + "CREATE user #{username} WITH PASSWORD '#{password}'; "\ + "GRANT #{permissions.to_s.upcase} ON #{database} TO #{username}" + ) + end + + def update_user_password(username, password) + execute("SET PASSWORD FOR #{username} = '#{password}'") + end + + # permission => [:all] + def grant_user_admin_privileges(username) + execute("GRANT ALL PRIVILEGES TO #{username}") + end + + # permission => [:read|:write|:all] + def grant_user_privileges(username, database, permission) + execute("GRANT #{permission.to_s.upcase} ON #{database} TO #{username}") + end + + def list_user_grants(username) + execute("SHOW GRANTS FOR #{username}") + end + + # permission => [:read|:write|:all] + def revoke_user_privileges(username, database, permission) + execute("REVOKE #{permission.to_s.upcase} ON #{database} FROM #{username}") + end + + def delete_user(username) + execute("DROP USER #{username}") + end + + # => [{"username"=>"usr", "admin"=>true}, {"username"=>"justauser", "admin"=>false}] + def list_users + resp = execute("SHOW USERS".freeze, parse: true) + fetch_series(resp) + .fetch(0, {}) + .fetch('values'.freeze, []) + .map { |v| { 'username' => v.first, 'admin' => v.last } } + end + end + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/version.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/version.rb new file mode 100644 index 0000000..d4770b5 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/version.rb @@ -0,0 +1,3 @@ +module InfluxDB # :nodoc: + VERSION = "0.3.13".freeze +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/writer/async.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/writer/async.rb new file mode 100644 index 0000000..3edaa10 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/writer/async.rb @@ -0,0 +1,127 @@ +require 'thread' +require "net/http" +require "uri" + +module InfluxDB + module Writer # :nodoc: all + class Async + attr_reader :config, :client + + def initialize(client, config) + @client = client + @config = config + end + + def write(data, _precision = nil, _retention_policy = nil, _database = nil) + data = data.is_a?(Array) ? data : [data] + data.map { |p| worker.push(p) } + end + + WORKER_MUTEX = Mutex.new + def worker + return @worker if @worker + WORKER_MUTEX.synchronize do + # this return is necessary because the previous mutex holder + # might have already assigned the @worker + return @worker if @worker + @worker = Worker.new(client, config) + end + end + + class Worker + attr_reader :client, + :queue, + :threads, + :max_post_points, + :max_queue_size, + :num_worker_threads, + :sleep_interval + + include InfluxDB::Logging + + MAX_POST_POINTS = 1000 + MAX_QUEUE_SIZE = 10_000 + NUM_WORKER_THREADS = 3 + SLEEP_INTERVAL = 5 + + def initialize(client, config) + @client = client + config = config.is_a?(Hash) ? config : {} + + @max_post_points = config.fetch(:max_post_points, MAX_POST_POINTS) + @max_queue_size = config.fetch(:max_queue_size, MAX_QUEUE_SIZE) + @num_worker_threads = config.fetch(:num_worker_threads, NUM_WORKER_THREADS) + @sleep_interval = config.fetch(:sleep_interval, SLEEP_INTERVAL) + + @queue = InfluxDB::MaxQueue.new max_queue_size + + spawn_threads! + end + + def push(payload) + queue.push(payload) + end + + def current_threads + Thread.list.select { |t| t[:influxdb] == object_id } + end + + def current_thread_count + Thread.list.count { |t| t[:influxdb] == object_id } + end + + # rubocop:disable Metrics/CyclomaticComplexity + # rubocop:disable Metrics/MethodLength + # rubocop:disable Metrics/AbcSize + + def spawn_threads! + @threads = [] + num_worker_threads.times do |thread_num| + log :debug, "Spawning background worker thread #{thread_num}." + + @threads << Thread.new do + Thread.current[:influxdb] = object_id + + until client.stopped? + check_background_queue(thread_num) + sleep rand(sleep_interval) + end + + log :debug, "Exit background worker thread #{thread_num}." + end + end + end + + def check_background_queue(thread_num = 0) + log :debug, + "Checking background queue on thread #{thread_num} (#{current_thread_count} active)" + + loop do + data = [] + + while data.size < max_post_points && !queue.empty? + p = queue.pop(true) rescue next + data.push p + end + + return if data.empty? + + begin + log :debug, "Found data in the queue! (#{data.length} points)" + client.write(data.join("\n"), nil) + rescue => e + puts "Cannot write data: #{e.inspect}" + end + + break if queue.length > max_post_points + end + end + + def stop! + log :debug, "Thread exiting, flushing queue." + check_background_queue until queue.empty? + end + end + end + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/writer/udp.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/writer/udp.rb new file mode 100644 index 0000000..5ee9277 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/writer/udp.rb @@ -0,0 +1,21 @@ +module InfluxDB + module Writer + # Writes data to InfluxDB through UDP + class UDP + attr_accessor :socket + attr_reader :host, :port + def initialize(client, config) + @client = client + config = config.is_a?(Hash) ? config : {} + @host = config.fetch(:host, "localhost".freeze) + @port = config.fetch(:port, 4444) + self.socket = UDPSocket.new + socket.connect(host, port) + end + + def write(payload, _precision = nil, _retention_policy = nil, _database = nil) + socket.send(payload, 0) + end + end + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/smoke/connect-and-get-version.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/smoke/connect-and-get-version.rb new file mode 100644 index 0000000..27398c7 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/smoke/connect-and-get-version.rb @@ -0,0 +1,18 @@ +require "influxdb" + +puts __FILE__ +puts "\tThis file contains some sanity checks." +puts + +client = InfluxDB::Client.new \ + username: "test_user", + password: "resu_tset", + retry: 4 + +version = client.version + +if version + puts "Got version: #{version}" +else + raise "version is empty" +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/smoke/noaa-sample-data.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/smoke/noaa-sample-data.rb new file mode 100644 index 0000000..d3366d4 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/smoke/noaa-sample-data.rb @@ -0,0 +1,79 @@ +require "influxdb" + +puts __FILE__ +puts "\tThis is basically a test whether the examples in documented on" +puts "\thttp://docs.influxdata.com/influxdb/v0.13/sample_data/data_download/" +puts "\twork with the Ruby client." +puts + +client = InfluxDB::Client.new \ + database: "NOAA_water_database", + username: "test_user", + password: "resu_tset", + retry: 4 + +TestFailure = Class.new StandardError +TestAllowedFailure = Class.new StandardError + +def test_case(name) + print name + yield + puts " [ OK ]" + +rescue TestAllowedFailure + puts " [WARN]" + puts $!.message + +rescue TestFailure + puts " [FAIL]" + puts $!.message + exit 1 +end + +test_case "See all five measurements?" do + result = client.query "show measurements" + expected = %w[ average_temperature h2o_feet h2o_pH h2o_quality h2o_temperature ] + actual = result[0]["values"].map{|v| v["name"] } + unexpected = actual - expected + if unexpected.any? + raise TestFailure, "unexpected measurements: #{unexpected.join(", ")}" + end +end + +test_case "Count the number of non-null values of water_level in h2o_feet" do + result = client.query "select count(water_level) from h2o_feet" + expected = 15258 + actual = result[0]["values"][0]["count"] + if expected != actual + raise TestFailure, "expected to find #{expected} points, got #{actual}" + end +end + +test_case "Select the first five observations in the measurement h2o_feet" do + result = client.query("select * from h2o_feet limit 5").first["values"] + expected = 5 + actual = result.size + if expected != actual + raise TestFailure, "expected #{expected} observations, got #{actual}" + end + + expected = { + "time" => "2015-08-18T00:00:00Z", + "level description" => "between 6 and 9 feet", + "location" => "coyote_creek", + "water_level" => 8.12 + } + if expected != result[0] + raise TestAllowedFailure, "unexpected first result, got #{result[0]}" + end + + expected = { + "time" => "2015-08-18T00:12:00Z", + "level description" => "between 6 and 9 feet", + "location" => "coyote_creek", + "water_level" => 7.887 + } + if expected != result[-1] + raise TestAllowedFailure, "unexpected last result, got #{result[-1]}" + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/smoke/provision.sh b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/smoke/provision.sh new file mode 100755 index 0000000..8c58a30 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/smoke/provision.sh @@ -0,0 +1,92 @@ +#!/bin/sh -e + +if [ -z "$influx_version" ]; then + echo "== Provisioning InfluxDB: Skipping, influx_version is empty" + exit 0 +else + echo "== Provisioning InfluxDB ${influx_version}" +fi + +package_name="influxdb_${influx_version}_amd64.deb" +[ -z "${channel}" ] && channel="releases" +download_url="https://dl.influxdata.com/influxdb/${channel}/${package_name}" + + +echo "== Downloading package" + +if which curl 2>&1 >/dev/null; then + curl "${download_url}" > "${HOME}/${package_name}" +else + echo >&2 "E: Could not find curl" + exit 1 +fi + +echo "== Download verification" +hash_sum=$(md5sum "${HOME}/${package_name}" | awk '{ print $1 }') + +if [ -z "${pkghash}" ]; then + echo "-- Skipping, pkghash is empty" +else + if [ "${hash_sum}" != "${pkghash}" ]; then + echo >&2 "E: Hash sum mismatch (got ${hash_sum}, expected ${pkghash})" + exit 1 + fi +fi +echo "-- Download has MD5 hash: ${hash_sum}" + + +echo "== Installing" + +sudo dpkg -i "${HOME}/${package_name}" +sudo /etc/init.d/influxdb start + +echo "-- waiting for daemon to start" +while ! curl --head --fail --silent http://localhost:8086/ping; do + echo -n "." + sleep 1 +done + + +echo "== Configuring" + +echo "-- create admin user" +/usr/bin/influx -execute "CREATE USER root WITH PASSWORD 'toor' WITH ALL PRIVILEGES" + +echo "-- create non-admin user" +/usr/bin/influx -execute "CREATE USER test_user WITH PASSWORD 'resu_tset'" + +echo "-- create databases" +/usr/bin/influx -execute "CREATE DATABASE db_one" +/usr/bin/influx -execute "CREATE DATABASE db_two" + +echo "-- grant access" +/usr/bin/influx -execute "GRANT ALL ON db_two TO test_user" + + +echo "== Download and import NOAA sample data" + +curl https://s3-us-west-1.amazonaws.com/noaa.water.database.0.9/NOAA_data.txt > noaa.txt +/usr/bin/influx -import -path noaa.txt -precision s + +echo "-- grant access" +/usr/bin/influx -execute "GRANT ALL ON NOAA_water_database TO test_user" + + +echo "== Enable authentication" + +if [ ! -f /etc/influxdb/influxdb.conf ]; then + echo >&2 "E: config file not found" + exit 1 +fi + +sudo sed -i 's/auth-enabled = false/auth-enabled = true/' /etc/influxdb/influxdb.conf +sudo /etc/init.d/influxdb restart + +echo "-- waiting for daemon to restart" +while ! curl --head --fail --silent http://localhost:8086/ping; do + echo -n "." + sleep 1 +done + + +echo "== Done" diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/async_client_spec.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/async_client_spec.rb new file mode 100644 index 0000000..3ff3b16 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/async_client_spec.rb @@ -0,0 +1,58 @@ +require "spec_helper" +require "timeout" + +describe InfluxDB::Client do + let(:async_options) { true } + let(:client) { described_class.new(async: async_options) } + let(:subject) { client } + let(:stub_url) { "http://localhost:8086/write?db=&p=root&precision=s&u=root" } + let(:worker) { client.writer.worker } + + specify { expect(subject.writer).to be_a(InfluxDB::Writer::Async) } + + describe "#write_point" do + it "sends writes to client" do + post_request = stub_request(:post, stub_url).to_return(status: 204) + + (worker.max_post_points + 100).times do + subject.write_point('a', {}) + end + + # The timout code is fragile, and heavily dependent on system load + # (and scheduler decisions). On the CI, the system is less + # responsive and needs a bit more time. + timeout_stretch = ENV["TRAVIS"] == "true" ? 10 : 3 + + Timeout.timeout(timeout_stretch * worker.sleep_interval) do + subject.stop! + end + + worker.threads.each do |t| + expect(t.stop?).to be true + end + + # exact times can be 2 or 3 (because we have 3 worker threads), + # but cannot be less than 2 due to MAX_POST_POINTS limit + expect(post_request).to have_been_requested.at_least_times(2) + end + end + + describe "async options" do + let(:async_options) do + { + max_post_points: 10, + max_queue_size: 100, + num_worker_threads: 1, + sleep_interval: 0.5 + } + end + + subject { worker } + before { worker.stop! } + + specify { expect(subject.max_post_points).to be 10 } + specify { expect(subject.max_queue_size).to be 100 } + specify { expect(subject.num_worker_threads).to be 1 } + specify { expect(subject.sleep_interval).to be_within(0.0001).of(0.5) } + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/query_cluster_spec.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/query_cluster_spec.rb new file mode 100644 index 0000000..2e47f09 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/query_cluster_spec.rb @@ -0,0 +1,81 @@ +require "spec_helper" +require "json" + +describe InfluxDB::Client do + let(:subject) do + described_class.new( + "database", + { + host: "influxdb.test", + port: 9999, + username: "username", + password: "password", + time_precision: "s" + }.merge(args) + ) + end + + let(:args) { {} } + + describe "#create_cluster_admin" do + let(:user) { 'adminadmin' } + let(:pass) { 'passpass' } + let(:query) { "CREATE USER #{user} WITH PASSWORD '#{pass}' WITH ALL PRIVILEGES" } + + context 'with existing admin user' do + before do + stub_request(:get, "http://influxdb.test:9999/query").with( + query: { u: "username", p: "password", q: query } + ) + end + + it "should GET to create a new cluster admin" do + expect(subject.create_cluster_admin(user, pass)).to be_a(Net::HTTPOK) + end + end + + context 'with no admin user' do + let(:args) { { auth_method: 'none' } } + + before do + stub_request(:get, "http://influxdb.test:9999/query").with( + query: { q: query } + ) + end + + it "should GET to create a new cluster admin" do + expect(subject.create_cluster_admin(user, pass)).to be_a(Net::HTTPOK) + end + end + end + + describe "#list_cluster_admins" do + let(:response) { { "results" => [{ "series" => [{ "columns" => %w(user admin), "values" => [["dbadmin", true], ["foobar", false]] }] }] } } + let(:expected_result) { ["dbadmin"] } + + before do + stub_request(:get, "http://influxdb.test:9999/query").with( + query: { u: "username", p: "password", q: "SHOW USERS" } + ).to_return(body: JSON.generate(response, status: 200)) + end + + it "should GET a list of cluster admins" do + expect(subject.list_cluster_admins).to eq(expected_result) + end + end + + describe "#revoke_cluster_admin_privileges" do + let(:user) { 'useruser' } + let(:query) { "REVOKE ALL PRIVILEGES FROM #{user}" } + + before do + stub_request(:get, "http://influxdb.test:9999/query").with( + query: { u: "username", p: "password", q: query } + ) + end + + it "should GET to revoke cluster admin privileges from a user" do + expect(subject.revoke_cluster_admin_privileges(user)).to be_a(Net::HTTPOK) + end + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/query_continuous_query_spec.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/query_continuous_query_spec.rb new file mode 100644 index 0000000..27197c8 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/query_continuous_query_spec.rb @@ -0,0 +1,120 @@ +require "spec_helper" +require "json" + +describe InfluxDB::Client do + let(:subject) do + described_class.new( + "database", + { + host: "influxdb.test", + port: 9999, + username: "username", + password: "password", + time_precision: "s" + }.merge(args) + ) + end + + let(:args) { {} } + + describe "#list_continuous_queries" do + let(:query) { "SHOW CONTINUOUS QUERIES" } + let(:database) { "testdb" } + let(:response) do + { "results" => [{ "series" => [{ "name" => "otherdb", "columns" => %w(name query), + "values" => [["clicks_per_hour", "CREATE CONTINUOUS QUERY clicks_per_hour ON otherdb BEGIN SELECT count(name) INTO \"otherdb\".\"default\".clicksCount_1h FROM \"otherdb\".\"default\".clicks GROUP BY time(1h) END"]] }, + { "name" => "testdb", "columns" => %w(name query), + "values" => [["event_counts", "CREATE CONTINUOUS QUERY event_counts ON testdb BEGIN SELECT count(type) INTO \"testdb\".\"default\".typeCount_10m_byType FROM \"testdb\".\"default\".events GROUP BY time(10m), type END"]] }] }] } + end + + let(:expected_result) do + [{ "name" => "event_counts", "query" => "CREATE CONTINUOUS QUERY event_counts ON testdb BEGIN SELECT count(type) INTO \"testdb\".\"default\".typeCount_10m_byType FROM \"testdb\".\"default\".events GROUP BY time(10m), type END" }] + end + + before do + stub_request(:get, "http://influxdb.test:9999/query").with( + query: { u: "username", p: "password", q: query } + ).to_return(body: JSON.generate(response), status: 200) + end + + it "should GET a list of continuous queries for specified db only" do + expect(subject.list_continuous_queries(database)).to eq(expected_result) + end + end + + describe "#create_continuous_query" do + let(:name) { "event_counts_per_10m_by_type" } + let(:database) { "testdb" } + let(:query) { "SELECT COUNT(type) INTO typeCount_10m_byType FROM events GROUP BY time(10m), type" } + let(:every_interval) { nil } + let(:for_interval) { nil } + + let(:clause) do + c = "CREATE CONTINUOUS QUERY #{name} ON #{database}" + + if every_interval && for_interval + c << " RESAMPLE EVERY #{every_interval} FOR #{for_interval}" + elsif every_interval + c << " RESAMPLE EVERY #{every_interval}" + elsif for_interval + c << " RESAMPLE FOR #{for_interval}" + end + + c << " BEGIN\n#{query}\nEND" + end + + before do + stub_request(:get, "http://influxdb.test:9999/query").with( + query: { u: "username", p: "password", q: clause } + ) + end + + context "without resampling" do + it "should GET to create a new continuous query" do + expect(subject.create_continuous_query(name, database, query)).to be_a(Net::HTTPOK) + end + end + + context "with resampling" do + context "EVERY " do + let(:every_interval) { "10m" } + + it "should GET to create a new continuous query" do + expect(subject.create_continuous_query(name, database, query, resample_every: every_interval)).to be_a(Net::HTTPOK) + end + end + + context "FOR " do + let(:for_interval) { "7d" } + + it "should GET to create a new continuous query" do + expect(subject.create_continuous_query(name, database, query, resample_for: for_interval)).to be_a(Net::HTTPOK) + end + end + + context "EVERY FOR " do + let(:every_interval) { "5m" } + let(:for_interval) { "3w" } + + it "should GET to create a new continuous query" do + expect(subject.create_continuous_query(name, database, query, resample_for: for_interval, resample_every: every_interval)).to be_a(Net::HTTPOK) + end + end + end + end + + describe "#delete_continuous_query" do + let(:name) { "event_counts_per_10m_by_type" } + let(:database) { "testdb" } + let(:query) { "DROP CONTINUOUS QUERY #{name} ON #{database}" } + before do + stub_request(:get, "http://influxdb.test:9999/query").with( + query: { u: "username", p: "password", q: query } + ) + end + + it "should GET to remove continuous query" do + expect(subject.delete_continuous_query(name, database)).to be_a(Net::HTTPOK) + end + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/query_core_spec.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/query_core_spec.rb new file mode 100644 index 0000000..b3c61e4 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/query_core_spec.rb @@ -0,0 +1,36 @@ +require "spec_helper" + +describe InfluxDB::Client do + let(:subject) do + described_class.new "database", { + host: "influxdb.test", + port: 9999, + username: "username", + password: "password", + time_precision: "s" + }.merge(args) + end + + let(:args) { {} } + + describe "#query" do + let(:query) { "SELECT value FROM requests_per_minute WHERE time > 1437019900" } + let(:response) do + { "results" => [{ "series" => [{ "name" => "requests_per_minute", + "columns" => %w(time value) }] }] } + end + + before do + stub_request(:get, "http://influxdb.test:9999/query") + .with(query: { db: "database", precision: "s", u: "username", p: "password", q: query }) + .to_return(body: JSON.generate(response), status: 200) + end + + it "should handle responses with no values" do + # Some requests (such as trying to retrieve values from the future) + # return a result with no "values" key set. + expected_result = [{ "name" => "requests_per_minute", "tags" => nil, "values" => [] }] + expect(subject.query(query)).to eq(expected_result) + end + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/query_database_spec.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/query_database_spec.rb new file mode 100644 index 0000000..5c13517 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/query_database_spec.rb @@ -0,0 +1,73 @@ +require "spec_helper" +require "json" + +describe InfluxDB::Client do + let(:subject) do + described_class.new( + "database", + { + host: "influxdb.test", + port: 9999, + username: "username", + password: "password", + time_precision: "s" + }.merge(args) + ) + end + + let(:args) { {} } + let(:query) { nil } + let(:response) { { "results" => [] } } + + before do + stub_request(:get, "http://influxdb.test:9999/query").with( + query: { u: "username", p: "password", q: query } + ).to_return(body: JSON.generate(response)) + end + + describe "#create_database" do + describe "from param" do + let(:query) { "CREATE DATABASE foo" } + + it "should GET to create a new database" do + expect(subject.create_database("foo")).to be_a(Net::HTTPOK) + end + end + + describe "from config" do + let(:query) { "CREATE DATABASE database" } + + it "should GET to create a new database using database name from config" do + expect(subject.create_database).to be_a(Net::HTTPOK) + end + end + end + + describe "#delete_database" do + describe "from param" do + let(:query) { "DROP DATABASE foo" } + + it "should GET to remove a database" do + expect(subject.delete_database("foo")).to be_a(Net::HTTPOK) + end + end + + describe "from config" do + let(:query) { "DROP DATABASE database" } + + it "should GET to remove a database using database name from config" do + expect(subject.delete_database).to be_a(Net::HTTPOK) + end + end + end + + describe "#list_databases" do + let(:query) { "SHOW DATABASES" } + let(:response) { { "results" => [{ "series" => [{ "name" => "databases", "columns" => ["name"], "values" => [["foobar"]] }] }] } } + let(:expected_result) { [{ "name" => "foobar" }] } + + it "should GET a list of databases" do + expect(subject.list_databases).to eq(expected_result) + end + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/query_retention_policy_spec.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/query_retention_policy_spec.rb new file mode 100644 index 0000000..27b5dbc --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/query_retention_policy_spec.rb @@ -0,0 +1,81 @@ +require "spec_helper" +require "json" + +describe InfluxDB::Client do + let(:subject) do + described_class.new( + "database", + { + host: "influxdb.test", + port: 9999, + username: "username", + password: "password", + time_precision: "s" + }.merge(args) + ) + end + + let(:args) { {} } + let(:query) { nil } + let(:response) { { "results" => [] } } + + before do + stub_request(:get, "http://influxdb.test:9999/query").with( + query: { u: "username", p: "password", q: query } + ).to_return(body: JSON.generate(response)) + end + + describe "#list_retention_policies" do + let(:response) { { "results" => [{ "series" => [{ "columns" => %w(name duration replicaN default), "values" => [["default", "0", 1, true], ["another", "1", 2, false]] }] }] } } + let(:query) { "SHOW RETENTION POLICIES ON \"database\"" } + let(:expected_result) { [{ "name" => "default", "duration" => "0", "replicaN" => 1, "default" => true }, { "name" => "another", "duration" => "1", "replicaN" => 2, "default" => false }] } + + it "should GET a list of retention policies" do + expect(subject.list_retention_policies('database')).to eq(expected_result) + end + end + + describe "#create_retention_policy" do + context "default" do + let(:query) { "CREATE RETENTION POLICY \"1h.cpu\" ON foo DURATION 1h REPLICATION 2 DEFAULT" } + + it "should GET to create a new database" do + expect(subject.create_retention_policy('1h.cpu', 'foo', '1h', 2, true)).to be_a(Net::HTTPOK) + end + end + + context "non-default" do + let(:query) { "CREATE RETENTION POLICY \"1h.cpu\" ON foo DURATION 1h REPLICATION 2" } + + it "should GET to create a new database" do + expect(subject.create_retention_policy('1h.cpu', 'foo', '1h', 2)).to be_a(Net::HTTPOK) + end + end + end + + describe "#delete_retention_policy" do + let(:query) { "DROP RETENTION POLICY \"1h.cpu\" ON foo" } + + it "should GET to remove a database" do + expect(subject.delete_retention_policy('1h.cpu', 'foo')).to be_a(Net::HTTPOK) + end + end + + describe "#alter_retention_policy" do + context "default" do + let(:query) { "ALTER RETENTION POLICY \"1h.cpu\" ON foo DURATION 1h REPLICATION 2 DEFAULT" } + + it "should GET to alter a new database" do + expect(subject.alter_retention_policy('1h.cpu', 'foo', '1h', 2, true)).to be_a(Net::HTTPOK) + end + end + + context "non-default" do + let(:query) { "ALTER RETENTION POLICY \"1h.cpu\" ON foo DURATION 1h REPLICATION 2" } + + it "should GET to alter a new database" do + expect(subject.alter_retention_policy('1h.cpu', 'foo', '1h', 2)).to be_a(Net::HTTPOK) + end + end + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/query_series_spec.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/query_series_spec.rb new file mode 100644 index 0000000..b737ca0 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/query_series_spec.rb @@ -0,0 +1,50 @@ +require "spec_helper" +require "json" + +describe InfluxDB::Client do + let(:subject) do + described_class.new( + "database", + { + host: "influxdb.test", + port: 9999, + username: "username", + password: "password", + time_precision: "s" + }.merge(args) + ) + end + + let(:args) { {} } + + ### TODO ### + + # describe "DELETE #delete_series" do + # it "removes a series" do + # stub_request(:delete, "http://influxdb.test:9999/db/database/series/foo").with( + # query: { u: "username", p: "password" } + # ) + + # expect(subject.delete_series("foo")).to be_a(Net::HTTPOK) + # end + # end + + # describe "GET #list_series" do + # it "returns a list of all series names" do + # data = [ + # { "name" => "list_series_result", + # "columns" => %w(time name), + # "points" => [[0, 'a'], [0, 'b']] + # } + # ] + + # stub_request(:get, "http://influxdb.test:9999/db/database/series").with( + # query: { u: "username", p: "password", q: "list series", time_precision: "s" } + # ).to_return( + # body: JSON.generate(data) + # ) + + # expect(subject.list_series).to eq %w(a b) + # end + # end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/query_shard_space_spec.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/query_shard_space_spec.rb new file mode 100644 index 0000000..e241aa2 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/query_shard_space_spec.rb @@ -0,0 +1,105 @@ +# TODO: support 0.9.x + +# require "spec_helper" +# require "json" + +# describe InfluxDB::Client do +# let(:subject) do +# described_class.new( +# "database", +# { +# host: "influxdb.test", +# port: 9999, +# username: "username", +# password: "password", +# time_precision: "s" +# }.merge(args) +# ) +# end + +# let(:args) { {} } + +# let(:url) { "http://influxdb.test:9999/cluster/shard_spaces" } +# let(:req_query) { { u: "username", p: "password" } } +# let(:req_body) { nil } +# let(:request_params) { { query: req_query, body: req_body } } +# let(:response) { { body: JSON.generate(shard_spaces), status: 200 } } +# let(:shard_spaces) { [subject.default_shard_space_options.merge("database" => "foo")] } + +# context "GET methods" do +# before { stub_request(:get, url).with(request_params).to_return(response) } + +# describe "GET #list_shard_spaces" do +# it 'returns OK' do +# expect(subject.list_shard_spaces).to eq shard_spaces +# end +# end + +# describe "GET #shard_space_info" do +# context "non-empty list" do +# it "returns shard space info" do +# expect(subject.shard_space_info('foo', 'default')).to eq shard_spaces.first +# end +# end + +# context "returns an empty list" do +# let(:shard_spaces) { [] } + +# it "returns no shard space" do +# expect(subject.shard_space_info('foo', 'default')).to be_nil +# end +# end +# end +# end + +# describe "POST #create_shard_space" do +# let(:url) { "http://influxdb.test:9999/cluster/shard_spaces/foo" } +# let(:req_body) { subject.default_shard_space_options } +# let(:response) { { status: 200 } } + +# before { stub_request(:post, url).with(request_params).to_return(response) } + +# it 'returns OK' do +# expect(subject.create_shard_space("foo", subject.default_shard_space_options)) +# .to be_a(Net::HTTPOK) +# end +# end + +# describe "DELETE #delete_shard_space" do +# let(:url) { "http://influxdb.test:9999/cluster/shard_spaces/foo/default" } +# let(:response) { { status: 200 } } +# before { stub_request(:delete, url).with(request_params).to_return(response) } + +# it 'returns OK' do +# expect(subject.delete_shard_space("foo", "default")).to be_a(Net::HTTPOK) +# end +# end + +# describe "#update_shard_space" do +# let(:post_url) { "http://influxdb.test:9999/cluster/shard_spaces/foo/default" } +# let(:post_request_params) do +# { +# query: req_query, +# body: subject.default_shard_space_options.merge("shardDuration" => "30d") +# } +# end + +# it 'gets the shard space and updates the shard space' do +# stub_request(:get, url).with(request_params).to_return(response) +# stub_request(:post, post_url).with(post_request_params) + +# expect(subject.update_shard_space("foo", "default", "shardDuration" => "30d")).to be_a(Net::HTTPOK) +# end +# end + +# describe "POST #configure_database" do +# let(:url) { "http://influxdb.test:9999/cluster/database_configs/foo" } +# let(:req_body) { subject.default_database_configuration } + +# before { stub_request(:post, url).with(request_params) } + +# it "returns OK" do +# expect(subject.configure_database("foo")).to be_a(Net::HTTPOK) +# end +# end +# end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/query_shard_spec.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/query_shard_spec.rb new file mode 100644 index 0000000..25af761 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/query_shard_spec.rb @@ -0,0 +1,43 @@ +require "spec_helper" +require "json" + +describe InfluxDB::Client do + let(:subject) do + described_class.new( + "database", + { + host: "influxdb.test", + port: 9999, + username: "username", + password: "password", + time_precision: "s" + }.merge(args) + ) + end + + let(:args) { {} } + + ### TODO ### + + # describe "GET #list_shards" do + # it "returns a list of shards" do + # shard_list = { "longTerm" => [], "shortTerm" => [] } + # stub_request(:get, "http://influxdb.test:9999/cluster/shards").with( + # query: { u: "username", p: "password" } + # ).to_return(body: JSON.generate(shard_list, status: 200)) + + # expect(subject.list_shards).to eq shard_list + # end + # end + + # describe "DELETE #delete_shard" do + # it "removes shard by id" do + # shard_id = 1 + # stub_request(:delete, "http://influxdb.test:9999/cluster/shards/#{shard_id}").with( + # query: { u: "username", p: "password" } + # ) + + # expect(subject.delete_shard(shard_id, [1, 2])).to be_a(Net::HTTPOK) + # end + # end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/query_user_spec.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/query_user_spec.rb new file mode 100644 index 0000000..fbd38b3 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/query_user_spec.rb @@ -0,0 +1,124 @@ +require "spec_helper" +require "json" + +describe InfluxDB::Client do + let(:subject) do + described_class.new( + "database", + { + host: "influxdb.test", + port: 9999, + username: "username", + password: "password", + time_precision: "s" + }.merge(args) + ) + end + + let(:args) { {} } + let(:query) { nil } + let(:response) { { "results" => [] } } + + before do + stub_request(:get, "http://influxdb.test:9999/query").with( + query: { u: "username", p: "password", q: query } + ).to_return(body: JSON.generate(response)) + end + + describe "#update user password" do + let(:user) { 'useruser' } + let(:pass) { 'passpass' } + let(:query) { "SET PASSWORD FOR #{user} = '#{pass}'" } + + it "should GET to update user password" do + expect(subject.update_user_password(user, pass)).to be_a(Net::HTTPOK) + end + end + + describe "#grant_user_privileges" do + let(:user) { 'useruser' } + let(:perm) { :write } + let(:db) { 'foo' } + let(:query) { "GRANT #{perm.to_s.upcase} ON #{db} TO #{user}" } + + it "should GET to grant privileges for a user on a database" do + expect(subject.grant_user_privileges(user, db, perm)).to be_a(Net::HTTPOK) + end + end + + describe "#grant_user_admin_privileges" do + let(:user) { 'useruser' } + let(:query) { "GRANT ALL PRIVILEGES TO #{user}" } + + it "should GET to grant privileges for a user on a database" do + expect(subject.grant_user_admin_privileges(user)).to be_a(Net::HTTPOK) + end + end + + describe "#revoke_user_privileges" do + let(:user) { 'useruser' } + let(:perm) { :write } + let(:db) { 'foo' } + let(:query) { "REVOKE #{perm.to_s.upcase} ON #{db} FROM #{user}" } + + it "should GET to revoke privileges from a user on a database" do + expect(subject.revoke_user_privileges(user, db, perm)).to be_a(Net::HTTPOK) + end + end + + describe "#create_database_user" do + let(:user) { 'useruser' } + let(:pass) { 'passpass' } + let(:db) { 'foo' } + let(:query) { "CREATE user #{user} WITH PASSWORD '#{pass}'; GRANT ALL ON #{db} TO #{user}" } + + context "without specifying permissions" do + it "should GET to create a new database user with all permissions" do + expect(subject.create_database_user(db, user, pass)).to be_a(Net::HTTPOK) + end + end + + context "with passing permission as argument" do + let(:permission) { :read } + let(:query) { "CREATE user #{user} WITH PASSWORD '#{pass}'; GRANT #{permission.to_s.upcase} ON #{db} TO #{user}" } + + it "should GET to create a new database user with permission set" do + expect(subject.create_database_user(db, user, pass, permissions: permission)).to be_a(Net::HTTPOK) + end + end + end + + describe "#delete_user" do + let(:user) { 'useruser' } + let(:query) { "DROP USER #{user}" } + + it "should GET to delete a user" do + expect(subject.delete_user(user)).to be_a(Net::HTTPOK) + end + end + + describe "#list_users" do + let(:response) { { "results" => [{ "series" => [{ "columns" => %w(user admin), "values" => [["dbadmin", true], ["foobar", false]] }] }] } } + let(:query) { "SHOW USERS" } + let(:expected_result) { [{ "username" => "dbadmin", "admin" => true }, { "username" => "foobar", "admin" => false }] } + + it "should GET a list of database users" do + expect(subject.list_users).to eq(expected_result) + end + end + + describe "#list_user_grants" do + let(:user) { 'useruser' } + let(:list_query) { "SHOW GRANTS FOR #{user}" } + + before do + stub_request(:get, "http://influxdb.test:9999/query") + .with(query: { u: "username", p: "password", q: list_query }) + .to_return(status: 200, body: "", headers: {}) + end + + it "should GET for a user" do + expect(subject.list_user_grants(user)).to be_a(Net::HTTPOK) + end + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/query_with_params_spec.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/query_with_params_spec.rb new file mode 100644 index 0000000..c449f6e --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/query_with_params_spec.rb @@ -0,0 +1,69 @@ +require "spec_helper" + +describe InfluxDB::Client do + let(:subject) do + described_class.new "database", { + host: "influxdb.test", + port: 9999, + username: "username", + password: "password", + time_precision: "s" + }.merge(args) + end + + let(:args) { {} } + + describe "#query with parameters" do + let(:query) { "SELECT value FROM requests_per_minute WHERE time > %{start}" } + let(:query_params) { { start: 1_437_019_900 } } + let(:query_compiled) { "SELECT value FROM requests_per_minute WHERE time > 1437019900" } + + let(:response) do + { "results" => [{ "series" => [{ "name" => "requests_per_minute", + "columns" => %w(time value) }] }] } + end + + before do + stub_request(:get, "http://influxdb.test:9999/query") + .with(query: { db: "database", precision: "s", u: "username", p: "password", q: query_compiled }) + .to_return(body: JSON.generate(response), status: 200) + end + + it "should handle responses with no values" do + # Some requests (such as trying to retrieve values from the future) + # return a result with no "values" key set. + expected_result = [{ "name" => "requests_per_minute", "tags" => nil, "values" => [] }] + expect(subject.query(query, params: query_params)).to eq(expected_result) + end + end + + describe "#query_with_params" do + let(:query) { "select * from foo where bar > %{param}" } + let(:compiled_query) { subject.builder.build(query, query_params) } + + context "with empty params hash" do + let(:query_params) { {} } + it { expect { compiled_query }.to raise_error ArgumentError } + end + + context "with empty params array" do + let(:query_params) { [] } + it { expect { compiled_query }.to raise_error ArgumentError } + end + + context "with empty params" do + let(:query_params) { nil } + it { expect { compiled_query }.to raise_error ArgumentError } + end + + context "with simple params" do + let(:query_params) { { param: 42 } } + it { expect(compiled_query).to eq "select * from foo where bar > 42" } + end + + context "string escaping" do + let(:query_params) { { param: "string" } } + it { expect(compiled_query).to eq "select * from foo where bar > 'string'" } + end + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/querying_issue_7000_spec.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/querying_issue_7000_spec.rb new file mode 100644 index 0000000..884a67a --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/querying_issue_7000_spec.rb @@ -0,0 +1,89 @@ +# This test spec addresses closed issue https://github.com/influxdata/influxdb/issues/7000 where +# it was confirmed that when chunking is enabled, the InfluxDB REST API returns multi-line JSON. + +require "spec_helper" +require "json" + +describe InfluxDB::Client do + let(:subject) do + described_class.new "database", { + host: "influxdb.test", + port: 9999, + username: "username", + password: "password", + time_precision: "s" + }.merge(args) + end + + let(:args) { {} } + let(:database) { subject.config.database } + let(:extra_params) { {} } + let(:response) { "" } + + before do + stub_request(:get, "http://influxdb.test:9999/query") + .with(query: { q: query, u: "username", p: "password", precision: 's', db: database }.merge(extra_params)) + .to_return(body: response) + end + + describe "#query" do + context "with series with different tags (multi-line)" do + let(:args) { { chunk_size: 100 } } + let(:extra_params) { { chunked: "true", chunk_size: "100" } } + + let(:response_line_1) do + { "results" => [{ "series" => [{ "name" => "cpu", "tags" => { "region" => "pl" }, "columns" => %w(time temp value), "values" => [["2015-07-07T15:13:04Z", 34, 0.343443]] }] }] } + end + let(:response_line_2) do + { "results" => [{ "series" => [{ "name" => "cpu", "tags" => { "region" => "us" }, "columns" => %w(time temp value), "values" => [["2015-07-07T14:58:37Z", 92, 0.3445], ["2015-07-07T14:59:09Z", 68, 0.8787]] }] }] } + end + let(:response) do + JSON.generate(response_line_1) + "\n" + JSON.generate(response_line_2) + end + let(:expected_result) do + [{ "name" => "cpu", "tags" => { "region" => "pl" }, + "values" => [{ "time" => "2015-07-07T15:13:04Z", "temp" => 34, "value" => 0.343443 }] }, + { "name" => "cpu", "tags" => { "region" => "us" }, + "values" => [{ "time" => "2015-07-07T14:58:37Z", "temp" => 92, "value" => 0.3445 }, + { "time" => "2015-07-07T14:59:09Z", "temp" => 68, "value" => 0.8787 }] }] + end + let(:query) { 'SELECT * FROM cpu' } + + it "should return array with 2 elements grouped by tags" do + expect(subject.query(query)).to eq(expected_result) + end + end + + context "with multiple series with different tags" do + let(:args) { { chunk_size: 100 } } + let(:extra_params) { { chunked: "true", chunk_size: "100" } } + + let(:response_line_1) do + { "results" => [{ "series" => [{ "name" => "access_times.service_1", "tags" => { "code" => "200", "result" => "failure", "status" => "OK" }, "columns" => %w(time value), "values" => [["2015-07-08T07:15:22Z", 327]] }] }] } + end + let(:response_line_2) do + { "results" => [{ "series" => [{ "name" => "access_times.service_1", "tags" => { "code" => "500", "result" => "failure", "status" => "Internal Server Error" }, "columns" => %w(time value), "values" => [["2015-07-08T06:15:22Z", 873]] }] }] } + end + let(:response_line_3) do + { "results" => [{ "series" => [{ "name" => "access_times.service_2", "tags" => { "code" => "200", "result" => "failure", "status" => "OK" }, "columns" => %w(time value), "values" => [["2015-07-08T07:15:22Z", 943]] }] }] } + end + let(:response_line_4) do + { "results" => [{ "series" => [{ "name" => "access_times.service_2", "tags" => { "code" => "500", "result" => "failure", "status" => "Internal Server Error" }, "columns" => %w(time value), "values" => [["2015-07-08T06:15:22Z", 606]] }] }] } + end + let(:response) do + JSON.generate(response_line_1) + "\n" + JSON.generate(response_line_2) + "\n" + JSON.generate(response_line_3) + "\n" + JSON.generate(response_line_4) + end + let(:expected_result) do + [{ "name" => "access_times.service_1", "tags" => { "code" => "200", "result" => "failure", "status" => "OK" }, "values" => [{ "time" => "2015-07-08T07:15:22Z", "value" => 327 }] }, + { "name" => "access_times.service_1", "tags" => { "code" => "500", "result" => "failure", "status" => "Internal Server Error" }, "values" => [{ "time" => "2015-07-08T06:15:22Z", "value" => 873 }] }, + { "name" => "access_times.service_2", "tags" => { "code" => "200", "result" => "failure", "status" => "OK" }, "values" => [{ "time" => "2015-07-08T07:15:22Z", "value" => 943 }] }, + { "name" => "access_times.service_2", "tags" => { "code" => "500", "result" => "failure", "status" => "Internal Server Error" }, "values" => [{ "time" => "2015-07-08T06:15:22Z", "value" => 606 }] }] + end + let(:query) { "SELECT * FROM /access_times.*/" } + + it "should return array with 4 elements grouped by name and tags" do + expect(subject.query(query)).to eq(expected_result) + end + end + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/querying_spec.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/querying_spec.rb new file mode 100644 index 0000000..bcccbaf --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/querying_spec.rb @@ -0,0 +1,265 @@ +require "spec_helper" +require "json" + +describe InfluxDB::Client do + let(:subject) do + described_class.new "database", { + host: "influxdb.test", + port: 9999, + username: "username", + password: "password", + time_precision: "s" + }.merge(args) + end + + let(:args) { {} } + let(:database) { subject.config.database } + let(:extra_params) { {} } + let(:response) {} + + before do + stub_request(:get, "http://influxdb.test:9999/query") + .with(query: { q: query, u: "username", p: "password", precision: 's', db: database }.merge(extra_params)) + .to_return(body: JSON.generate(response)) + end + + describe "#query" do + context "with single series with multiple points" do + let(:response) do + { "results" => [{ "series" => [{ "name" => "cpu", "tags" => { "region" => "us" }, + "columns" => %w(time temp value), + "values" => [["2015-07-07T14:58:37Z", 92, 0.3445], ["2015-07-07T14:59:09Z", 68, 0.8787]] }] }] } + end + let(:expected_result) do + [{ "name" => "cpu", "tags" => { "region" => "us" }, + "values" => [{ "time" => "2015-07-07T14:58:37Z", "temp" => 92, "value" => 0.3445 }, + { "time" => "2015-07-07T14:59:09Z", "temp" => 68, "value" => 0.8787 }] }] + end + let(:query) { 'SELECT * FROM cpu' } + + it "should return array with single hash containing multiple values" do + expect(subject.query(query)).to eq(expected_result) + end + end + + context "with series with different tags" do + let(:response) do + { "results" => [{ "series" => [{ "name" => "cpu", "tags" => { "region" => "pl" }, "columns" => %w(time temp value), "values" => [["2015-07-07T15:13:04Z", 34, 0.343443]] }, + { "name" => "cpu", "tags" => { "region" => "us" }, "columns" => %w(time temp value), "values" => [["2015-07-07T14:58:37Z", 92, 0.3445], ["2015-07-07T14:59:09Z", 68, 0.8787]] }] }] } + end + let(:expected_result) do + [{ "name" => "cpu", "tags" => { "region" => "pl" }, + "values" => [{ "time" => "2015-07-07T15:13:04Z", "temp" => 34, "value" => 0.343443 }] }, + { "name" => "cpu", "tags" => { "region" => "us" }, + "values" => [{ "time" => "2015-07-07T14:58:37Z", "temp" => 92, "value" => 0.3445 }, + { "time" => "2015-07-07T14:59:09Z", "temp" => 68, "value" => 0.8787 }] }] + end + let(:query) { 'SELECT * FROM cpu' } + + it "should return array with 2 elements grouped by tags" do + expect(subject.query(query)).to eq(expected_result) + end + end + + context "with multiple series with different tags" do + let(:response) do + { "results" => [{ "series" => [{ "name" => "access_times.service_1", "tags" => { "code" => "200", "result" => "failure", "status" => "OK" }, "columns" => %w(time value), "values" => [["2015-07-08T07:15:22Z", 327]] }, + { "name" => "access_times.service_1", "tags" => { "code" => "500", "result" => "failure", "status" => "Internal Server Error" }, "columns" => %w(time value), "values" => [["2015-07-08T06:15:22Z", 873]] }, + { "name" => "access_times.service_2", "tags" => { "code" => "200", "result" => "failure", "status" => "OK" }, "columns" => %w(time value), "values" => [["2015-07-08T07:15:22Z", 943]] }, + { "name" => "access_times.service_2", "tags" => { "code" => "500", "result" => "failure", "status" => "Internal Server Error" }, "columns" => %w(time value), "values" => [["2015-07-08T06:15:22Z", 606]] }] }] } + end + let(:expected_result) do + [{ "name" => "access_times.service_1", "tags" => { "code" => "200", "result" => "failure", "status" => "OK" }, "values" => [{ "time" => "2015-07-08T07:15:22Z", "value" => 327 }] }, + { "name" => "access_times.service_1", "tags" => { "code" => "500", "result" => "failure", "status" => "Internal Server Error" }, "values" => [{ "time" => "2015-07-08T06:15:22Z", "value" => 873 }] }, + { "name" => "access_times.service_2", "tags" => { "code" => "200", "result" => "failure", "status" => "OK" }, "values" => [{ "time" => "2015-07-08T07:15:22Z", "value" => 943 }] }, + { "name" => "access_times.service_2", "tags" => { "code" => "500", "result" => "failure", "status" => "Internal Server Error" }, "values" => [{ "time" => "2015-07-08T06:15:22Z", "value" => 606 }] }] + end + let(:query) { "SELECT * FROM /access_times.*/" } + + it "should return array with 4 elements grouped by name and tags" do + expect(subject.query(query)).to eq(expected_result) + end + end + + context "with multiple series for explicit value only" do + let(:response) do + { "results" => [{ "series" => [{ "name" => "access_times.service_1", "columns" => %w(time value), "values" => [["2015-07-08T06:15:22Z", 873], ["2015-07-08T07:15:22Z", 327]] }, + { "name" => "access_times.service_2", "columns" => %w(time value), "values" => [["2015-07-08T06:15:22Z", 606], ["2015-07-08T07:15:22Z", 943]] }] }] } + end + let(:expected_result) do + [{ "name" => "access_times.service_1", "tags" => nil, "values" => [{ "time" => "2015-07-08T06:15:22Z", "value" => 873 }, { "time" => "2015-07-08T07:15:22Z", "value" => 327 }] }, + { "name" => "access_times.service_2", "tags" => nil, "values" => [{ "time" => "2015-07-08T06:15:22Z", "value" => 606 }, { "time" => "2015-07-08T07:15:22Z", "value" => 943 }] }] + end + let(:query) { "SELECT value FROM /access_times.*/" } + + it "should return array with 2 elements grouped by name only and no tags" do + expect(subject.query(query)).to eq(expected_result) + end + end + + context "with a block" do + let(:response) do + { "results" => [{ "series" => [{ "name" => "cpu", "tags" => { "region" => "pl" }, "columns" => %w(time temp value), "values" => [["2015-07-07T15:13:04Z", 34, 0.343443]] }, + { "name" => "cpu", "tags" => { "region" => "us" }, "columns" => %w(time temp value), "values" => [["2015-07-07T14:58:37Z", 92, 0.3445], ["2015-07-07T14:59:09Z", 68, 0.8787]] }] }] } + end + + let(:expected_result) do + [{ "name" => "cpu", "tags" => { "region" => "pl" }, + "values" => [{ "time" => "2015-07-07T15:13:04Z", "temp" => 34, "value" => 0.343443 }] }, + { "name" => "cpu", "tags" => { "region" => "us" }, + "values" => [{ "time" => "2015-07-07T14:58:37Z", "temp" => 92, "value" => 0.3445 }, + { "time" => "2015-07-07T14:59:09Z", "temp" => 68, "value" => 0.8787 }] }] + end + let(:query) { 'SELECT * FROM cpu' } + + it "should accept a block and yield name, tags and points" do + results = [] + subject.query(query) do |name, tags, points| + results << { 'name' => name, 'tags' => tags, 'values' => points } + end + expect(results).to eq(expected_result) + end + end + + context "with epoch set to seconds" do + let(:args) { { epoch: 's' } } + let(:extra_params) { { epoch: 's' } } + + let(:response) do + { "results" => [{ "series" => [{ "name" => "cpu", "tags" => { "region" => "pl" }, "columns" => %w(time temp value), "values" => [[1_438_580_576, 34, 0.343443]] }, + { "name" => "cpu", "tags" => { "region" => "us" }, "columns" => %w(time temp value), "values" => [[1_438_612_976, 92, 0.3445], [1_438_612_989, 68, 0.8787]] }] }] } + end + let(:expected_result) do + [{ "name" => "cpu", "tags" => { "region" => "pl" }, + "values" => [{ "time" => 1_438_580_576, "temp" => 34, "value" => 0.343443 }] }, + { "name" => "cpu", "tags" => { "region" => "us" }, + "values" => [{ "time" => 1_438_612_976, "temp" => 92, "value" => 0.3445 }, + { "time" => 1_438_612_989, "temp" => 68, "value" => 0.8787 }] }] + end + let(:query) { 'SELECT * FROM cpu' } + + it "should return results with integer timestamp" do + expect(subject.query(query)).to eq(expected_result) + end + end + + context "with chunk_size set to 100" do + let(:args) { { chunk_size: 100 } } + let(:extra_params) { { chunked: "true", chunk_size: "100" } } + + let(:response) do + { "results" => [{ "series" => [{ "name" => "cpu", "tags" => { "region" => "pl" }, "columns" => %w(time temp value), "values" => [[1_438_580_576, 34, 0.343443]] }] }] } + end + let(:expected_result) do + [{ "name" => "cpu", "tags" => { "region" => "pl" }, "values" => [{ "time" => 1_438_580_576, "temp" => 34, "value" => 0.343443 }] }] + end + let(:query) { 'SELECT * FROM cpu' } + + it "should set 'chunked' and 'chunk_size' parameters" do + expect(subject.query(query)).to eq(expected_result) + end + end + + context "with database" do + let(:extra_params) { { db: 'overriden_db' } } + let(:response) do + { "results" => [{ "series" => [{ "name" => "cpu", "tags" => { "region" => "us" }, + "columns" => %w(time temp value), + "values" => [["2015-07-07T14:58:37Z", 92, 0.3445], ["2015-07-07T14:59:09Z", 68, 0.8787]] }] }] } + end + let(:expected_result) do + [{ "name" => "cpu", "tags" => { "region" => "us" }, + "values" => [{ "time" => "2015-07-07T14:58:37Z", "temp" => 92, "value" => 0.3445 }, + { "time" => "2015-07-07T14:59:09Z", "temp" => 68, "value" => 0.8787 }] }] + end + let(:query) { 'SELECT * FROM cpu' } + + it "should return array with single hash containing multiple values" do + expect(subject.query(query, database: 'overriden_db')).to eq(expected_result) + end + end + end + + describe "multiple select queries" do + context "with single series with multiple points" do + let(:response) do + { "results" => [{ "series" => [{ "name" => "cpu", "tags" => { "region" => "us" }, + "columns" => %w(time temp value), + "values" => [["2015-07-07T14:58:37Z", 92, 0.3445], ["2015-07-07T14:59:09Z", 68, 0.8787]] }] }, + { "series" => [{ "name" => "memory", "tags" => { "region" => "us" }, + "columns" => %w(time free total), + "values" => [["2015-07-07T14:58:37Z", 96_468_992, 134_217_728], ["2015-07-07T14:59:09Z", 71_303_168, 134_217_728]] }] }] } + end + let(:expected_result) do + [{ "name" => "cpu", "tags" => { "region" => "us" }, + "values" => [{ "time" => "2015-07-07T14:58:37Z", "temp" => 92, "value" => 0.3445 }, + { "time" => "2015-07-07T14:59:09Z", "temp" => 68, "value" => 0.8787 }] }, + { "name" => "memory", "tags" => { "region" => "us" }, + "values" => [{ "time" => "2015-07-07T14:58:37Z", "free" => 92 * 2**20, "total" => 128 * 2**20 }, + { "time" => "2015-07-07T14:59:09Z", "free" => 68 * 2**20, "total" => 128 * 2**20 }] }] + end + let(:query) { 'SELECT * FROM cpu; SELECT * FROM memory' } + + it "should return array with single hash containing multiple values" do + expect(subject.query(query)).to eq(expected_result) + end + end + + context "with series with different tags" do + let(:response) do + { "results" => [{ "series" => [{ "name" => "cpu", "tags" => { "region" => "pl" }, "columns" => %w(time temp value), "values" => [["2015-07-07T15:13:04Z", 34, 0.343443]] }, + { "name" => "cpu", "tags" => { "region" => "us" }, "columns" => %w(time temp value), "values" => [["2015-07-07T14:58:37Z", 92, 0.3445], ["2015-07-07T14:59:09Z", 68, 0.8787]] }] }, + { "series" => [{ "name" => "memory", "tags" => { "region" => "pl" }, "columns" => %w(time free total), "values" => [["2015-07-07T15:13:04Z", 35_651_584, 134_217_728]] }, + { "name" => "memory", "tags" => { "region" => "us" }, "columns" => %w(time free total), "values" => [["2015-07-07T14:58:37Z", 96_468_992, 134_217_728], ["2015-07-07T14:59:09Z", 71_303_168, 134_217_728]] }] }] } + end + let(:expected_result) do + [{ "name" => "cpu", "tags" => { "region" => "pl" }, + "values" => [{ "time" => "2015-07-07T15:13:04Z", "temp" => 34, "value" => 0.343443 }] }, + { "name" => "cpu", "tags" => { "region" => "us" }, + "values" => [{ "time" => "2015-07-07T14:58:37Z", "temp" => 92, "value" => 0.3445 }, + { "time" => "2015-07-07T14:59:09Z", "temp" => 68, "value" => 0.8787 }] }, + { "name" => "memory", "tags" => { "region" => "pl" }, + "values" => [{ "time" => "2015-07-07T15:13:04Z", "free" => 34 * 2**20, "total" => 128 * 2**20 }] }, + { "name" => "memory", "tags" => { "region" => "us" }, + "values" => [{ "time" => "2015-07-07T14:58:37Z", "free" => 92 * 2**20, "total" => 128 * 2**20 }, + { "time" => "2015-07-07T14:59:09Z", "free" => 68 * 2**20, "total" => 128 * 2**20 }] }] + end + let(:query) { 'SELECT * FROM cpu; SELECT * FROM memory' } + + it "should return array with 2 elements grouped by tags" do + expect(subject.query(query)).to eq(expected_result) + end + end + + context "with a block" do + let(:response) do + { "results" => [{ "series" => [{ "name" => "cpu", "tags" => { "region" => "pl" }, "columns" => %w(time temp value), "values" => [["2015-07-07T15:13:04Z", 34, 0.343443]] }, + { "name" => "cpu", "tags" => { "region" => "us" }, "columns" => %w(time temp value), "values" => [["2015-07-07T14:58:37Z", 92, 0.3445], ["2015-07-07T14:59:09Z", 68, 0.8787]] }] }, + { "series" => [{ "name" => "memory", "tags" => { "region" => "pl" }, "columns" => %w(time free total), "values" => [["2015-07-07T15:13:04Z", 35_651_584, 134_217_728]] }, + { "name" => "memory", "tags" => { "region" => "us" }, "columns" => %w(time free total), "values" => [["2015-07-07T14:58:37Z", 96_468_992, 134_217_728], ["2015-07-07T14:59:09Z", 71_303_168, 134_217_728]] }] }] } + end + + let(:expected_result) do + [{ "name" => "cpu", "tags" => { "region" => "pl" }, + "values" => [{ "time" => "2015-07-07T15:13:04Z", "temp" => 34, "value" => 0.343443 }] }, + { "name" => "cpu", "tags" => { "region" => "us" }, + "values" => [{ "time" => "2015-07-07T14:58:37Z", "temp" => 92, "value" => 0.3445 }, + { "time" => "2015-07-07T14:59:09Z", "temp" => 68, "value" => 0.8787 }] }, + { "name" => "memory", "tags" => { "region" => "pl" }, + "values" => [{ "time" => "2015-07-07T15:13:04Z", "free" => 34 * 2**20, "total" => 128 * 2**20 }] }, + { "name" => "memory", "tags" => { "region" => "us" }, + "values" => [{ "time" => "2015-07-07T14:58:37Z", "free" => 92 * 2**20, "total" => 128 * 2**20 }, + { "time" => "2015-07-07T14:59:09Z", "free" => 68 * 2**20, "total" => 128 * 2**20 }] }] + end + let(:query) { 'SELECT * FROM cpu; SELECT * FROM memory' } + + it "should accept a block and yield name, tags and points" do + results = [] + subject.query(query) do |name, tags, points| + results << { 'name' => name, 'tags' => tags, 'values' => points } + end + expect(results).to eq(expected_result) + end + end + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/retry_requests_spec.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/retry_requests_spec.rb new file mode 100644 index 0000000..69af5e4 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/retry_requests_spec.rb @@ -0,0 +1,104 @@ +require "spec_helper" +require "json" + +describe InfluxDB::Client do + let(:client) do + described_class.new( + "database", + { + host: "influxdb.test", + port: 9999, + username: "username", + password: "password", + time_precision: "s" + }.merge(args) + ) + end + + let(:args) { {} } + + let(:database) { client.config.database } + + describe "retrying requests" do + let(:series) { "cpu" } + let(:data) do + { tags: { region: 'us', host: 'server_1' }, + values: { temp: 88, value: 54 } } + end + let(:body) do + InfluxDB::PointValue.new(data.merge(series: series)).dump + end + + subject { client.write_point(series, data) } + + before do + allow(client).to receive(:log) + stub_request(:post, "http://influxdb.test:9999/write").with( + query: { u: "username", p: "password", precision: 's', db: database }, + headers: { "Content-Type" => "application/octet-stream" }, + body: body + ).to_raise(Timeout::Error) + end + + it "raises when stopped" do + client.stop! + expect(client).not_to receive(:sleep) + expect { subject }.to raise_error(InfluxDB::ConnectionError) do |e| + expect(e.cause).to be_an_instance_of(Timeout::Error) + end + end + + context "when retry is 0" do + let(:args) { { retry: 0 } } + it "raise error directly" do + expect(client).not_to receive(:sleep) + expect { subject }.to raise_error(InfluxDB::ConnectionError) do |e| + expect(e.cause).to be_an_instance_of(Timeout::Error) + end + end + end + + context "when retry is 'n'" do + let(:args) { { retry: 3 } } + + it "raise error after 'n' attemps" do + expect(client).to receive(:sleep).exactly(3).times + expect { subject }.to raise_error(InfluxDB::ConnectionError) do |e| + expect(e.cause).to be_an_instance_of(Timeout::Error) + end + end + end + + context "when retry is -1" do + let(:args) { { retry: -1 } } + before do + stub_request(:post, "http://influxdb.test:9999/write") + .with( + query: { u: "username", p: "password", precision: 's', db: database }, + headers: { "Content-Type" => "application/octet-stream" }, + body: body + ) + .to_raise(Timeout::Error).then + .to_raise(Timeout::Error).then + .to_raise(Timeout::Error).then + .to_raise(Timeout::Error).then + .to_return(status: 204) + end + + it "keep trying until get the connection" do + expect(client).to receive(:sleep).exactly(4).times + expect { subject }.to_not raise_error + end + end + + it "raise an exception if the server didn't return 200" do + stub_request(:post, "http://influxdb.test:9999/write").with( + query: { u: "username", p: "password", precision: 's', db: database }, + headers: { "Content-Type" => "application/octet-stream" }, + body: body + ).to_return(status: 401) + + expect { client.write_point(series, data) }.to raise_error(InfluxDB::AuthenticationError) + end + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/udp_client_spec.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/udp_client_spec.rb new file mode 100644 index 0000000..3aa4f9c --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/udp_client_spec.rb @@ -0,0 +1,21 @@ +require "spec_helper" + +describe InfluxDB::Client do + let(:client) { described_class.new(udp: { host: "localhost", port: 44_444 }) } + + specify { expect(client.writer).to be_a(InfluxDB::Writer::UDP) } + + describe "#write" do + let(:message) { 'responses,region=eu value=5i' } + + it "sends a UPD packet" do + s = UDPSocket.new + s.bind("localhost", 44_444) + + client.write_point("responses", values: { value: 5 }, tags: { region: 'eu' }) + + rec_message = s.recvfrom(30).first + expect(rec_message).to eq message + end + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/write_points_spec.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/write_points_spec.rb new file mode 100644 index 0000000..e4c28cb --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/cases/write_points_spec.rb @@ -0,0 +1,184 @@ +require "spec_helper" +require "json" + +describe InfluxDB::Client do + let(:subject) do + described_class.new "database", { + host: "influxdb.test", + port: 9999, + username: "username", + password: "password", + time_precision: "s" + }.merge(args) + end + + let(:args) { {} } + + let(:database) { subject.config.database } + + describe "#write_point" do + let(:series) { "cpu" } + let(:data) do + { tags: { region: 'us', host: 'server_1' }, + values: { temp: 88, value: 54 } } + end + let(:body) do + InfluxDB::PointValue.new(data.merge(series: series)).dump + end + + before do + stub_request(:post, "http://influxdb.test:9999/write").with( + query: { u: "username", p: "password", precision: 's', db: database }, + headers: { "Content-Type" => "application/octet-stream" }, + body: body + ).to_return(status: 204) + end + + it "should POST to add single point" do + expect(subject.write_point(series, data)).to be_a(Net::HTTPNoContent) + end + + it "should not mutate data object" do + original_data = data + subject.write_point(series, data) + expect(data[:series]).to be_nil + expect(original_data).to eql(data) + end + end + + describe "#write_points" do + context "with multiple series" do + let(:data) do + [{ series: 'cpu', + tags: { region: 'us', host: 'server_1' }, + values: { temp: 88, value: 54 } }, + { series: 'gpu', + tags: { region: 'uk', host: 'server_5' }, + values: { value: 0.5435345 } }] + end + let(:body) do + data.map do |point| + InfluxDB::PointValue.new(point).dump + end.join("\n") + end + + before do + stub_request(:post, "http://influxdb.test:9999/write").with( + query: { u: "username", p: "password", precision: 's', db: database }, + headers: { "Content-Type" => "application/octet-stream" }, + body: body + ).to_return(status: 204) + end + + it "should POST multiple points" do + expect(subject.write_points(data)).to be_a(Net::HTTPNoContent) + end + end + + context "with no tags" do + let(:data) do + [{ series: 'cpu', + values: { temp: 88, value: 54 } }, + { series: 'gpu', + values: { value: 0.5435345 } }] + end + let(:body) do + data.map do |point| + InfluxDB::PointValue.new(point).dump + end.join("\n") + end + + before do + stub_request(:post, "http://influxdb.test:9999/write").with( + query: { u: "username", p: "password", precision: 's', db: database }, + headers: { "Content-Type" => "application/octet-stream" }, + body: body + ).to_return(status: 204) + end + + it "should POST multiple points" do + expect(subject.write_points(data)).to be_a(Net::HTTPNoContent) + end + end + + context "with time precision set to milisceconds" do + let(:data) do + [{ series: 'cpu', + values: { temp: 88, value: 54 }, + timestamp: (Time.now.to_f * 1000).to_i }, + { series: 'gpu', + values: { value: 0.5435345 }, + timestamp: (Time.now.to_f * 1000).to_i }] + end + + let(:body) do + data.map do |point| + InfluxDB::PointValue.new(point).dump + end.join("\n") + end + + before do + stub_request(:post, "http://influxdb.test:9999/write").with( + query: { u: "username", p: "password", precision: 'ms', db: database }, + headers: { "Content-Type" => "application/octet-stream" }, + body: body + ).to_return(status: 204) + end + it "should POST multiple points" do + expect(subject.write_points(data, 'ms')).to be_a(Net::HTTPNoContent) + end + end + + context "with retention policy" do + let(:data) do + [{ series: 'cpu', + values: { temp: 88, value: 54 } }, + { series: 'gpu', + values: { value: 0.5435345 } }] + end + + let(:body) do + data.map do |point| + InfluxDB::PointValue.new(point).dump + end.join("\n") + end + + before do + stub_request(:post, "http://influxdb.test:9999/write").with( + query: { u: "username", p: "password", precision: 's', db: database, rp: 'rp_1_hour' }, + headers: { "Content-Type" => "application/octet-stream" }, + body: body + ).to_return(status: 204) + end + it "should POST multiple points" do + expect(subject.write_points(data, nil, 'rp_1_hour')).to be_a(Net::HTTPNoContent) + end + end + + context "with database" do + let(:data) do + [{ series: 'cpu', + values: { temp: 88, value: 54 } }, + { series: 'gpu', + values: { value: 0.5435345 } }] + end + + let(:body) do + data.map do |point| + InfluxDB::PointValue.new(point).dump + end.join("\n") + end + + before do + stub_request(:post, "http://influxdb.test:9999/write").with( + query: { u: "username", p: "password", precision: 's', db: 'overriden_db' }, + headers: { "Content-Type" => "application/octet-stream" }, + body: body + ).to_return(status: 204) + end + it "should POST multiple points" do + expect(subject.write_points(data, nil, nil, 'overriden_db')).to be_a(Net::HTTPNoContent) + end + end + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/client_spec.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/client_spec.rb new file mode 100644 index 0000000..d1b0e52 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/client_spec.rb @@ -0,0 +1,120 @@ +require "spec_helper" +require "json" + +describe InfluxDB::Client do + let(:subject) do + described_class.new( + "database", + { + host: "influxdb.test", + port: 9999, + username: "username", + password: "password", + time_precision: "s" + }.merge(args) + ) + end + + let(:args) { {} } + + specify { is_expected.not_to be_stopped } + + context "with basic auth" do + let(:args) { { auth_method: 'basic_auth' } } + + let(:credentials) { "username:password" } + let(:auth_header) { { "Authorization" => "Basic " + Base64.encode64(credentials).chomp } } + + let(:stub_url) { "http://influxdb.test:9999/" } + let(:url) { subject.send(:full_url, '/') } + + it "GET" do + stub_request(:get, stub_url).with(headers: auth_header).to_return(body: '[]') + expect(subject.get(url, parse: true)).to eq [] + end + + it "POST" do + stub_request(:post, stub_url).with(headers: auth_header).to_return(status: 204) + expect(subject.post(url, {})).to be_a(Net::HTTPNoContent) + end + end + + describe "#full_url" do + it "returns String" do + expect(subject.send(:full_url, "/unknown")).to be_a String + end + + it "escapes params" do + url = subject.send(:full_url, "/unknown", value: ' !@#$%^&*()/\\_+-=?|`~') + expect(url).to include("value=+%21%40%23%24%25%5E%26%2A%28%29%2F%5C_%2B-%3D%3F%7C%60%7E") + end + + context "with prefix" do + let(:args) { { prefix: '/dev' } } + + it "returns path with prefix" do + expect(subject.send(:full_url, "/series")).to start_with("/dev") + end + end + end + + describe "GET #ping" do + it "returns OK" do + stub_request(:get, "http://influxdb.test:9999/ping") + .to_return(status: 204) + + expect(subject.ping).to be_a(Net::HTTPNoContent) + end + + context "with prefix" do + let(:args) { { prefix: '/dev' } } + + it "returns OK with prefix" do + stub_request(:get, "http://influxdb.test:9999/dev/ping") + .to_return(status: 204) + + expect(subject.ping).to be_a(Net::HTTPNoContent) + end + end + end + + describe "GET #version" do + it "returns 1.1.1" do + stub_request(:get, "http://influxdb.test:9999/ping") + .to_return(status: 204, headers: { 'x-influxdb-version' => '1.1.1' }) + + expect(subject.version).to eq('1.1.1') + end + + context "with prefix" do + let(:args) { { prefix: '/dev' } } + + it "returns 1.1.1 with prefix" do + stub_request(:get, "http://influxdb.test:9999/dev/ping") + .to_return(status: 204, headers: { 'x-influxdb-version' => '1.1.1' }) + + expect(subject.version).to eq('1.1.1') + end + end + end + + describe "Load balancing" do + let(:args) { { hosts: hosts } } + let(:hosts) do + [ + "influxdb.test0", + "influxdb.test1", + "influxdb.test2" + ] + end + let(:cycle) { 3 } + let!(:stubs) do + hosts.map { |host| stub_request(:get, "http://#{host}:9999/ping").to_return(status: 204) } + end + + it "balance requests" do + (hosts.size * cycle).times { subject.ping } + stubs.cycle(cycle) { |stub| expect(stub).to have_been_requested.times(cycle) } + end + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/config_spec.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/config_spec.rb new file mode 100644 index 0000000..8c543db --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/config_spec.rb @@ -0,0 +1,127 @@ +require 'spec_helper' + +describe InfluxDB::Config do + let(:conf) do + InfluxDB::Client.new(*args).config + end + + let(:args) { {} } + + context "with no parameters specified" do + specify { expect(conf.database).to be_nil } + specify { expect(conf.hosts).to eq ["localhost"] } + specify { expect(conf.port).to eq 8086 } + specify { expect(conf.username).to eq "root" } + specify { expect(conf.password).to eq "root" } + specify { expect(conf.use_ssl).to be_falsey } + specify { expect(conf.time_precision).to eq "s" } + specify { expect(conf.auth_method).to eq "params" } + specify { expect(conf.denormalize).to be_truthy } + specify { expect(conf).not_to be_udp } + specify { expect(conf).not_to be_async } + specify { expect(conf.epoch).to be_falsey } + end + + context "with no database specified" do + let(:args) do + [{ + host: "host", + port: "port", + username: "username", + password: "password", + time_precision: "m" + }] + end + + specify { expect(conf.database).to be_nil } + specify { expect(conf.hosts).to eq ["host"] } + specify { expect(conf.port).to eq "port" } + specify { expect(conf.username).to eq "username" } + specify { expect(conf.password).to eq "password" } + specify { expect(conf.time_precision).to eq "m" } + specify { expect(conf.epoch).to be_falsey } + end + + context "with both a database and options specified" do + let(:args) do + [ + "database", + host: "host", + port: "port", + username: "username", + password: "password", + time_precision: "m" + ] + end + + specify { expect(conf.database).to eq "database" } + specify { expect(conf.hosts).to eq ["host"] } + specify { expect(conf.port).to eq "port" } + specify { expect(conf.username).to eq "username" } + specify { expect(conf.password).to eq "password" } + specify { expect(conf.time_precision).to eq "m" } + specify { expect(conf.epoch).to be_falsey } + end + + context "with ssl option specified" do + let(:args) { [{ use_ssl: true }] } + + specify { expect(conf.database).to be_nil } + specify { expect(conf.hosts).to eq ["localhost"] } + specify { expect(conf.port).to eq 8086 } + specify { expect(conf.username).to eq "root" } + specify { expect(conf.password).to eq "root" } + specify { expect(conf.use_ssl).to be_truthy } + end + + context "with multiple hosts specified" do + let(:args) { [{ hosts: ["1.1.1.1", "2.2.2.2"] }] } + + specify { expect(conf.database).to be_nil } + specify { expect(conf.port).to eq 8086 } + specify { expect(conf.username).to eq "root" } + specify { expect(conf.password).to eq "root" } + specify { expect(conf.hosts).to eq ["1.1.1.1", "2.2.2.2"] } + end + + context "with auth_method basic auth specified" do + let(:args) { [{ auth_method: 'basic_auth' }] } + + specify { expect(conf.database).to be_nil } + specify { expect(conf.hosts).to eq ["localhost"] } + specify { expect(conf.port).to eq 8086 } + specify { expect(conf.username).to eq "root" } + specify { expect(conf.password).to eq "root" } + specify { expect(conf.auth_method).to eq "basic_auth" } + end + + context "with udp specified with params" do + let(:args) { [{ udp: { host: 'localhost', port: 4444 } }] } + + specify { expect(conf).to be_udp } + end + + context "with udp specified as true" do + let(:args) { [{ udp: true }] } + + specify { expect(conf).to be_udp } + end + + context "with async specified with params" do + let(:args) { [{ async: { max_queue: 20_000 } }] } + + specify { expect(conf).to be_async } + end + + context "with async specified as true" do + let(:args) { [{ async: true }] } + + specify { expect(conf).to be_async } + end + + context "with epoch specified as seconds" do + let(:args) { [{ epoch: 's' }] } + + specify { expect(conf.epoch).to eq 's' } + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/logging_spec.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/logging_spec.rb new file mode 100644 index 0000000..804808f --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/logging_spec.rb @@ -0,0 +1,51 @@ +require 'spec_helper' +require 'logger' + +describe InfluxDB::Logging do + class LoggerTest # :nodoc: + include InfluxDB::Logging + + def write_to_log(level, message) + log(level, message) + end + end + + around do |example| + old_logger = InfluxDB::Logging.logger + example.call + InfluxDB::Logging.logger = old_logger + end + + it "has a default logger" do + expect(InfluxDB::Logging.logger).to be_a(Logger) + end + + it "allows setting of a logger" do + new_logger = Logger.new(STDOUT) + InfluxDB::Logging.logger = new_logger + expect(InfluxDB::Logging.logger).to eq(new_logger) + end + + it "allows disabling of a logger" do + InfluxDB::Logging.logger = false + expect(InfluxDB::Logging.logger).to eql false + end + + context "when logging is disabled" do + subject { LoggerTest.new } + it "does not log" do + InfluxDB::Logging.logger = false + expect(InfluxDB::Logging.logger).not_to receive(:debug) + subject.write_to_log(:debug, 'test') + end + end + + context "when included in classes" do + subject { LoggerTest.new } + + it "logs" do + expect(InfluxDB::Logging.logger).to receive(:debug).with(an_instance_of(String)).once + subject.write_to_log(:debug, 'test') + end + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/max_queue_spec.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/max_queue_spec.rb new file mode 100644 index 0000000..2543e40 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/max_queue_spec.rb @@ -0,0 +1,29 @@ +require 'spec_helper' + +describe InfluxDB::MaxQueue do + specify { is_expected.to be_a(Queue) } + + context "#new" do + it "allows max_depth to be set" do + expect(described_class.new(500).max).to eq 500 + end + end + + context "#push" do + let(:queue) { described_class.new(5) } + + it "allows an item to be added if the queue is not full" do + expect(queue.size).to be_zero + queue.push(1) + expect(queue.size).to eq 1 + end + + it "doesn't allow items to be added if the queue is full" do + expect(queue.size).to be_zero + 5.times { |n| queue.push(n) } + expect(queue.size).to eq 5 + queue.push(6) + expect(queue.size).to eq 5 + end + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/point_value_spec.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/point_value_spec.rb new file mode 100644 index 0000000..9b44f24 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/point_value_spec.rb @@ -0,0 +1,89 @@ +# encoding: UTF-8 + +require "spec_helper" + +describe InfluxDB::PointValue do + describe "escaping" do + let(:data) do + point = { + series: '1= ,"\\1', + tags: { + '2= ,"\\2' => '3= ,"\\3' + }, + values: { + '4= ,"\\4' => '5= ,"\\5', + intval: 5, + floatval: 7.0, + invalid_encoding: "a b", + non_latin: "Улан-Удэ" + } + } + if RUBY_VERSION > "2.0.0" + # see github.com/influxdata/influxdb-ruby/issues/171 for details + point[:values][:invalid_encoding] = "a\255 b" + end + point + end + + it 'should escape correctly' do + point = InfluxDB::PointValue.new(data) + expected = %(1=\\ \\,"\\1,2\\=\\ \\,"\\2=3\\=\\ \\,"\\3 ) + + %(4\\=\\ \\,\\"\\4="5= ,\\"\\5",intval=5i,floatval=7.0,invalid_encoding="a b",non_latin="Улан-Удэ") + expect(point.dump).to eq(expected) + end + end + + describe 'dump' do + context "with all possible data passed" do + let(:expected_value) do + 'responses,region=eu,status=200 value=5i,threshold=0.54 1436349652' + end + it 'should have proper form' do + point = InfluxDB::PointValue.new(series: "responses", + values: { value: 5, threshold: 0.54 }, + tags: { region: 'eu', status: 200 }, + timestamp: 1_436_349_652) + + expect(point.dump).to eq(expected_value) + end + end + + context "with no tags" do + let(:expected_value) do + "responses value=5i,threshold=0.54 1436349652" + end + it 'should have proper form' do + point = InfluxDB::PointValue.new(series: "responses", + values: { value: 5, threshold: 0.54 }, + timestamp: 1_436_349_652) + + expect(point.dump).to eq(expected_value) + end + end + + context "with values only" do + let(:expected_value) do + "responses value=5i,threshold=0.54" + end + it 'should have proper form' do + point = InfluxDB::PointValue.new(series: "responses", + values: { value: 5, threshold: 0.54 }) + + expect(point.dump).to eq(expected_value) + end + end + + context "empty tag values" do + let(:expected_value) do + "responses,region=eu value=5i" + end + + it "should be omitted" do + point = InfluxDB::PointValue.new(series: "responses", + values: { value: 5 }, + tags: { region: "eu", status: nil, other: "", nil => "ignored", "" => "ignored" }) + expect(point.dump).to eq(expected_value) + end + end + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/query_builder_spec.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/query_builder_spec.rb new file mode 100644 index 0000000..70d7b0f --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/query_builder_spec.rb @@ -0,0 +1,63 @@ +require "spec_helper" + +RSpec.describe InfluxDB::Query::Builder do + let(:builder) { described_class.new } + + describe "#quote" do + subject { builder } + + it "should quote parameters properly" do + expect(subject.quote(3.14)).to eq "3.14" + expect(subject.quote(14)).to eq "14" + + expect(subject.quote("3.14")).to eq "'3.14'" + expect(subject.quote("Ben Hur's Carriage")).to eq "'Ben Hur\\'s Carriage'" + + expect(subject.quote(true)).to eq "true" + expect(subject.quote(false)).to eq "false" + expect(subject.quote(0 || 1)).to eq "0" + + expect(subject.quote(:symbol)).to eq "'symbol'" + + expect { subject.quote(/regex/) }.to raise_error(ArgumentError, /Unexpected parameter type Regex/) + end + end + + describe "#build" do + subject { builder.build(query, params) } + + context "named parameters" do + let(:query) { "SELECT value FROM rpm WHERE f = %{f_val} group by time(%{minutes}m)" } + let(:params) { { f_val: "value", minutes: 5 } } + + it { is_expected.to eq "SELECT value FROM rpm WHERE f = 'value' group by time(5m)" } + + context "with string keys" do + let(:params) { { "f_val" => "value", "minutes" => 5 } } + + it { is_expected.to eq "SELECT value FROM rpm WHERE f = 'value' group by time(5m)" } + end + end + + context "positional parameter" do + let(:query) { "SELECT value FROM rpm WHERE time > %{1}" } + let(:params) { [1_437_019_900] } + + it { is_expected.to eq "SELECT value FROM rpm WHERE time > 1437019900" } + end + + context "missing parameters" do + let(:query) { "SELECT value FROM rpm WHERE time > %{1}" } + let(:params) { [] } + + it { expect { subject }.to raise_error(/key.1. not found/) } + end + + context "extra parameters" do + let(:query) { "SELECT value FROM rpm WHERE time > %{a}" } + let(:params) { { "a" => 0, "b" => 2 } } + + it { is_expected.to eq "SELECT value FROM rpm WHERE time > 0" } + end + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/worker_spec.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/worker_spec.rb new file mode 100644 index 0000000..4002832 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/influxdb/worker_spec.rb @@ -0,0 +1,27 @@ +require "spec_helper" +require 'timeout' + +describe InfluxDB::Writer::Async::Worker do + let(:fake_client) { double(stopped?: false) } + let(:worker) { described_class.new(fake_client, {}) } + + describe "#push" do + let(:payload1) { "responses,region=eu value=5" } + let(:payload2) { "responses,region=eu value=6" } + let(:aggregate) { "#{payload1}\n#{payload2}" } + + it "writes aggregate payload to the client" do + queue = Queue.new + allow(fake_client).to receive(:write) do |data, _precision| + queue.push(data) + end + worker.push(payload1) + worker.push(payload2) + + Timeout.timeout(described_class::SLEEP_INTERVAL) do + result = queue.pop + expect(result).to eq aggregate + end + end + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/spec_helper.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/spec_helper.rb new file mode 100644 index 0000000..e8aadea --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/spec/spec_helper.rb @@ -0,0 +1,39 @@ +require "influxdb" +require "webmock/rspec" + +begin + # rubocop:disable Lint/HandleExceptions + require "pry-byebug" +rescue LoadError +end + +RSpec.configure do |config| + config.color = ENV["TRAVIS"] != "true" + + # rubocop:disable Style/ConditionalAssignment + if config.files_to_run.one? || ENV["TRAVIS"] == "true" + config.formatter = :documentation + else + config.formatter = :progress + end + + if ENV["LOG"] + Dir.mkdir("tmp") unless Dir.exist?("tmp") + logfile = File.open("tmp/spec.log", File::WRONLY | File::TRUNC | File::CREAT) + + InfluxDB::Logging.logger = Logger.new(logfile).tap do |logger| + logger.formatter = proc { |severity, _datetime, progname, message| + "%-5s - %s: %s\n".format severity, progname, message + } + end + + config.before(:each) do + InfluxDB::Logging.logger.info("RSpec") { self.class } + InfluxDB::Logging.logger.info("RSpec") { @__inspect_output } + end + + config.after(:each) do + logfile.write "\n" + end + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/.gemtest b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/.gemtest new file mode 100644 index 0000000..e69de29 diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/.gitignore b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/.gitignore new file mode 100644 index 0000000..79744e1 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/.gitignore @@ -0,0 +1,5 @@ +pkg/* +Gemfile.lock +coverage/* +doc/* +.yardoc diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/.rspec b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/.rspec new file mode 100644 index 0000000..8c1177f --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/.rspec @@ -0,0 +1,3 @@ +--colour +--format doc +--backtrace \ No newline at end of file diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/.travis.yml b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/.travis.yml new file mode 100644 index 0000000..e10ddff --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/.travis.yml @@ -0,0 +1,5 @@ +rvm: + - 1.9.2 + - 1.9.3 + - 2.0.0 + - jruby diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/Gemfile b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/Gemfile new file mode 100644 index 0000000..34efd14 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/Gemfile @@ -0,0 +1,2 @@ +source "http://rubygems.org" +gemspec \ No newline at end of file diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/README.md b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/README.md new file mode 100644 index 0000000..0e43a6b --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/README.md @@ -0,0 +1,132 @@ +# JsonPath + +This is an implementation of http://goessner.net/articles/JsonPath/. + +## What is JsonPath? + +JsonPath is a way of addressing elements within a JSON object. Similar to xpath of yore, JsonPath lets you +traverse a json object and manipulate or access it. + +## Usage + +### Command-line + +There is stand-alone usage through the binary `jsonpath` + + jsonpath [expression] (file|string) + + If you omit the second argument, it will read stdin, assuming one valid JSON object + per line. Expression must be a valid jsonpath expression. + +### Library + +To use JsonPath as a library simply include and get goin'! + +~~~~~ {ruby} +require 'jsonpath' + +json = <<-HERE_DOC +{"store": + {"bicycle": + {"price":19.95, "color":"red"}, + "book":[ + {"price":8.95, "category":"reference", "title":"Sayings of the Century", "author":"Nigel Rees"}, + {"price":12.99, "category":"fiction", "title":"Sword of Honour", "author":"Evelyn Waugh"}, + {"price":8.99, "category":"fiction", "isbn":"0-553-21311-3", "title":"Moby Dick", "author":"Herman Melville","color":"blue"}, + {"price":22.99, "category":"fiction", "isbn":"0-395-19395-8", "title":"The Lord of the Rings", "author":"Tolkien"} + ] + } +} +HERE_DOC +~~~~~ + +Now that we have a JSON object, let's get all the prices present in the object. We create an object for the path +in the following way. + +~~~~~ {ruby} +path = JsonPath.new('$..price') +~~~~~ + +Now that we have a path, let's apply it to the object above. + +~~~~~ {ruby} +path.on(json) +# => [19.95, 8.95, 12.99, 8.99, 22.99] +~~~~~ + +Or on some other object ... + +~~~~~ {ruby} +path.on('{"books":[{"title":"A Tale of Two Somethings","price":18.88}]}') +# => [18.88] +~~~~~ + +You can also just combine this into one mega-call with the convenient `JsonPath.on` method. + +~~~~~ {ruby} +JsonPath.on(json, '$..author') +# => ["Nigel Rees", "Evelyn Waugh", "Herman Melville", "Tolkien"] +~~~~~ + +Of course the full JsonPath syntax is supported, such as array slices + +~~~~~ {ruby} +JsonPath.new('$..book[::2]').on(json) +# => [ +# {"price"=>8.95, "category"=>"reference", "author"=>"Nigel Rees", "title"=>"Sayings of the Century"}, +# {"price"=>8.99, "category"=>"fiction", "author"=>"Herman Melville", "title"=>"Moby Dick", "isbn"=>"0-553-21311-3"} +# ] +~~~~~ + +...and evals. + +~~~~~ {ruby} +JsonPath.new('$..price[?(@ < 20)]').on(json) +# => [8.95, 8.99] +~~~~~ + +There is a convenience method, `#first` that gives you the first element for a JSON object and path. + +~~~~~ {ruby} +JsonPath.new('$..color').first(object) +# => "red" +~~~~~ + +As well, we can directly create an `Enumerable` at any time using `#[]`. + +~~~~~ {ruby} +enum = JsonPath.new('$..color')[object] +# => # +enum.first +# => "red" +enum.any?{ |c| c == 'red' } +# => true +~~~~~ + +You can optionally prevent eval from being called on sub-expressions by passing in :allow_eval => false to the constructor. + +### Manipulation + +If you'd like to do substitution in a json object, you can use `#gsub` or `#gsub!` to modify the object in place. + +~~~~~ {ruby} +JsonPath.for('{"candy":"lollipop"}').gsub('$..candy') {|v| "big turks" }.to_hash +~~~~~ + +The result will be + +~~~~~ {ruby} +{'candy' => 'big turks'} +~~~~~ + +If you'd like to remove all nil keys, you can use `#compact` and `#compact!`. To remove all keys under a certain path, use `#delete` or `#delete!`. You can even chain these methods together as follows: + +~~~~~ {ruby} +json = '{"candy":"lollipop","noncandy":null,"other":"things"}' +o = JsonPath.for(json). + gsub('$..candy') {|v| "big turks" }. + compact. + delete('$..other'). + to_hash +# => {"candy" => "big turks"} +~~~~~ diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/Rakefile b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/Rakefile new file mode 100644 index 0000000..39f6501 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/Rakefile @@ -0,0 +1,12 @@ +require 'bundler' +Bundler::GemHelper.install_tasks + +task :test do + $: << 'lib' + require 'minitest/autorun' + require 'phocus' + require 'jsonpath' + Dir['./test/**/test_*.rb'].each { |test| require test } +end + +task :default => :test \ No newline at end of file diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/bin/jsonpath b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/bin/jsonpath new file mode 100755 index 0000000..4793a6d --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/bin/jsonpath @@ -0,0 +1,22 @@ +#!/usr/bin/env ruby + +require 'jsonpath' +require 'multi_json' + +def usage + puts "jsonpath [expression] (file|string) + +If you omit the second argument, it will read stdin, assuming one valid JSON object +per line. Expression must be a valid jsonpath expression." + exit! +end + +usage unless ARGV[0] + +jsonpath = JsonPath.new(ARGV[0]) +case ARGV[1] +when nil #stdin + puts MultiJson.encode(jsonpath.on(MultiJson.decode(STDIN.read))) +when String + puts MultiJson.encode(jsonpath.on(MultiJson.decode(File.exist?(ARGV[1]) ? File.read(ARGV[1]) : ARGV[1]))) +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/jsonpath.gemspec b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/jsonpath.gemspec new file mode 100644 index 0000000..7ff16b0 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/jsonpath.gemspec @@ -0,0 +1,32 @@ +# -*- encoding: utf-8 -*- + +require File.join(File.dirname(__FILE__), 'lib', 'jsonpath', 'version') + +Gem::Specification.new do |s| + s.name = 'jsonpath' + s.version = JsonPath::VERSION + s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= + s.authors = ["Joshua Hull"] + s.summary = "Ruby implementation of http://goessner.net/articles/JsonPath/" + s.description = "Ruby implementation of http://goessner.net/articles/JsonPath/." + s.email = %q{joshbuddy@gmail.com} + s.extra_rdoc_files = ['README.md'] + s.files = `git ls-files`.split("\n") + s.homepage = %q{http://github.com/joshbuddy/jsonpath} + s.rdoc_options = ["--charset=UTF-8"] + s.require_paths = ["lib"] + s.rubygems_version = %q{1.3.7} + s.test_files = `git ls-files`.split("\n").select{|f| f =~ /^spec/} + s.rubyforge_project = 'jsonpath' + s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } + s.licenses = ['MIT'] + + # dependencies + s.add_runtime_dependency 'multi_json' + s.add_development_dependency 'code_stats' + s.add_development_dependency 'rake' + s.add_development_dependency 'minitest', '~> 2.2.0' + s.add_development_dependency 'phocus' + s.add_development_dependency 'bundler' +end + diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/lib/jsonpath.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/lib/jsonpath.rb new file mode 100644 index 0000000..82bd295 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/lib/jsonpath.rb @@ -0,0 +1,93 @@ +require 'strscan' +require 'multi_json' +require 'jsonpath/proxy' +require 'jsonpath/enumerable' +require 'jsonpath/version' + +class JsonPath + + PATH_ALL = '$..*' + + attr_accessor :path + + def initialize(path, opts = nil) + @opts = opts + scanner = StringScanner.new(path) + @path = [] + while not scanner.eos? + if token = scanner.scan(/\$/) + @path << token + elsif token = scanner.scan(/@/) + @path << token + elsif token = scanner.scan(/[a-zA-Z0-9_-]+/) + @path << "['#{token}']" + elsif token = scanner.scan(/'(.*?)'/) + @path << "[#{token}]" + elsif token = scanner.scan(/\[/) + count = 1 + while !count.zero? + if t = scanner.scan(/\[/) + token << t + count += 1 + elsif t = scanner.scan(/\]/) + token << t + count -= 1 + elsif t = scanner.scan(/[^\[\]]+/) + token << t + elsif scanner.eos? + raise ArgumentError, 'unclosed bracket' + end + end + @path << token + elsif token = scanner.scan(/\]/) + raise ArgumentError, 'unmatched closing bracket' + elsif token = scanner.scan(/\.\./) + @path << token + elsif scanner.scan(/\./) + nil + elsif token = scanner.scan(/\*/) + @path << token + elsif token = scanner.scan(/[><=] \d+/) + @path.last << token + elsif token = scanner.scan(/./) + @path.last << token + end + end + end + + def join(join_path) + res = deep_clone + res.path += JsonPath.new(join_path).path + res + end + + def on(obj_or_str) + enum_on(obj_or_str).to_a + end + + def first(obj_or_str, *args) + enum_on(obj_or_str).first(*args) + end + + def enum_on(obj_or_str, mode = nil) + JsonPath::Enumerable.new(self, self.class.process_object(obj_or_str), mode, @opts) + end + alias_method :[], :enum_on + + def self.on(obj_or_str, path, opts = nil) + self.new(path, opts).on(process_object(obj_or_str)) + end + + def self.for(obj_or_str) + Proxy.new(process_object(obj_or_str)) + end + + private + def self.process_object(obj_or_str) + obj_or_str.is_a?(String) ? MultiJson.decode(obj_or_str) : obj_or_str + end + + def deep_clone + Marshal.load Marshal.dump(self) + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/lib/jsonpath/enumerable.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/lib/jsonpath/enumerable.rb new file mode 100644 index 0000000..373ac66 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/lib/jsonpath/enumerable.rb @@ -0,0 +1,135 @@ +class JsonPath + class Enumerable + include ::Enumerable + attr_reader :allow_eval + alias_method :allow_eval?, :allow_eval + + def initialize(path, object, mode, options = nil) + @path, @object, @mode, @options = path.path, object, mode, options + @allow_eval = @options && @options.key?(:allow_eval) ? @options[:allow_eval] : true + end + + def each(context = @object, key = nil, pos = 0, &blk) + node = key ? context[key] : context + @_current_node = node + return yield_value(blk, context, key) if pos == @path.size + case expr = @path[pos] + when '*', '..' + each(context, key, pos + 1, &blk) + when '$' + each(context, key, pos + 1, &blk) if node == @object + when '@' + each(context, key, pos + 1, &blk) + when /^\[(.*)\]$/ + expr[1,expr.size - 2].split(',').each do |sub_path| + case sub_path[0] + when ?', ?" + if node.is_a?(Hash) + k = sub_path[1,sub_path.size - 2] + each(node, k, pos + 1, &blk) if node.key?(k) + end + when ?? + raise "Cannot use ?(...) unless eval is enabled" unless allow_eval? + case node + when Hash, Array + (node.is_a?(Hash) ? node.keys : (0..node.size)).each do |e| + @_current_node = node[e] + if process_function_or_literal(sub_path[1, sub_path.size - 1]) + each(@_current_node, nil, pos + 1, &blk) + end + end + else + yield node if process_function_or_literal(sub_path[1, sub_path.size - 1]) + end + else + if node.is_a?(Array) + next if node.empty? + array_args = sub_path.split(':') + if array_args[0] == ?* + start_idx = 0 + end_idx = node.size - 1 + else + start_idx = process_function_or_literal(array_args[0], 0) + next unless start_idx + end_idx = (array_args[1] && process_function_or_literal(array_args[1], -1) || (sub_path.count(':') == 0 ? start_idx : -1)) + next unless end_idx + if start_idx == end_idx + next unless start_idx < node.size + end + end + start_idx %= node.size + end_idx %= node.size + step = process_function_or_literal(array_args[2], 1) + next unless step + (start_idx..end_idx).step(step) {|i| each(node, i, pos + 1, &blk)} + end + end + end + else + if pos == (@path.size - 1) && node && allow_eval? + if eval("node #{@path[pos]}") + yield_value(blk, context, key) + end + end + end + + if pos > 0 && @path[pos-1] == '..' + case node + when Hash then node.each {|k, v| each(node, k, pos, &blk) } + when Array then node.each_with_index {|n, i| each(node, i, pos, &blk) } + end + end + end + + private + def yield_value(blk, context, key) + case @mode + when nil + blk.call(key ? context[key] : context) + when :compact + context.delete(key) if key && context[key].nil? + when :delete + context.delete(key) if key + when :substitute + if key + context[key] = blk.call(context[key]) + else + context.replace(blk.call(context[key])) + end + end + end + + def process_function_or_literal(exp, default = nil) + if exp.nil? + default + elsif exp[0] == ?( + return nil unless allow_eval? && @_current_node + identifiers = /@?(\.(\w+))+/.match(exp) + + if !identifiers.nil? && !@_current_node.methods.include?(identifiers[2].to_sym) + exp_to_eval = exp.dup + exp_to_eval[identifiers[0]] = identifiers[0].split('.').map{|el| el == '@' ? '@_current_node' : "['#{el}']"}.join + begin + return eval(exp_to_eval) + rescue StandardError # if eval failed because of bad arguments or missing methods + return default + end + end + + # otherwise eval as is + # TODO: this eval is wrong, because hash accessor could be nil and nil cannot be compared with anything, + # for instance, @_current_node['price'] - we can't be sure that 'price' are in every node, but it's only in several nodes + # I wrapped this eval into rescue returning false when error, but this eval should be refactored. + begin + eval(exp.gsub(/@/, '@_current_node')) + rescue + false + end + elsif exp.empty? + default + else + Integer(exp) + end + end + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/lib/jsonpath/proxy.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/lib/jsonpath/proxy.rb new file mode 100644 index 0000000..4e8f1b7 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/lib/jsonpath/proxy.rb @@ -0,0 +1,54 @@ +class JsonPath + class Proxy + attr_reader :obj + alias_method :to_hash, :obj + + def initialize(obj) + @obj = obj + end + + def gsub(path, replacement = nil, &replacement_block) + _gsub(_deep_copy, path, replacement ? proc{replacement} : replacement_block) + end + + def gsub!(path, replacement = nil, &replacement_block) + _gsub(@obj, path, replacement ? proc{replacement} : replacement_block) + end + + def delete(path = JsonPath::PATH_ALL) + _delete(_deep_copy, path) + end + + def delete!(path = JsonPath::PATH_ALL) + _delete(@obj, path) + end + + def compact(path = JsonPath::PATH_ALL) + _compact(_deep_copy, path) + end + + def compact!(path = JsonPath::PATH_ALL) + _compact(@obj, path) + end + + private + def _deep_copy + Marshal::load(Marshal::dump(@obj)) + end + + def _gsub(obj, path, replacement) + JsonPath.new(path)[obj, :substitute].each(&replacement) + Proxy.new(obj) + end + + def _delete(obj, path) + JsonPath.new(path)[obj, :delete].each + Proxy.new(obj) + end + + def _compact(obj, path) + JsonPath.new(path)[obj, :compact].each + Proxy.new(obj) + end + end +end \ No newline at end of file diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/lib/jsonpath/version.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/lib/jsonpath/version.rb new file mode 100644 index 0000000..b7a592a --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/lib/jsonpath/version.rb @@ -0,0 +1,3 @@ +class JsonPath + VERSION = '0.5.8' +end \ No newline at end of file diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/test/test_jsonpath.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/test/test_jsonpath.rb new file mode 100644 index 0000000..76c267b --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/test/test_jsonpath.rb @@ -0,0 +1,231 @@ +class TestJsonpath < MiniTest::Unit::TestCase + + def setup + @object = example_object + @object2 = example_object + end + + def test_bracket_matching + assert_raises(ArgumentError) { + JsonPath.new('$.store.book[0') + } + assert_raises(ArgumentError) { + JsonPath.new('$.store.book[0]]') + } + end + + def test_lookup_direct_path + assert_equal 7, JsonPath.new('$.store.*').on(@object).first['book'].size + end + + def test_lookup_missing_element + assert_equal [], JsonPath.new('$.store.book[99].price').on(@object) + end + + def test_retrieve_all_authors + assert_equal [ + @object['store']['book'][0]['author'], + @object['store']['book'][1]['author'], + @object['store']['book'][2]['author'], + @object['store']['book'][3]['author'], + @object['store']['book'][4]['author'], + @object['store']['book'][5]['author'], + @object['store']['book'][6]['author'] + ], JsonPath.new('$..author').on(@object) + end + + def test_retrieve_all_prices + assert_equal [ + @object['store']['bicycle']['price'], + @object['store']['book'][0]['price'], + @object['store']['book'][1]['price'], + @object['store']['book'][2]['price'], + @object['store']['book'][3]['price'] + ].sort, JsonPath.new('$..price').on(@object).sort + end + + def test_recognize_array_splices + assert_equal [@object['store']['book'][0], @object['store']['book'][1]], JsonPath.new('$..book[0:1:1]').on(@object) + assert_equal [@object['store']['book'][1], @object['store']['book'][3], @object['store']['book'][5]], JsonPath.new('$..book[1::2]').on(@object) + assert_equal [@object['store']['book'][0], @object['store']['book'][2], @object['store']['book'][4], @object['store']['book'][6]], JsonPath.new('$..book[::2]').on(@object) + assert_equal [@object['store']['book'][0], @object['store']['book'][2]], JsonPath.new('$..book[:-5:2]').on(@object) + assert_equal [@object['store']['book'][5], @object['store']['book'][6]], JsonPath.new('$..book[5::]').on(@object) + end + + def test_recognize_array_comma + assert_equal [@object['store']['book'][0], @object['store']['book'][1]], JsonPath.new('$..book[0,1]').on(@object) + assert_equal [@object['store']['book'][2], @object['store']['book'][6]], JsonPath.new('$..book[2,-1::]').on(@object) + end + + def test_recognize_filters + assert_equal [@object['store']['book'][2], @object['store']['book'][3]], JsonPath.new("$..book[?(@['isbn'])]").on(@object) + assert_equal [@object['store']['book'][0], @object['store']['book'][2]], JsonPath.new("$..book[?(@['price'] < 10)]").on(@object) + assert_equal [@object['store']['book'][0], @object['store']['book'][2]], JsonPath.new("$..book[?(@['price'] == 9)]").on(@object) + assert_equal [@object['store']['book'][3]], JsonPath.new("$..book[?(@['price'] > 20)]").on(@object) + end + + if RUBY_VERSION[/^1\.9/] + def test_recognize_filters_on_val + assert_equal [@object['store']['book'][1]['price'], @object['store']['book'][3]['price'], @object['store']['bicycle']['price']], JsonPath.new("$..price[?(@ > 10)]").on(@object) + end + end + + def test_no_eval + assert_equal [], JsonPath.new('$..book[(@.length-2)]', :allow_eval => false).on(@object) + end + + def test_paths_with_underscores + assert_equal [@object['store']['bicycle']['catalogue_number']], JsonPath.new('$.store.bicycle.catalogue_number').on(@object) + end + + def test_path_with_hyphens + assert_equal [@object['store']['bicycle']['single-speed']], JsonPath.new('$.store.bicycle.single-speed').on(@object) + end + + def test_paths_with_numbers + assert_equal [@object['store']['bicycle']['2seater']], JsonPath.new('$.store.bicycle.2seater').on(@object) + end + + def test_recognize_array_with_evald_index + assert_equal [@object['store']['book'][2]], JsonPath.new('$..book[(@.length-5)]').on(@object) + end + + def test_use_first + assert_equal @object['store']['book'][2], JsonPath.new('$..book[(@.length-5)]').first(@object) + end + + def test_counting + assert_equal 49, JsonPath.new('$..*').on(@object).to_a.size + end + + def test_space_in_path + assert_equal ['e'], JsonPath.new("$.'c d'").on({"a" => "a","b" => "b", "c d" => "e"}) + end + + def test_class_method + assert_equal JsonPath.new('$..author').on(@object), JsonPath.on(@object, '$..author') + end + + def test_join + assert_equal JsonPath.new('$.store.book..author').on(@object), JsonPath.new('$.store').join('book..author').on(@object) + end + + def test_gsub + @object2['store']['bicycle']['price'] += 10 + @object2['store']['book'][0]['price'] += 10 + @object2['store']['book'][1]['price'] += 10 + @object2['store']['book'][2]['price'] += 10 + @object2['store']['book'][3]['price'] += 10 + assert_equal @object2, JsonPath.for(@object).gsub('$..price') { |p| p + 10 }.to_hash + end + + def test_gsub! + JsonPath.for(@object).gsub!('$..price') { |p| p + 10 } + assert_equal 30, @object['store']['bicycle']['price'] + assert_equal 19, @object['store']['book'][0]['price'] + assert_equal 23, @object['store']['book'][1]['price'] + assert_equal 19, @object['store']['book'][2]['price'] + assert_equal 33, @object['store']['book'][3]['price'] + end + + def test_weird_gsub! + h = {'hi' => 'there'} + JsonPath.for(@object).gsub!('$.*') { |n| h } + assert_equal h, @object + end + + def test_compact + h = {'hi' => 'there', 'you' => nil} + JsonPath.for(h).compact! + assert_equal({'hi' => 'there'}, h) + end + + def test_delete + h = {'hi' => 'there', 'you' => nil} + JsonPath.for(h).delete!('*.hi') + assert_equal({'you' => nil}, h) + end + + def test_wildcard + assert_equal @object['store']['book'].collect{|e| e['price']}.compact, JsonPath.on(@object, '$..book[*].price') + end + + def test_wildcard_empty_array + object = @object.merge("bicycle" => { "tire" => [] }) + assert_equal [], JsonPath.on(object, "$..bicycle.tire[*]") + end + + def test_support_filter_by_childnode_value + assert_equal [@object['store']['book'][3]], JsonPath.new("$..book[?(@.price > 20)]").on(@object) + end + + def test_support_filter_by_childnode_value_with_inconsistent_children + @object['store']['book'][0] = "string_instead_of_object" + assert_equal [@object['store']['book'][3]], JsonPath.new("$..book[?(@.price > 20)]").on(@object) + end + + def test_support_filter_by_childnode_value_and_select_child_key + assert_equal [23], JsonPath.new("$..book[?(@.price > 20)].price").on(@object) + end + + def test_support_filter_by_childnode_value_over_childnode_and_select_child_key + assert_equal ["Osennie Vizity"], JsonPath.new("$..book[?(@.written.year == 1996)].title").on(@object) + end + + def example_object + { "store"=> { + "book" => [ + { "category"=> "reference", + "author"=> "Nigel Rees", + "title"=> "Sayings of the Century", + "price"=> 9 + }, + { "category"=> "fiction", + "author"=> "Evelyn Waugh", + "title"=> "Sword of Honour", + "price"=> 13 + }, + { "category"=> "fiction", + "author"=> "Herman Melville", + "title"=> "Moby Dick", + "isbn"=> "0-553-21311-3", + "price"=> 9 + }, + { "category"=> "fiction", + "author"=> "J. R. R. Tolkien", + "title"=> "The Lord of the Rings", + "isbn"=> "0-395-19395-8", + "price"=> 23 + }, + { "category"=> "russian_fiction", + "author"=> "Lukyanenko", + "title"=> "Imperatory Illuziy", + "written" => { + "year" => 1995 + } + }, + { "category"=> "russian_fiction", + "author"=> "Lukyanenko", + "title"=> "Osennie Vizity", + "written" => { + "year" => 1996 + } + }, + { "category"=> "russian_fiction", + "author"=> "Lukyanenko", + "title"=> "Ne vremya dlya drakonov", + "written" => { + "year" => 1997 + } + } + ], + "bicycle"=> { + "color"=> "red", + "price"=> 20, + "catalogue_number" => 12345, + "single-speed" => "no", + "2seater" => "yes"} + } } + end + +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/test/test_jsonpath_bin.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/test/test_jsonpath_bin.rb new file mode 100644 index 0000000..626a119 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/jsonpath-0.5.8/test/test_jsonpath_bin.rb @@ -0,0 +1,21 @@ +class TestJsonpathBin < MiniTest::Unit::TestCase + def setup + @runner = "ruby -Ilib bin/jsonpath" + @original_dir = Dir.pwd + Dir.chdir(File.join(File.dirname(__FILE__), '..')) + end + + def teardown + Dir.chdir(@original_dir) + `rm /tmp/test.json` + end + + def test_stdin + assert_equal '["time"]', `echo '{"test": "time"}' | #{@runner} '$.test'`.strip + end + + def test_stdin + File.open('/tmp/test.json', 'w'){|f| f << '{"test": "time"}'} + assert_equal '["time"]', `#{@runner} '$.test' /tmp/test.json`.strip + end +end \ No newline at end of file diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/linux-kstat-0.1.3-universal-linux/CHANGES b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/linux-kstat-0.1.3-universal-linux/CHANGES new file mode 100644 index 0000000..f909654 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/linux-kstat-0.1.3-universal-linux/CHANGES @@ -0,0 +1,11 @@ += 0.1.3 - 18-Dec-2014 +* Now properly ignores blank lines. Thanks go to "onlinehead" for the patch. + += 0.1.2 - 2-Nov-2014 +* Updates to the gemspec and Rakefile. + += 0.1.1 - 20-May-2011 +* Set the spec platform to 'universal-linux'. + += 0.1.0 - 10-Feb-2011 +* Initial release. diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/linux-kstat-0.1.3-universal-linux/MANIFEST b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/linux-kstat-0.1.3-universal-linux/MANIFEST new file mode 100644 index 0000000..0a6c769 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/linux-kstat-0.1.3-universal-linux/MANIFEST @@ -0,0 +1,7 @@ +* CHANGES +* README +* MANIFEST +* Rakefile +* linux-kstat.gemspec +* lib/linux/kstat.rb +* test/test_linux_kstat.rb diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/linux-kstat-0.1.3-universal-linux/README b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/linux-kstat-0.1.3-universal-linux/README new file mode 100644 index 0000000..6ab49cb --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/linux-kstat-0.1.3-universal-linux/README @@ -0,0 +1,43 @@ += Description + A Ruby library for gathering Linux kernel statistics out of /proc/stat. + += Installation + gem install linux-kstat + += Synopsis + require 'linux/kstat' + + kstat = Linux::Kstat.new + + p kstat[:cpu] + p kstat[:procs_running] + += Details + The values for most of the keys are a single numeric value. However, in the + case of "cpu" keys, the result is a 7 element hash of numeric values. In + the case of the "intr" key, the value is an array containing the list of + interrupts. + += Information about /proc/stat + See http://www.linuxhowtos.org/System/procstat.htm for more information + about the meaning of each of the fields. + += Known Bugs + None known. Please report any bugs on the github project page. + + http://www.github.com/djberg96/linux-kstat + += License + Artistic 2.0 + += Copyright + (C) 2003-2014 Daniel J. Berger + All Rights Reserved.` + += Warranty + This package is provided "as is" and without any express or + implied warranties, including, without limitation, the implied + warranties of merchantability and fitness for a particular purpose. + += Author + Daniel J. Berger diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/linux-kstat-0.1.3-universal-linux/Rakefile b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/linux-kstat-0.1.3-universal-linux/Rakefile new file mode 100644 index 0000000..a8bc277 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/linux-kstat-0.1.3-universal-linux/Rakefile @@ -0,0 +1,36 @@ +require 'rake' +require 'rake/clean' +require 'rake/testtask' + +CLEAN.include('**/*.gem', '**/*.rbc') + +namespace :gem do + desc 'Build the linux-kstat gem' + task :create => [:clean] do + spec = eval(IO.read('linux-kstat.gemspec')) + if Gem::VERSION < "2.0" + Gem::Builder.new(spec).build + else + require 'rubygems/package' + Gem::Package.build(spec) + end + end + + desc "Install the linux-kstat gem" + task :install => [:create] do + file = Dir["*.gem"].first + if RUBY_PLATFORM == 'java' + sh "jruby -S gem install -l #{file}" + else + sh "gem install -l #{file}" + end + end +end + +Rake::TestTask.new do |t| + task :test => :clean + t.warning = true + t.verbose = true +end + +task :default => :test diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/linux-kstat-0.1.3-universal-linux/lib/linux/kstat.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/linux-kstat-0.1.3-universal-linux/lib/linux/kstat.rb new file mode 100644 index 0000000..19607c5 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/linux-kstat-0.1.3-universal-linux/lib/linux/kstat.rb @@ -0,0 +1,78 @@ +require 'forwardable' + +# The Linux module serves as a namespace only. +module Linux + # The Kstat class encapsulates Linux kernel statistics derived from /proc/stat. + class Kstat + extend Forwardable + + # The version of the linux-kstat library + VERSION = '0.1.3' + + # :stopdoc: + + # Delegate the the [] and inspect methods to the @hash variable + def_delegator(:@hash, :[]) + def_delegator(:@hash, :inspect) + + # :startdoc: + + # Create a new Linux::Kstat instance. You can access the information + # stored in this object the same way you would access a hash key. Note + # that all keys are symbols. + # + # Example: + # + # kstat = Linux::Kstat.new + # + # kstat[:cpu] => { + # :idle => 250713454, + # :iowait => 2745691, + # :irq => 39717, + # :softirq => 31323, + # :system => 1881655, + # :nice => 117158, + # :user => 7137418 + # } + # + # kstat[:processes] # => 1299560 + # + def initialize + @hash = get_proc_stat_info + end + + private + + # Parse the information out of /proc/stat and assign keys and values to + # a hash that can be accessed via the Forwardable module. + # + def get_proc_stat_info + hash = {} + + IO.readlines('/proc/stat').each{ |line| + info = line.split + unless info.empty? + if info.first =~ /^cpu/i + hash[info.first.to_sym] = { + :user => info[1].to_i, + :nice => info[2].to_i, + :system => info[3].to_i, + :idle => info[4].to_i, + :iowait => info[5].to_i, + :irq => info[6].to_i, + :softirq => info[7].to_i + } + else + if info.size > 2 + hash[info.first.to_sym] = info[1..-1].map{ |e| e.to_i } + else + hash[info.first.to_sym] = info[1].to_i + end + end + end + } + + hash + end + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/linux-kstat-0.1.3-universal-linux/linux-kstat.gemspec b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/linux-kstat-0.1.3-universal-linux/linux-kstat.gemspec new file mode 100644 index 0000000..b126fa5 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/linux-kstat-0.1.3-universal-linux/linux-kstat.gemspec @@ -0,0 +1,24 @@ +require 'rubygems' +require 'rbconfig' + +Gem::Specification.new do |gem| + gem.name = 'linux-kstat' + gem.version = '0.1.3' + gem.license = 'Artistic 2.0' + gem.author = 'Daniel J. Berger' + gem.email = 'djberg96@gmail.com' + gem.platform = Gem::Platform.new('universal-linux') + gem.homepage = 'https://github.com/djberg96/linux-kstat' + gem.summary = 'Ruby interface for Linux kernel stats in /proc/stat' + gem.test_files = Dir['test/test*'] + gem.files = Dir['**/*'].reject{ |f| f.include?('git') } + + gem.extra_rdoc_files = ['README', 'CHANGES', 'MANIFEST'] + + gem.add_development_dependency('test-unit', '>= 2.5.0') + + gem.description = <<-EOF + The linux-kstat library provides a hash style interface for reading + Linux kernel statistics read out of /proc/stat. + EOF +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/linux-kstat-0.1.3-universal-linux/test/test_linux_kstat.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/linux-kstat-0.1.3-universal-linux/test/test_linux_kstat.rb new file mode 100644 index 0000000..63c2ffe --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/linux-kstat-0.1.3-universal-linux/test/test_linux_kstat.rb @@ -0,0 +1,36 @@ +####################################################################### +# test_linux_kstat.rb +# +# Test suite for the linux-kstat library. +####################################################################### +require 'test-unit' +require 'linux/kstat' + +class TC_Linux_Kstat < Test::Unit::TestCase + def setup + @kstat = Linux::Kstat.new + end + + test "version constant is set to the expected value" do + assert_equal('0.1.3', Linux::Kstat::VERSION) + end + + test "kstat object can be accessed like a hash" do + assert_respond_to(@kstat, :[]) + assert_nothing_raised{ @kstat[:cpu] } + end + + test "kstat object contains expected keys" do + assert_kind_of(Hash, @kstat[:cpu]) + assert_kind_of(Numeric, @kstat[:btime]) + assert_kind_of(Array, @kstat[:intr]) + end + + test "values cannot be assigned to keys" do + assert_raise(NoMethodError){ @kstat[:cpu] = 'test' } + end + + def teardown + @kstat = nil + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/CHANGELOG.md b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/CHANGELOG.md new file mode 100644 index 0000000..8b98307 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/CHANGELOG.md @@ -0,0 +1,245 @@ +1.12.1 +------ + +* [Prevent meory leak in OptionsCache](https://github.com/intridea/multi_json/commit/aa7498199ad272f3d4a13750d7c568a66047e2ee) + +1.12.0 +------ + +* [Introduce global options cache to improve peroformance](https://github.com/intridea/multi_json/commit/7aaef2a1bc2b83c95e4208b12dad5d1d87ff20a6) + +1.11.2 +------ + +* [Only pass one argument to JrJackson when two is not supported](https://github.com/intridea/multi_json/commit/e798fa517c817fc706982d3f3c61129b6651d601) + +1.11.1 +------ + +* [Dump method passes options throught for JrJackson adapter](https://github.com/intridea/multi_json/commit/3c730fd12135c3e7bf212f878958004908f13909) + +1.11.0 +------ + +* [Make all adapters read IO object before load](https://github.com/intridea/multi_json/commit/167f559e18d4efee05e1f160a2661d16dbb215d4) + +1.10.1 +------ +* [Explicitly require stringio for Gson adapter](https://github.com/intridea/multi_json/commit/623ec8142d4a212fa0db763bb71295789a119929) +* [Do not read StringIO object before passing it to JrJackson](https://github.com/intridea/multi_json/commit/a6dc935df08e7b3d5d701fbb9298384c96df0fde) + +1.10.0 +------ +* [Performance tweaks](https://github.com/intridea/multi_json/commit/58724acfed31866d079eaafb1cd824e341ade287) + +1.9.3 +----- +* [Convert indent option to Fixnum before passing to Oj](https://github.com/intridea/multi_json/commit/826fc5535b863b74fc9f981dfdda3e26f1ee4e5b) + +1.9.2 +----- +* [Enable use_to_json option for Oj adapter by default](https://github.com/intridea/multi_json/commit/76a4aaf697b10bbabd5d535d83cf1149efcfe5c7) + +1.9.1 +----- +* [Remove unused LoadError file](https://github.com/intridea/multi_json/commit/65dedd84d59baeefc25c477fedf0bbe85e7ce2cd) + +1.9.0 +---- +* [Rename LoadError to ParseError](https://github.com/intridea/multi_json/commit/4abb98fe3a90b2a7b3d1594515c8a06042b4a27d) +* [Adapter load failure throws AdapterError instead of ArgumentError](https://github.com/intridea/multi_json/commit/4da612b617bd932bb6fa1cc4c43210327f98f271) + +1.8.4 +----- +* [Make Gson adapter explicitly read StringIO object](https://github.com/intridea/multi_json/commit/b58b498747ff6e94f41488c971b2a30a98760ef2) + +1.8.3 +----- +* [Make JrJackson explicitly read StringIO objects](https://github.com/intridea/multi_json/commit/e1f162d5b668e5e4db5afa175361a601a8aa2b05) +* [Prevent calling #downcase on alias symbols](https://github.com/intridea/multi_json/commit/c1cf075453ce0110f7decc4f906444b1233bb67c) + +1.8.2 +----- +* [Downcase adapter string name for OS compatibility](https://github.com/intridea/multi_json/commit/b8e15a032247a63f1410d21a18add05035f3fa66) + +1.8.1 +----- +* [Let the adapter handle strings with invalid encoding](https://github.com/intridea/multi_json/commit/6af2bf87b89f44eabf2ae9ca96779febc65ea94b) + +1.8.0 +----- +* [Raise MultiJson::LoadError on blank input](https://github.com/intridea/multi_json/commit/c44f9c928bb25fe672246ad394b3e5b991be32e6) + +1.7.9 +----- +* [Explicitly require json gem code even when constant is defined](https://github.com/intridea/multi_json/commit/36f7906c66477eb4b55b7afeaa3684b6db69eff2) + +1.7.8 +----- +* [Reorder JrJackson before json_gem](https://github.com/intridea/multi_json/commit/315b6e460b6e4dcdb6c82e04e4be8ee975d395da) +* [Update vendored OkJson to version 43](https://github.com/intridea/multi_json/commit/99a6b662f6ef4036e3ee94d7eb547fa72fb2ab50) + +1.7.7 +----- +* [Fix options caching issues](https://github.com/intridea/multi_json/commit/a3f14c3661688c5927638fa6088c7b46a67e875e) + +1.7.6 +----- +* [Bring back MultiJson::VERSION constant](https://github.com/intridea/multi_json/commit/31b990c2725e6673bf8ce57540fe66b57a751a72) + +1.7.5 +----- +* [Fix warning '*' interpreted as argument prefix](https://github.com/intridea/multi_json/commit/b698962c7f64430222a1f06430669706a47aff89) +* [Remove stdlib warning](https://github.com/intridea/multi_json/commit/d06eec6b7996ac8b4ff0e2229efd835379b0c30f) + +1.7.4 +----- +* [Cache options for better performance](https://github.com/intridea/multi_json/commit/8a26ee93140c4bed36194ed9fb887a1b6919257b) + +1.7.3 +----- +* [Require json/ext to ensure extension version gets loaded for json_gem](https://github.com/intridea/multi_json/commit/942686f7e8597418c6f90ee69e1d45242fac07b1) +* [Rename JrJackson](https://github.com/intridea/multi_json/commit/078de7ba8b6035343c3e96b4767549e9ec43369a) +* [Prefer JrJackson to JSON gem if present](https://github.com/intridea/multi_json/commit/af8bd9799a66855f04b3aff1c488485950cec7bf) +* [Print a warning if outdated gem versions are used](https://github.com/intridea/multi_json/commit/e7438e7ba2be0236cfa24c2bb9ad40ee821286d1) +* [Loosen required_rubygems_version for compatibility with Ubuntu 10.04](https://github.com/intridea/multi_json/commit/59fad014e8fe41dbc6f09485ea0dc21fc42fd7a7) + +1.7.2 +----- +* [Rename Jrjackson adapter to JrJackson](https://github.com/intridea/multi_json/commit/b36dc915fc0e6548cbad06b5db6f520e040c9c8b) +* [Implement jrjackson -> jr_jackson alias for back-compatability](https://github.com/intridea/multi_json/commit/aa50ab8b7bb646b8b75d5d65dfeadae8248a4f10) +* [Update vendored OkJson module](https://github.com/intridea/multi_json/commit/30a3f474e17dd86a697c3fab04f468d1a4fd69d7) + +1.7.1 +----- +* [Fix capitalization of JrJackson class](https://github.com/intridea/multi_json/commit/5373a5e38c647f02427a0477cb8e0e0dafad1b8d) + +1.7.0 +----- +* [Add load_options/dump_options to MultiJson](https://github.com/intridea/multi_json/commit/a153956be6b0df06ea1705ce3c1ff0b5b0e27ea5) +* [MultiJson does not modify arguments](https://github.com/intridea/multi_json/commit/58525b01c4c2f6635ba2ac13d6fd987b79f3962f) +* [Enable quirks_mode by default for json_gem/json_pure adapters](https://github.com/intridea/multi_json/commit/1fd4e6635c436515b7d7d5a0bee4548de8571520) +* [Add JrJackson adapter](https://github.com/intridea/multi_json/commit/4dd86fa96300aaaf6d762578b9b31ea82adb056d) +* [Raise ArgumentError on bad adapter input](https://github.com/intridea/multi_json/commit/911a3756bdff2cb5ac06497da3fa3e72199cb7ad) + +1.6.1 +----- +* [Revert "Use JSON.generate instead of #to_json"](https://github.com/intridea/multi_json/issues/86) + +1.6.0 +----- +* [Add gson.rb support](https://github.com/intridea/multi_json/pull/71) +* [Add MultiJson.default_options](https://github.com/intridea/multi_json/pull/70) +* [Add MultiJson.with_adapter](https://github.com/intridea/multi_json/pull/67) +* [Stringify all possible keys for ok_json](https://github.com/intridea/multi_json/pull/66) +* [Use JSON.generate instead of #to_json](https://github.com/intridea/multi_json/issues/73) +* [Alias `MultiJson::DecodeError` to `MultiJson::LoadError`](https://github.com/intridea/multi_json/pull/79) + +1.5.1 +----- +* [Do not allow Oj or JSON to create symbols by searching for classes](https://github.com/intridea/multi_json/commit/193e28cf4dc61b6e7b7b7d80f06f74c76df65c41) + +1.5.0 +----- +* [Add `MultiJson.with_adapter` method](https://github.com/intridea/multi_json/commit/d14c5d28cae96557a0421298621b9499e1f28104) +* [Stringify all possible keys for `ok_json`](https://github.com/intridea/multi_json/commit/73998074058e1e58c557ffa7b9541d486d6041fa) + +1.4.0 +----- +* [Allow `load`/`dump` of JSON fragments](https://github.com/intridea/multi_json/commit/707aae7d48d39c85b38febbd2c210ba87f6e4a36) + +1.3.7 +----- +* [Fix rescue clause for MagLev](https://github.com/intridea/multi_json/commit/39abdf50199828c50e85b2ce8f8ba31fcbbc9332) +* [Remove unnecessary check for string version of options key](https://github.com/intridea/multi_json/commit/660101b70e962b3c007d0b90d45944fa47d13ec4) +* [Explicitly set default adapter when adapter is set to `nil` or `false`](https://github.com/intridea/multi_json/commit/a9e587d5a63eafb4baee9fb211265e4dd96a26bc) +* [Fix Oj `ParseError` mapping for Oj 1.4.0](https://github.com/intridea/multi_json/commit/7d9045338cc9029401c16f3c409d54ce97f275e2) + +1.3.6 +----- +* [Allow adapter-specific options to be passed through to Oj](https://github.com/intridea/multi_json/commit/d0e5feeebcba0bc69400dd203a295f5c30971223) + +1.3.5 +----- +* [Add pretty support to Oj adapter](https://github.com/intridea/multi_json/commit/0c8f75f03020c53bcf4c6be258faf433d24b2c2b) + +1.3.4 +----- +* [Use `class << self` instead of `module_function` to create aliases](https://github.com/intridea/multi_json/commit/ba1451c4c48baa297e049889be241a424cb05980) + +1.3.3 +----- +* [Remove deprecation warnings](https://github.com/intridea/multi_json/commit/36b524e71544eb0186826a891bcc03b2820a008f) + +1.3.2 +----- +* [Add ability to use adapter per call](https://github.com/intridea/multi_json/commit/106bbec469d5d0a832bfa31fffcb8c0f0cdc9bd3) +* [Add and deprecate `default_engine` method](https://github.com/intridea/multi_json/commit/fc3df0c7a3e2ab9ce0c2c7e7617a4da97dd13f6e) + +1.3.1 +----- +* [Only warn once for each instance a deprecated method is called](https://github.com/intridea/multi_json/commit/e21d6eb7da74b3f283995c1d27d5880e75f0ae84) + +1.3.0 +----- +* [Implement `load`/`dump`; deprecate `decode`/`encode`](https://github.com/intridea/multi_json/commit/e90fd6cb1b0293eb0c73c2f4eb0f7a1764370216) +* [Rename engines to adapters](https://github.com/intridea/multi_json/commit/ae7fd144a7949a9c221dcaa446196ec23db908df) + +1.2.0 +----- +* [Add support for Oj](https://github.com/intridea/multi_json/commit/acd06b233edabe6c44f226873db7b49dab560c60) + +1.1.0 +----- +* [`NSJSONSerialization` support for MacRuby](https://github.com/intridea/multi_json/commit/f862e2fc966cac8867fe7da3997fc76e8a6cf5d4) + +1.0.4 +----- +* [Set data context to `DecodeError` exception](https://github.com/intridea/multi_json/commit/19ddafd44029c6681f66fae2a0f6eabfd0f85176) +* [Allow `ok_json` to fallback to `to_json`](https://github.com/intridea/multi_json/commit/c157240b1193b283d06d1bd4d4b5b06bcf3761f8) +* [Add warning when using `ok_json`](https://github.com/intridea/multi_json/commit/dd4b68810c84f826fb98f9713bfb29ab96888d57) +* [Options can be passed to an engine on encode](https://github.com/intridea/multi_json/commit/e0a7ff5d5ff621ffccc61617ed8aeec5816e81f7) + +1.0.3 +----- +* [`Array` support for `stringify_keys`](https://github.com/intridea/multi_json/commit/644d1c5c7c7f6a27663b11668527b346094e38b9) +* [`Array` support for `symbolize_keys`](https://github.com/intridea/multi_json/commit/c885377d47a2aa39cb0d971fea78db2d2fa479a7) + +1.0.2 +----- +* [Allow encoding of rootless JSON when `ok_json` is used](https://github.com/intridea/multi_json/commit/d1cde7de97cb0f6152aef8daf14037521cdce8c6) + +1.0.1 +----- +* [Correct an issue with `ok_json` not being returned as the default engine](https://github.com/intridea/multi_json/commit/d33c141619c54cccd770199694da8fd1bd8f449d) + +1.0.0 +----- +* [Remove `ActiveSupport::JSON` support](https://github.com/intridea/multi_json/commit/c2f4140141d785a24b3f56e58811b0e561b37f6a) +* [Fix `@engine` ivar warning](https://github.com/intridea/multi_json/commit/3b978a8995721a8dffedc3b75a7f49e5494ec553) +* [Only `rescue` from parsing errors during decoding, not any `StandardError`](https://github.com/intridea/multi_json/commit/391d00b5e85294d42d41347605d8d46b4a7f66cc) +* [Rename `okjson` engine and vendored lib to `ok_json`](https://github.com/intridea/multi_json/commit/5bd1afc977a8208ddb0443e1d57cb79665c019f1) +* [Add `StringIO` support to `json` gem and `ok_json`](https://github.com/intridea/multi_json/commit/1706b11568db7f50af451fce5f4d679aeb3bbe8f) + +0.0.5 +----- +* [Trap all JSON decoding errors; raise `MultiJson::DecodeError`](https://github.com/intridea/multi_json/commit/dea9a1aef6dd1212aa1e5a37ab1669f9b045b732) + +0.0.4 +----- +* [Fix default_engine check for `json` gem](https://github.com/intridea/multi_json/commit/caced0c4e8c795922a109ebc00c3c4fa8635bed8) +* [Make requirement mapper an `Array` to preserve order in Ruby versions < 1.9](https://github.com/intridea/multi_json/commit/526f5f29a42131574a088ad9bbb43d7f48439b2c) + +0.0.3 +----- +* [Improve defaulting and documentation](https://github.com/sferik/twitter/commit/3a0e41b9e4b0909201045fa47704b78c9d949b73) + +0.0.2 +----- + +* [Rename to `multi_json`](https://github.com/sferik/twitter/commit/461ab89ce071c8c9fabfc183581e0ec523788b62) + +0.0.1 +----- + +* [Initial commit](https://github.com/sferik/twitter/commit/518c21ab299c500527491e6c049ab2229e22a805) diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/CONTRIBUTING.md b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/CONTRIBUTING.md new file mode 100644 index 0000000..3e8bfd5 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/CONTRIBUTING.md @@ -0,0 +1,46 @@ +## Contributing +In the spirit of [free software][free-sw], **everyone** is encouraged to help +improve this project. + +[free-sw]: http://www.fsf.org/licensing/essays/free-sw.html + +Here are some ways *you* can contribute: + +* by using alpha, beta, and prerelease versions +* by reporting bugs +* by suggesting new features +* by writing or editing documentation +* by writing specifications +* by writing code (**no patch is too small**: fix typos, add comments, clean up + inconsistent whitespace) +* by refactoring code +* by closing [issues][] +* by reviewing patches + +[issues]: https://github.com/intridea/multi_json/issues + +## Submitting an Issue +We use the [GitHub issue tracker][issues] to track bugs and features. Before +submitting a bug report or feature request, check to make sure it hasn't +already been submitted. When submitting a bug report, please include a [Gist][] +that includes a stack trace and any details that may be necessary to reproduce +the bug, including your gem version, Ruby version, and operating system. +Ideally, a bug report should include a pull request with failing specs. + +[gist]: https://gist.github.com/ + +## Submitting a Pull Request +1. [Fork the repository.][fork] +2. [Create a topic branch.][branch] +3. Add specs for your unimplemented feature or bug fix. +4. Run `bundle exec rake spec`. If your specs pass, return to step 3. +5. Implement your feature or bug fix. +6. Run `bundle exec rake spec`. If your specs fail, return to step 5. +7. Run `open coverage/index.html`. If your changes are not completely covered + by your tests, return to step 3. +8. Add, commit, and push your changes. +9. [Submit a pull request.][pr] + +[fork]: http://help.github.com/fork-a-repo/ +[branch]: http://learn.github.com/p/branching.html +[pr]: http://help.github.com/send-pull-requests/ diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/LICENSE.md b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/LICENSE.md new file mode 100644 index 0000000..1768f37 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/LICENSE.md @@ -0,0 +1,20 @@ +Copyright (c) 2010-2013 Michael Bleigh, Josh Kalderimis, Erik Michaels-Ober, Pavel Pravosud + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/README.md b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/README.md new file mode 100644 index 0000000..ee8b86e --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/README.md @@ -0,0 +1,121 @@ +# MultiJSON + +[![Gem Version](http://img.shields.io/gem/v/multi_json.svg)][gem] +[![Build Status](http://travis-ci.org/intridea/multi_json.svg)][travis] +[![Dependency Status](http://img.shields.io/gemnasium/intridea/multi_json.svg)][gemnasium] +[![Code Climate](http://img.shields.io/codeclimate/github/intridea/multi_json.svg)][codeclimate] + +[gem]: https://rubygems.org/gems/multi_json +[travis]: http://travis-ci.org/intridea/multi_json +[gemnasium]: https://gemnasium.com/intridea/multi_json +[codeclimate]: https://codeclimate.com/github/intridea/multi_json + +Lots of Ruby libraries parse JSON and everyone has their favorite JSON coder. +Instead of choosing a single JSON coder and forcing users of your library to be +stuck with it, you can use MultiJSON instead, which will simply choose the +fastest available JSON coder. Here's how to use it: + +```ruby +require 'multi_json' + +MultiJson.load('{"abc":"def"}') #=> {"abc" => "def"} +MultiJson.load('{"abc":"def"}', :symbolize_keys => true) #=> {:abc => "def"} +MultiJson.dump({:abc => 'def'}) # convert Ruby back to JSON +MultiJson.dump({:abc => 'def'}, :pretty => true) # encoded in a pretty form (if supported by the coder) +``` + +When loading invalid JSON, MultiJson will throw a `MultiJson::ParseError`. `MultiJson::DecodeError` and `MultiJson::LoadError` are aliases for backwards compatibility. + +```ruby +begin + MultiJson.load('{invalid json}') +rescue MultiJson::ParseError => exception + exception.data # => "{invalid json}" + exception.cause # => JSON::ParserError: 795: unexpected token at '{invalid json}' +end +``` + +`ParseError` instance has `cause` reader which contains the original exception. +It also has `data` reader with the input that caused the problem. + +The `use` method, which sets the MultiJson adapter, takes either a symbol or a +class (to allow for custom JSON parsers) that responds to both `.load` and `.dump` +at the class level. + +When MultiJson fails to load the specified adapter, it'll throw `MultiJson::AdapterError` +which inherits from `ArgumentError`. + +MultiJSON tries to have intelligent defaulting. That is, if you have any of the +supported engines already loaded, it will utilize them before attempting to +load any. When loading, libraries are ordered by speed. First Oj, then Yajl, +then the JSON gem, then JSON pure. If no other JSON library is available, +MultiJSON falls back to [OkJson][], a simple, vendorable JSON parser. + +[okjson]: https://github.com/kr/okjson + +## Supported JSON Engines + +* [Oj](https://github.com/ohler55/oj) Optimized JSON by Peter Ohler +* [Yajl](https://github.com/brianmario/yajl-ruby) Yet Another JSON Library by Brian Lopez +* [JSON](https://github.com/flori/json) The default JSON gem with C-extensions (ships with Ruby 1.9) +* [JSON Pure](https://github.com/flori/json) A Ruby variant of the JSON gem +* [NSJSONSerialization](https://developer.apple.com/library/ios/#documentation/Foundation/Reference/NSJSONSerialization_Class/Reference/Reference.html) Wrapper for Apple's NSJSONSerialization in the Cocoa Framework (MacRuby only) +* [gson.rb](https://github.com/avsej/gson.rb) A Ruby wrapper for google-gson library (JRuby only) +* [JrJackson](https://github.com/guyboertje/jrjackson) JRuby wrapper for Jackson (JRuby only) +* [OkJson][okjson] A simple, vendorable JSON parser + +## Supported Ruby Versions +This library aims to support and is [tested against][travis] the following Ruby +implementations: + +* Ruby 1.8.7 +* Ruby 1.9.2 +* Ruby 1.9.3 +* Ruby 2.0.0 +* Ruby 2.1 +* Ruby 2.2.4 +* Ruby 2.3.1 +* [JRuby][] +* [Rubinius][] +* [MacRuby][] (not tested on Travis CI) + +[jruby]: http://www.jruby.org/ +[rubinius]: http://rubini.us/ +[macruby]: http://www.macruby.org/ + +If something doesn't work on one of these interpreters, it's a bug. + +This library may inadvertently work (or seem to work) on other Ruby +implementations, however support will only be provided for the versions listed +above. + +If you would like this library to support another Ruby version, you may +volunteer to be a maintainer. Being a maintainer entails making sure all tests +run and pass on that implementation. When something breaks on your +implementation, you will be responsible for providing patches in a timely +fashion. If critical issues for a particular implementation exist at the time +of a major release, support for that Ruby version may be dropped. + +## Versioning + +This library aims to adhere to [Semantic Versioning 2.0.0][semver]. Violations +of this scheme should be reported as bugs. Specifically, if a minor or patch +version is released that breaks backward compatibility, that version should be +immediately yanked and/or a new version should be immediately released that +restores compatibility. Breaking changes to the public API will only be +introduced with new major versions. As a result of this policy, you can (and +should) specify a dependency on this gem using the [Pessimistic Version +Constraint][pvc] with two digits of precision. For example: + +```ruby +spec.add_dependency 'multi_json', '~> 1.0' +``` + +[semver]: http://semver.org/ +[pvc]: http://docs.rubygems.org/read/chapter/16#page74 + +## Copyright +Copyright (c) 2010-2013 Michael Bleigh, Josh Kalderimis, Erik Michaels-Ober, +and Pavel Pravosud. See [LICENSE][] for details. + +[license]: LICENSE.md diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json.rb new file mode 100644 index 0000000..02c7250 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json.rb @@ -0,0 +1,161 @@ +require 'multi_json/options' +require 'multi_json/version' +require 'multi_json/adapter_error' +require 'multi_json/parse_error' +require 'multi_json/options_cache' + +module MultiJson + include Options + extend self + + def default_options=(value) + Kernel.warn "MultiJson.default_options setter is deprecated\n" \ + 'Use MultiJson.load_options and MultiJson.dump_options instead' + + self.load_options = self.dump_options = value + end + + def default_options + Kernel.warn "MultiJson.default_options is deprecated\n" \ + 'Use MultiJson.load_options or MultiJson.dump_options instead' + + load_options + end + + %w(cached_options reset_cached_options!).each do |method_name| + define_method method_name do |*| + Kernel.warn "MultiJson.#{method_name} method is deprecated and no longer used." + end + end + + ALIASES = {'jrjackson' => 'jr_jackson'} + + REQUIREMENT_MAP = [ + [:oj, 'oj'], + [:yajl, 'yajl'], + [:jr_jackson, 'jrjackson'], + [:json_gem, 'json/ext'], + [:gson, 'gson'], + [:json_pure, 'json/pure'], + ] + + # The default adapter based on what you currently + # have loaded and installed. First checks to see + # if any adapters are already loaded, then checks + # to see which are installed if none are loaded. + def default_adapter + return :oj if defined?(::Oj) + return :yajl if defined?(::Yajl) + return :jr_jackson if defined?(::JrJackson) + return :json_gem if defined?(::JSON::JSON_LOADED) + return :gson if defined?(::Gson) + + REQUIREMENT_MAP.each do |adapter, library| + begin + require library + return adapter + rescue ::LoadError + next + end + end + + Kernel.warn '[WARNING] MultiJson is using the default adapter (ok_json). ' \ + 'We recommend loading a different JSON library to improve performance.' + + :ok_json + end + alias_method :default_engine, :default_adapter + + # Get the current adapter class. + def adapter + return @adapter if defined?(@adapter) && @adapter + + use nil # load default adapter + + @adapter + end + alias_method :engine, :adapter + + # Set the JSON parser utilizing a symbol, string, or class. + # Supported by default are: + # + # * :oj + # * :json_gem + # * :json_pure + # * :ok_json + # * :yajl + # * :nsjsonserialization (MacRuby only) + # * :gson (JRuby only) + # * :jr_jackson (JRuby only) + def use(new_adapter) + @adapter = load_adapter(new_adapter) + ensure + OptionsCache.reset + end + alias_method :adapter=, :use + alias_method :engine=, :use + + def load_adapter(new_adapter) + case new_adapter + when String, Symbol + load_adapter_from_string_name new_adapter.to_s + when NilClass, FalseClass + load_adapter default_adapter + when Class, Module + new_adapter + else + fail ::LoadError, new_adapter + end + rescue ::LoadError => exception + raise AdapterError.build(exception) + end + + # Decode a JSON string into Ruby. + # + # Options + # + # :symbolize_keys :: If true, will use symbols instead of strings for the keys. + # :adapter :: If set, the selected adapter will be used for this call. + def load(string, options = {}) + adapter = current_adapter(options) + begin + adapter.load(string, options) + rescue adapter::ParseError => exception + raise ParseError.build(exception, string) + end + end + alias_method :decode, :load + + def current_adapter(options = {}) + if (new_adapter = options[:adapter]) + load_adapter(new_adapter) + else + adapter + end + end + + # Encodes a Ruby object as JSON. + def dump(object, options = {}) + current_adapter(options).dump(object, options) + end + alias_method :encode, :dump + + # Executes passed block using specified adapter. + def with_adapter(new_adapter) + old_adapter = adapter + self.adapter = new_adapter + yield + ensure + self.adapter = old_adapter + end + alias_method :with_engine, :with_adapter + +private + + def load_adapter_from_string_name(name) + name = ALIASES.fetch(name, name) + require "multi_json/adapters/#{name.downcase}" + klass_name = name.to_s.split('_').map(&:capitalize) * '' + MultiJson::Adapters.const_get(klass_name) + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapter.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapter.rb new file mode 100644 index 0000000..1d54d9a --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapter.rb @@ -0,0 +1,49 @@ +require 'singleton' +require 'multi_json/options' + +module MultiJson + class Adapter + extend Options + include Singleton + + class << self + def defaults(action, value) + metaclass = class << self; self; end + + metaclass.instance_eval do + define_method("default_#{action}_options") { value } + end + end + + def load(string, options = {}) + fail self::ParseError if blank?(string) + string = string.read if string.respond_to?(:read) + instance.load(string, cached_load_options(options)) + end + + def dump(object, options = {}) + instance.dump(object, cached_dump_options(options)) + end + + private + + def blank?(input) + input.nil? || /\A\s*\z/ === input + rescue ArgumentError # invalid byte sequence in UTF-8 + false + end + + def cached_dump_options(options) + OptionsCache.fetch(:dump, options) do + dump_options(options).merge(MultiJson.dump_options(options)).merge!(options) + end + end + + def cached_load_options(options) + OptionsCache.fetch(:load, options) do + load_options(options).merge(MultiJson.load_options(options)).merge!(options) + end + end + end + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapter_error.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapter_error.rb new file mode 100644 index 0000000..86902b6 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapter_error.rb @@ -0,0 +1,15 @@ +module MultiJson + class AdapterError < ArgumentError + attr_reader :cause + + def self.build(original_exception) + message = "Did not recognize your adapter specification (#{original_exception.message})." + new(message).tap do |exception| + exception.instance_eval do + @cause = original_exception + set_backtrace original_exception.backtrace + end + end + end + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapters/gson.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapters/gson.rb new file mode 100644 index 0000000..797fbf4 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapters/gson.rb @@ -0,0 +1,20 @@ +require 'gson' +require 'stringio' +require 'multi_json/adapter' + +module MultiJson + module Adapters + # Use the gson.rb library to dump/load. + class Gson < Adapter + ParseError = ::Gson::DecodeError + + def load(string, options = {}) + ::Gson::Decoder.new(options).decode(string) + end + + def dump(object, options = {}) + ::Gson::Encoder.new(options).encode(object) + end + end + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapters/jr_jackson.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapters/jr_jackson.rb new file mode 100644 index 0000000..a7e6cd8 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapters/jr_jackson.rb @@ -0,0 +1,25 @@ +require 'jrjackson' unless defined?(::JrJackson) +require 'multi_json/adapter' + +module MultiJson + module Adapters + # Use the jrjackson.rb library to dump/load. + class JrJackson < Adapter + ParseError = ::JrJackson::ParseError + + def load(string, options = {}) #:nodoc: + ::JrJackson::Json.load(string, options) + end + + if ::JrJackson::Json.method(:dump).arity == 1 + def dump(object, _) + ::JrJackson::Json.dump(object) + end + else + def dump(object, options = {}) + ::JrJackson::Json.dump(object, options) + end + end + end + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapters/json_common.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapters/json_common.rb new file mode 100644 index 0000000..e188895 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapters/json_common.rb @@ -0,0 +1,23 @@ +require 'multi_json/adapter' + +module MultiJson + module Adapters + class JsonCommon < Adapter + defaults :load, :create_additions => false, :quirks_mode => true + + def load(string, options = {}) + if string.respond_to?(:force_encoding) + string = string.dup.force_encoding(::Encoding::ASCII_8BIT) + end + + options[:symbolize_names] = true if options.delete(:symbolize_keys) + ::JSON.parse(string, options) + end + + def dump(object, options = {}) + options.merge!(::JSON::PRETTY_STATE_PROTOTYPE.to_h) if options.delete(:pretty) + object.to_json(options) + end + end + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapters/json_gem.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapters/json_gem.rb new file mode 100644 index 0000000..035de37 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapters/json_gem.rb @@ -0,0 +1,11 @@ +require 'json/ext' +require 'multi_json/adapters/json_common' + +module MultiJson + module Adapters + # Use the JSON gem to dump/load. + class JsonGem < JsonCommon + ParseError = ::JSON::ParserError + end + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapters/json_pure.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapters/json_pure.rb new file mode 100644 index 0000000..c5d7036 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapters/json_pure.rb @@ -0,0 +1,11 @@ +require 'json/pure' +require 'multi_json/adapters/json_common' + +module MultiJson + module Adapters + # Use JSON pure to dump/load. + class JsonPure < JsonCommon + ParseError = ::JSON::ParserError + end + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapters/nsjsonserialization.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapters/nsjsonserialization.rb new file mode 100644 index 0000000..207b0e2 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapters/nsjsonserialization.rb @@ -0,0 +1,32 @@ +framework 'Foundation' +require 'multi_json/adapters/ok_json' + +module MultiJson + module Adapters + class Nsjsonserialization < MultiJson::Adapters::OkJson + ParseError = ::MultiJson::OkJson::Error + + def load(string, options = {}) + data = string.dataUsingEncoding(NSUTF8StringEncoding) + object = NSJSONSerialization.JSONObjectWithData(data, :options => NSJSONReadingMutableContainers | NSJSONReadingMutableLeaves, :error => nil) + if object + object = symbolize_keys(object) if options[:symbolize_keys] + object + else + super(string, options) + end + end + + def dump(object, options = {}) + pretty = options[:pretty] ? NSJSONWritingPrettyPrinted : 0 + object = object.as_json if object.respond_to?(:as_json) + if NSJSONSerialization.isValidJSONObject(object) + data = NSJSONSerialization.dataWithJSONObject(object, :options => pretty, :error => nil) + NSMutableString.alloc.initWithData(data, :encoding => NSUTF8StringEncoding) + else + super(object, options) + end + end + end + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapters/oj.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapters/oj.rb new file mode 100644 index 0000000..7d6c1f8 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapters/oj.rb @@ -0,0 +1,25 @@ +require 'oj' +require 'multi_json/adapter' + +module MultiJson + module Adapters + # Use the Oj library to dump/load. + class Oj < Adapter + defaults :load, :mode => :strict, :symbolize_keys => false + defaults :dump, :mode => :compat, :time_format => :ruby, :use_to_json => true + + ParseError = defined?(::Oj::ParseError) ? ::Oj::ParseError : SyntaxError + + def load(string, options = {}) + options[:symbol_keys] = options[:symbolize_keys] + ::Oj.load(string, options) + end + + def dump(object, options = {}) + options.merge!(:indent => 2) if options[:pretty] + options[:indent] = options[:indent].to_i if options[:indent] + ::Oj.dump(object, options) + end + end + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapters/ok_json.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapters/ok_json.rb new file mode 100644 index 0000000..7f51145 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapters/ok_json.rb @@ -0,0 +1,23 @@ +require 'multi_json/adapter' +require 'multi_json/convertible_hash_keys' +require 'multi_json/vendor/okjson' + +module MultiJson + module Adapters + class OkJson < Adapter + include ConvertibleHashKeys + ParseError = ::MultiJson::OkJson::Error + + def load(string, options = {}) + result = ::MultiJson::OkJson.decode("[#{string}]").first + options[:symbolize_keys] ? symbolize_keys(result) : result + rescue ArgumentError # invalid byte sequence in UTF-8 + raise ParseError + end + + def dump(object, _ = {}) + ::MultiJson::OkJson.valenc(stringify_keys(object)) + end + end + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapters/yajl.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapters/yajl.rb new file mode 100644 index 0000000..1c297a5 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapters/yajl.rb @@ -0,0 +1,19 @@ +require 'yajl' +require 'multi_json/adapter' + +module MultiJson + module Adapters + # Use the Yajl-Ruby library to dump/load. + class Yajl < Adapter + ParseError = ::Yajl::ParseError + + def load(string, options = {}) + ::Yajl::Parser.new(:symbolize_keys => options[:symbolize_keys]).parse(string) + end + + def dump(object, options = {}) + ::Yajl::Encoder.encode(object, options) + end + end + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/convertible_hash_keys.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/convertible_hash_keys.rb new file mode 100644 index 0000000..1253e66 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/convertible_hash_keys.rb @@ -0,0 +1,43 @@ +module MultiJson + module ConvertibleHashKeys + private + + def symbolize_keys(hash) + prepare_hash(hash) do |key| + key.respond_to?(:to_sym) ? key.to_sym : key + end + end + + def stringify_keys(hash) + prepare_hash(hash) do |key| + key.respond_to?(:to_s) ? key.to_s : key + end + end + + def prepare_hash(hash, &key_modifier) + return hash unless block_given? + case hash + when Array + hash.map do |value| + prepare_hash(value, &key_modifier) + end + when Hash + hash.inject({}) do |result, (key, value)| + new_key = key_modifier.call(key) + new_value = prepare_hash(value, &key_modifier) + result.merge! new_key => new_value + end + when String, Numeric, true, false, nil + hash + else + if hash.respond_to?(:to_json) + hash + elsif hash.respond_to?(:to_s) + hash.to_s + else + hash + end + end + end + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/options.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/options.rb new file mode 100644 index 0000000..a56a90e --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/options.rb @@ -0,0 +1,39 @@ +module MultiJson + module Options + def load_options=(options) + OptionsCache.reset + @load_options = options + end + + def dump_options=(options) + OptionsCache.reset + @dump_options = options + end + + def load_options(*args) + defined?(@load_options) && get_options(@load_options, *args) || default_load_options + end + + def dump_options(*args) + defined?(@dump_options) && get_options(@dump_options, *args) || default_dump_options + end + + def default_load_options + @default_load_options ||= {} + end + + def default_dump_options + @default_dump_options ||= {} + end + + private + + def get_options(options, *args) + if options.respond_to?(:call) && options.arity + options.arity == 0 ? options[] : options[*args] + elsif options.respond_to?(:to_hash) + options.to_hash + end + end + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/options_cache.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/options_cache.rb new file mode 100644 index 0000000..05bf59d --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/options_cache.rb @@ -0,0 +1,29 @@ +module MultiJson + module OptionsCache + extend self + + def reset + @dump_cache = {} + @load_cache = {} + end + + def fetch(type, key) + cache = instance_variable_get("@#{type}_cache") + cache.key?(key) ? cache[key] : write(cache, key, &Proc.new) + end + + private + + # Normally MultiJson is used with a few option sets for both dump/load + # methods. When options are generated dynamically though, every call would + # cause a cache miss and the cache would grow indefinitely. To prevent + # this, we just reset the cache every time the number of keys outgrows + # 1000. + MAX_CACHE_SIZE = 1000 + + def write(cache, key) + cache.clear if cache.length >= MAX_CACHE_SIZE + cache[key] = yield + end + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/parse_error.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/parse_error.rb new file mode 100644 index 0000000..407a622 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/parse_error.rb @@ -0,0 +1,17 @@ +module MultiJson + class ParseError < StandardError + attr_reader :data, :cause + + def self.build(original_exception, data) + new(original_exception.message).tap do |exception| + exception.instance_eval do + @cause = original_exception + set_backtrace original_exception.backtrace + @data = data + end + end + end + end + + DecodeError = LoadError = ParseError # Legacy support +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/vendor/okjson.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/vendor/okjson.rb new file mode 100644 index 0000000..0d5f814 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/vendor/okjson.rb @@ -0,0 +1,606 @@ +# encoding: UTF-8 +# +# Copyright 2011, 2012 Keith Rarick +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. + +# See https://github.com/kr/okjson for updates. + +require 'stringio' + +module MultiJson + # Some parts adapted from + # https://golang.org/src/encoding/json/decode.go and + # https://golang.org/src/unicode/utf8/utf8.go + module OkJson + Upstream = '45' + extend self + + + # Decodes a json document in string s and + # returns the corresponding ruby value. + # String s must be valid UTF-8. If you have + # a string in some other encoding, convert + # it first. + # + # String values in the resulting structure + # will be UTF-8. + def decode(s) + ts = lex(s) + v, ts = textparse(ts) + if ts.length > 0 + raise Error, 'trailing garbage' + end + v + end + + + # Encodes x into a json text. It may contain only + # Array, Hash, String, Numeric, true, false, nil. + # (Note, this list excludes Symbol.) + # X itself must be an Array or a Hash. + # No other value can be encoded, and an error will + # be raised if x contains any other value, such as + # Nan, Infinity, Symbol, and Proc, or if a Hash key + # is not a String. + # Strings contained in x must be valid UTF-8. + def encode(x) + case x + when Hash then objenc(x) + when Array then arrenc(x) + else + raise Error, 'root value must be an Array or a Hash' + end + end + + + def valenc(x) + case x + when Hash then objenc(x) + when Array then arrenc(x) + when String then strenc(x) + when Numeric then numenc(x) + when true then "true" + when false then "false" + when nil then "null" + else + if x.respond_to?(:to_json) + x.to_json + else + raise Error, "cannot encode #{x.class}: #{x.inspect}" + end + end + end + + + private + + + # Parses a "json text" in the sense of RFC 4627. + # Returns the parsed value and any trailing tokens. + # Note: this is almost the same as valparse, + # except that it does not accept atomic values. + def textparse(ts) + if ts.length <= 0 + raise Error, 'empty' + end + + typ, _, val = ts[0] + case typ + when '{' then objparse(ts) + when '[' then arrparse(ts) + else + raise Error, "unexpected #{val.inspect}" + end + end + + + # Parses a "value" in the sense of RFC 4627. + # Returns the parsed value and any trailing tokens. + def valparse(ts) + if ts.length <= 0 + raise Error, 'empty' + end + + typ, _, val = ts[0] + case typ + when '{' then objparse(ts) + when '[' then arrparse(ts) + when :val,:str then [val, ts[1..-1]] + else + raise Error, "unexpected #{val.inspect}" + end + end + + + # Parses an "object" in the sense of RFC 4627. + # Returns the parsed value and any trailing tokens. + def objparse(ts) + ts = eat('{', ts) + obj = {} + + if ts[0][0] == '}' + return obj, ts[1..-1] + end + + k, v, ts = pairparse(ts) + obj[k] = v + + if ts[0][0] == '}' + return obj, ts[1..-1] + end + + loop do + ts = eat(',', ts) + + k, v, ts = pairparse(ts) + obj[k] = v + + if ts[0][0] == '}' + return obj, ts[1..-1] + end + end + end + + + # Parses a "member" in the sense of RFC 4627. + # Returns the parsed values and any trailing tokens. + def pairparse(ts) + (typ, _, k), ts = ts[0], ts[1..-1] + if typ != :str + raise Error, "unexpected #{k.inspect}" + end + ts = eat(':', ts) + v, ts = valparse(ts) + [k, v, ts] + end + + + # Parses an "array" in the sense of RFC 4627. + # Returns the parsed value and any trailing tokens. + def arrparse(ts) + ts = eat('[', ts) + arr = [] + + if ts[0][0] == ']' + return arr, ts[1..-1] + end + + v, ts = valparse(ts) + arr << v + + if ts[0][0] == ']' + return arr, ts[1..-1] + end + + loop do + ts = eat(',', ts) + + v, ts = valparse(ts) + arr << v + + if ts[0][0] == ']' + return arr, ts[1..-1] + end + end + end + + + def eat(typ, ts) + if ts[0][0] != typ + raise Error, "expected #{typ} (got #{ts[0].inspect})" + end + ts[1..-1] + end + + + # Scans s and returns a list of json tokens, + # excluding white space (as defined in RFC 4627). + def lex(s) + ts = [] + while s.length > 0 + typ, lexeme, val = tok(s) + if typ == nil + raise Error, "invalid character at #{s[0,10].inspect}" + end + if typ != :space + ts << [typ, lexeme, val] + end + s = s[lexeme.length..-1] + end + ts + end + + + # Scans the first token in s and + # returns a 3-element list, or nil + # if s does not begin with a valid token. + # + # The first list element is one of + # '{', '}', ':', ',', '[', ']', + # :val, :str, and :space. + # + # The second element is the lexeme. + # + # The third element is the value of the + # token for :val and :str, otherwise + # it is the lexeme. + def tok(s) + case s[0] + when ?{ then ['{', s[0,1], s[0,1]] + when ?} then ['}', s[0,1], s[0,1]] + when ?: then [':', s[0,1], s[0,1]] + when ?, then [',', s[0,1], s[0,1]] + when ?[ then ['[', s[0,1], s[0,1]] + when ?] then [']', s[0,1], s[0,1]] + when ?n then nulltok(s) + when ?t then truetok(s) + when ?f then falsetok(s) + when ?" then strtok(s) + when Spc, ?\t, ?\n, ?\r then [:space, s[0,1], s[0,1]] + else + numtok(s) + end + end + + + def nulltok(s); s[0,4] == 'null' ? [:val, 'null', nil] : [] end + def truetok(s); s[0,4] == 'true' ? [:val, 'true', true] : [] end + def falsetok(s); s[0,5] == 'false' ? [:val, 'false', false] : [] end + + + def numtok(s) + m = /(-?(?:[1-9][0-9]+|[0-9]))([.][0-9]+)?([eE][+-]?[0-9]+)?/.match(s) + if m && m.begin(0) == 0 + if !m[2] && !m[3] + [:val, m[0], Integer(m[0])] + elsif m[2] + [:val, m[0], Float(m[0])] + else + [:val, m[0], Integer(m[1])*(10**m[3][1..-1].to_i(10))] + end + else + [] + end + end + + + def strtok(s) + m = /"([^"\\]|\\["\/\\bfnrt]|\\u[0-9a-fA-F]{4})*"/.match(s) + if ! m + raise Error, "invalid string literal at #{abbrev(s)}" + end + [:str, m[0], unquote(m[0])] + end + + + def abbrev(s) + t = s[0,10] + p = t['`'] + t = t[0,p] if p + t = t + '...' if t.length < s.length + '`' + t + '`' + end + + + # Converts a quoted json string literal q into a UTF-8-encoded string. + # The rules are different than for Ruby, so we cannot use eval. + # Unquote will raise an error if q contains control characters. + def unquote(q) + q = q[1...-1] + a = q.dup # allocate a big enough string + # In ruby >= 1.9, a[w] is a codepoint, not a byte. + if rubydoesenc? + a.force_encoding('UTF-8') + end + r, w = 0, 0 + while r < q.length + c = q[r] + if c == ?\\ + r += 1 + if r >= q.length + raise Error, "string literal ends with a \"\\\": \"#{q}\"" + end + + case q[r] + when ?",?\\,?/,?' + a[w] = q[r] + r += 1 + w += 1 + when ?b,?f,?n,?r,?t + a[w] = Unesc[q[r]] + r += 1 + w += 1 + when ?u + r += 1 + uchar = begin + hexdec4(q[r,4]) + rescue RuntimeError => e + raise Error, "invalid escape sequence \\u#{q[r,4]}: #{e}" + end + r += 4 + if surrogate? uchar + if q.length >= r+6 + uchar1 = hexdec4(q[r+2,4]) + uchar = subst(uchar, uchar1) + if uchar != Ucharerr + # A valid pair; consume. + r += 6 + end + end + end + if rubydoesenc? + a[w] = '' << uchar + w += 1 + else + w += ucharenc(a, w, uchar) + end + else + raise Error, "invalid escape char #{q[r]} in \"#{q}\"" + end + elsif c == ?" || c < Spc + raise Error, "invalid character in string literal \"#{q}\"" + else + # Copy anything else byte-for-byte. + # Valid UTF-8 will remain valid UTF-8. + # Invalid UTF-8 will remain invalid UTF-8. + # In ruby >= 1.9, c is a codepoint, not a byte, + # in which case this is still what we want. + a[w] = c + r += 1 + w += 1 + end + end + a[0,w] + end + + + # Encodes unicode character u as UTF-8 + # bytes in string a at position i. + # Returns the number of bytes written. + def ucharenc(a, i, u) + if u <= Uchar1max + a[i] = (u & 0xff).chr + 1 + elsif u <= Uchar2max + a[i+0] = (Utag2 | ((u>>6)&0xff)).chr + a[i+1] = (Utagx | (u&Umaskx)).chr + 2 + elsif u <= Uchar3max + a[i+0] = (Utag3 | ((u>>12)&0xff)).chr + a[i+1] = (Utagx | ((u>>6)&Umaskx)).chr + a[i+2] = (Utagx | (u&Umaskx)).chr + 3 + else + a[i+0] = (Utag4 | ((u>>18)&0xff)).chr + a[i+1] = (Utagx | ((u>>12)&Umaskx)).chr + a[i+2] = (Utagx | ((u>>6)&Umaskx)).chr + a[i+3] = (Utagx | (u&Umaskx)).chr + 4 + end + end + + + def hexdec4(s) + if s.length != 4 + raise Error, 'short' + end + (nibble(s[0])<<12) | (nibble(s[1])<<8) | (nibble(s[2])<<4) | nibble(s[3]) + end + + + def subst(u1, u2) + if Usurr1 <= u1 && u1 < Usurr2 && Usurr2 <= u2 && u2 < Usurr3 + return ((u1-Usurr1)<<10) | (u2-Usurr2) + Usurrself + end + return Ucharerr + end + + + def surrogate?(u) + Usurr1 <= u && u < Usurr3 + end + + + def nibble(c) + if ?0 <= c && c <= ?9 then c.ord - ?0.ord + elsif ?a <= c && c <= ?z then c.ord - ?a.ord + 10 + elsif ?A <= c && c <= ?Z then c.ord - ?A.ord + 10 + else + raise Error, "invalid hex code #{c}" + end + end + + + def objenc(x) + '{' + x.map{|k,v| keyenc(k) + ':' + valenc(v)}.join(',') + '}' + end + + + def arrenc(a) + '[' + a.map{|x| valenc(x)}.join(',') + ']' + end + + + def keyenc(k) + case k + when String then strenc(k) + else + raise Error, "Hash key is not a string: #{k.inspect}" + end + end + + + def strenc(s) + t = StringIO.new + t.putc(?") + r = 0 + + while r < s.length + case s[r] + when ?" then t.print('\\"') + when ?\\ then t.print('\\\\') + when ?\b then t.print('\\b') + when ?\f then t.print('\\f') + when ?\n then t.print('\\n') + when ?\r then t.print('\\r') + when ?\t then t.print('\\t') + else + c = s[r] + # In ruby >= 1.9, s[r] is a codepoint, not a byte. + if rubydoesenc? + begin + # c.ord will raise an error if c is invalid UTF-8 + if c.ord < Spc.ord + c = "\\u%04x" % [c.ord] + end + t.write(c) + rescue + t.write(Ustrerr) + end + elsif c < Spc + t.write("\\u%04x" % c) + elsif Spc <= c && c <= ?~ + t.putc(c) + else + n = ucharcopy(t, s, r) # ensure valid UTF-8 output + r += n - 1 # r is incremented below + end + end + r += 1 + end + t.putc(?") + t.string + end + + + def numenc(x) + if ((x.nan? || x.infinite?) rescue false) + raise Error, "Numeric cannot be represented: #{x}" + end + "#{x}" + end + + + # Copies the valid UTF-8 bytes of a single character + # from string s at position i to I/O object t, and + # returns the number of bytes copied. + # If no valid UTF-8 char exists at position i, + # ucharcopy writes Ustrerr and returns 1. + def ucharcopy(t, s, i) + n = s.length - i + raise Utf8Error if n < 1 + + c0 = s[i].ord + + # 1-byte, 7-bit sequence? + if c0 < Utagx + t.putc(c0) + return 1 + end + + raise Utf8Error if c0 < Utag2 # unexpected continuation byte? + + raise Utf8Error if n < 2 # need continuation byte + c1 = s[i+1].ord + raise Utf8Error if c1 < Utagx || Utag2 <= c1 + + # 2-byte, 11-bit sequence? + if c0 < Utag3 + raise Utf8Error if ((c0&Umask2)<<6 | (c1&Umaskx)) <= Uchar1max + t.putc(c0) + t.putc(c1) + return 2 + end + + # need second continuation byte + raise Utf8Error if n < 3 + + c2 = s[i+2].ord + raise Utf8Error if c2 < Utagx || Utag2 <= c2 + + # 3-byte, 16-bit sequence? + if c0 < Utag4 + u = (c0&Umask3)<<12 | (c1&Umaskx)<<6 | (c2&Umaskx) + raise Utf8Error if u <= Uchar2max + t.putc(c0) + t.putc(c1) + t.putc(c2) + return 3 + end + + # need third continuation byte + raise Utf8Error if n < 4 + c3 = s[i+3].ord + raise Utf8Error if c3 < Utagx || Utag2 <= c3 + + # 4-byte, 21-bit sequence? + if c0 < Utag5 + u = (c0&Umask4)<<18 | (c1&Umaskx)<<12 | (c2&Umaskx)<<6 | (c3&Umaskx) + raise Utf8Error if u <= Uchar3max + t.putc(c0) + t.putc(c1) + t.putc(c2) + t.putc(c3) + return 4 + end + + raise Utf8Error + rescue Utf8Error + t.write(Ustrerr) + return 1 + end + + + def rubydoesenc? + ::String.method_defined?(:force_encoding) + end + + + class Utf8Error < ::StandardError + end + + + class Error < ::StandardError + end + + + Utagx = 0b1000_0000 + Utag2 = 0b1100_0000 + Utag3 = 0b1110_0000 + Utag4 = 0b1111_0000 + Utag5 = 0b1111_1000 + Umaskx = 0b0011_1111 + Umask2 = 0b0001_1111 + Umask3 = 0b0000_1111 + Umask4 = 0b0000_0111 + Uchar1max = (1<<7) - 1 + Uchar2max = (1<<11) - 1 + Uchar3max = (1<<16) - 1 + Ucharerr = 0xFFFD # unicode "replacement char" + Ustrerr = "\xef\xbf\xbd" # unicode "replacement char" + Usurrself = 0x10000 + Usurr1 = 0xd800 + Usurr2 = 0xdc00 + Usurr3 = 0xe000 + + Spc = ' '[0] + Unesc = {?b=>?\b, ?f=>?\f, ?n=>?\n, ?r=>?\r, ?t=>?\t} + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/version.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/version.rb new file mode 100644 index 0000000..bc37e01 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/lib/multi_json/version.rb @@ -0,0 +1,17 @@ +module MultiJson + class Version + MAJOR = 1 unless defined? MultiJson::Version::MAJOR + MINOR = 12 unless defined? MultiJson::Version::MINOR + PATCH = 1 unless defined? MultiJson::Version::PATCH + PRE = nil unless defined? MultiJson::Version::PRE + + class << self + # @return [String] + def to_s + [MAJOR, MINOR, PATCH, PRE].compact.join('.') + end + end + end + + VERSION = Version.to_s.freeze +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/multi_json.gemspec b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/multi_json.gemspec new file mode 100644 index 0000000..e9de919 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/multi_json-1.12.1/multi_json.gemspec @@ -0,0 +1,20 @@ +# coding: utf-8 +require File.expand_path('../lib/multi_json/version.rb', __FILE__) + +Gem::Specification.new do |spec| + spec.authors = ['Michael Bleigh', 'Josh Kalderimis', 'Erik Michaels-Ober', 'Pavel Pravosud'] + spec.cert_chain = %w(certs/rwz.pem) + spec.summary = 'A common interface to multiple JSON libraries.' + spec.description = 'A common interface to multiple JSON libraries, including Oj, Yajl, the JSON gem (with C-extensions), the pure-Ruby JSON gem, NSJSONSerialization, gson.rb, JrJackson, and OkJson.' + spec.email = %w(michael@intridea.com josh.kalderimis@gmail.com sferik@gmail.com pavel@pravosud.com) + spec.files = Dir['CHANGELOG.md', 'CONTRIBUTING.md', 'LICENSE.md', 'README.md', 'multi_json.gemspec', 'lib/**/*'] + spec.homepage = 'http://github.com/intridea/multi_json' + spec.license = 'MIT' + spec.name = 'multi_json' + spec.require_path = 'lib' + spec.signing_key = File.expand_path('~/.ssh/gem-private_key.pem') if $PROGRAM_NAME =~ /gem\z/ + spec.version = MultiJson::Version + + spec.required_rubygems_version = '>= 1.3.5' + spec.add_development_dependency 'bundler', '~> 1.0' +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/CHANGELOG.md b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/CHANGELOG.md new file mode 100644 index 0000000..00b2aa1 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/CHANGELOG.md @@ -0,0 +1,47 @@ +#Change Log +This project adheres to [Semantic Versioning](http://semver.org/). + +This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachangelog.com/) + +## [Unreleased] + +## [1.0.0] - 2016-06-15 +### Changed +- Modified check-cpu.rb to change state if >= threshold +- Updated Rubocop to 0.40, applied auto-correct +- Loosened sensu-plugin dependency to ~> 1.2 +- Specify the /proc location for use within a container + +### Added +- Added metrics-numastat.rb +- check-cpu.rb: Added --idle-metrics flag for indicating counters which should be considered idle + +### Removed +- Remove Ruby 1.9.3 support; add Ruby 2.3.0 support in test matrix + +## [0.0.4] - 2015-09-29 +### Changed +- Fix getopts syntax in check-cpu.sh +- Improvements to system/metrics-user-pct-usage.rb (option to use uid instead of username) + +## [0.0.3] - 2015-07-14 +### Changed +- updated sensu-plugin gem to 1.2.0 + +## [0.0.2] - 2015-06-02 +### Fixed +- added binstubs + +### Changed +- removed cruft from /lib + +## 0.0.1 - 2015-05-21 +### Added +- initial release + + +[Unreleased]: https://github.com/sensu-plugins/sensu-plugins-cpu-checks/compare/1.0.0...HEAD +[1.0.0]: https://github.com/sensu-plugins/sensu-plugins-cpu-checks/compare/0.0.4...1.0.0 +[0.0.4]: https://github.com/sensu-plugins/sensu-plugins-cpu-checks/compare/0.0.3...0.0.4 +[0.0.3]: https://github.com/sensu-plugins/sensu-plugins-cpu-checks/compare/0.0.2...0.0.3 +[0.0.2]: https://github.com/sensu-plugins/sensu-plugins-cpu-checks/compare/0.0.1...0.0.2 diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/LICENSE b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/LICENSE new file mode 100644 index 0000000..f661cbd --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/LICENSE @@ -0,0 +1,22 @@ +Copyright (c) 2015 Sensu-Plugins + +MIT License + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/README.md b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/README.md new file mode 100644 index 0000000..93bb848 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/README.md @@ -0,0 +1,25 @@ +## Sensu-Plugins-cpu-checks + +[ ![Build Status](https://travis-ci.org/sensu-plugins/sensu-plugins-cpu-checks.svg?branch=master)](https://travis-ci.org/sensu-plugins/sensu-plugins-cpu-checks) +[![Gem Version](https://badge.fury.io/rb/sensu-plugins-cpu-checks.svg)](http://badge.fury.io/rb/sensu-plugins-cpu-checks) +[![Code Climate](https://codeclimate.com/github/sensu-plugins/sensu-plugins-cpu-checks/badges/gpa.svg)](https://codeclimate.com/github/sensu-plugins/sensu-plugins-cpu-checks) +[![Test Coverage](https://codeclimate.com/github/sensu-plugins/sensu-plugins-cpu-checks/badges/coverage.svg)](https://codeclimate.com/github/sensu-plugins/sensu-plugins-cpu-checks) +[![Dependency Status](https://gemnasium.com/sensu-plugins/sensu-plugins-cpu-checks.svg)](https://gemnasium.com/sensu-plugins/sensu-plugins-cpu-checks) + +## Functionality + +## Files + * bin/check-cpu.rb + * bin/check-cpu.sh + * bin/metrics-cpu-mpstat.rb + * bin/metrics-cpu-pcnt-usage.rb + * bin/metrics-numastat.rb + * bin/metrics-user-pct-usage.rb + +## Usage + +## Installation + +[Installation and Setup](http://sensu-plugins.io/docs/installation_instructions.html) + +## Notes diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/bin/check-cpu.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/bin/check-cpu.rb new file mode 100755 index 0000000..d101ecf --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/bin/check-cpu.rb @@ -0,0 +1,120 @@ +#! /usr/bin/env ruby +# +# check-cpu +# +# DESCRIPTION: +# Check cpu usage +# +# OUTPUT: +# plain text +# +# PLATFORMS: +# Linux +# +# DEPENDENCIES: +# gem: sensu-plugin +# +# USAGE: +# #YELLOW +# +# NOTES: +# +# LICENSE: +# Copyright 2014 Sonian, Inc. and contributors. +# Released under the same terms as Sensu (the MIT license); see LICENSE +# for details. +# + +require 'sensu-plugin/check/cli' + +# +# Check CPU +# +class CheckCPU < Sensu::Plugin::Check::CLI + CPU_METRICS = [:user, :nice, :system, :idle, :iowait, :irq, :softirq, :steal, :guest, :guest_nice].freeze + + option :warn, + short: '-w WARN', + proc: proc(&:to_f), + default: 80 + + option :crit, + short: '-c CRIT', + proc: proc(&:to_f), + default: 100 + + option :sleep, + long: '--sleep SLEEP', + proc: proc(&:to_f), + default: 1 + + option :proc_path, + long: '--proc-path /proc', + proc: proc(&:to_f), + default: '/proc' + + option :idle_metrics, + long: '--idle-metrics METRICS', + description: 'Treat the specified metrics as idle. Defaults to idle,iowait,steal,guest,guest_nice', + proc: proc { |x| x.split(/,/).map { |y| y.strip.to_sym } }, + default: [:idle, :iowait, :steal, :guest, :guest_nice] + + CPU_METRICS.each do |metric| + option metric, + long: "--#{metric}", + description: "Check cpu #{metric} instead of total cpu usage", + boolean: true, + default: false + end + + def acquire_cpu_stats + File.open("#{config[:proc_path]}/stat", 'r').each_line do |line| + info = line.split(/\s+/) + name = info.shift + return info.map(&:to_f) if name =~ /^cpu$/ + end + end + + def run + cpu_stats_before = acquire_cpu_stats + sleep config[:sleep] + cpu_stats_after = acquire_cpu_stats + + # Some kernels don't have 'guest' and 'guest_nice' values + metrics = CPU_METRICS.slice(0, cpu_stats_after.length) + + cpu_total_diff = 0.to_f + cpu_stats_diff = [] + metrics.each_index do |i| + cpu_stats_diff[i] = cpu_stats_after[i] - cpu_stats_before[i] + cpu_total_diff += cpu_stats_diff[i] + end + + cpu_stats = [] + metrics.each_index do |i| + cpu_stats[i] = 100 * (cpu_stats_diff[i] / cpu_total_diff) + end + + idle_diff = metrics.each_with_index.map { |metric, i| config[:idle_metrics].include?(metric) ? cpu_stats_diff[i] : 0.0 }.reduce(0.0, :+) + + cpu_usage = 100 * (cpu_total_diff - idle_diff) / cpu_total_diff + checked_usage = cpu_usage + + self.class.check_name 'CheckCPU TOTAL' + metrics.each do |metric| + if config[metric] + self.class.check_name "CheckCPU #{metric.to_s.upcase}" + checked_usage = cpu_stats[metrics.find_index(metric)] + end + end + + msg = "total=#{(cpu_usage * 100).round / 100.0}" + cpu_stats.each_index { |i| msg += " #{metrics[i]}=#{(cpu_stats[i] * 100).round / 100.0}" } + + message msg + + critical if checked_usage >= config[:crit] + warning if checked_usage >= config[:warn] + ok + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/bin/check-cpu.sh b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/bin/check-cpu.sh new file mode 100755 index 0000000..d625f36 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/bin/check-cpu.sh @@ -0,0 +1,84 @@ +#!/bin/bash +# +# Check CPU usage +# +# === +# +# Examples: +# +# check-cpu.sh -w 85 -c 95 +# +# Date: 2014-09-12 +# Author: Jun Ichikawa +# +# Released under the same terms as Sensu (the MIT license); see LICENSE +# for details. + +# get arguments +while getopts ':w:c:h' OPT; do + case $OPT in + w) WARN=$OPTARG;; + c) CRIT=$OPTARG;; + h) hlp="yes";; + *) unknown="yes";; + esac +done + +PROC_PATH=${PROC_PATH:-'/proc'} + +# usage +HELP=" + usage: $0 [ -w value -c value -p -h ] + + -w --> Warning percentage < value + -c --> Critical percentage < value + -h --> print this help screen +" + +if [ "$hlp" = "yes" ]; then + echo "$HELP" + exit 0 +fi + +cpuusage1=(`cat /proc/stat | head -1`) +if [ ${#cpuusage1} -eq 0 ]; then + echo "CRITICAL - CPU UNKNOWN" + exit 2 +fi +sleep 1 +cpuusage2=(`cat $PROC_PATH/stat | head -1`) +if [ ${#cpuusage2} -eq 0 ]; then + echo "CRITICAL - CPU UNKNOWN" + exit 2 +fi + +WARN=${WARN:=90} +CRIT=${CRIT:=95} + +cpu_diff=(0) +total=0 +usage_diff=0 +for i in `seq 1 9` +do + cpu_diff=("${cpu_diff[@]}" `echo "${cpuusage2[$i]}-${cpuusage1[$i]}" | bc`) + total=`echo "$total+${cpu_diff[$i]}" | bc` + if [ $i -ne "4" ]; then + usage_diff=`echo "$usage_diff+${cpu_diff[$i]}" | bc` + else + idl=$cpu_diff[$i] + fi +done +cpu_usage=`echo "scale=2; 100*$usage_diff/$total" | bc` + +if [ "$(echo "${cpu_usage} > ${CRIT}" | bc)" -eq 1 ]; then + echo "CPU CRITICAL - ${cpu_usage}% is greater than critical point.[${CRIT}]" + exit 2 +fi + +if [ "$(echo "${cpu_usage} > ${WARN}" | bc)" -eq 1 ]; then + echo "CPU WARNING - ${cpu_usage}% is greater than warning point.[${WARN}]" + exit 1 +fi + +echo "CPU OK - Usage:${cpu_usage}" +exit 0 diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/bin/metrics-cpu-mpstat.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/bin/metrics-cpu-mpstat.rb new file mode 100755 index 0000000..b938e69 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/bin/metrics-cpu-mpstat.rb @@ -0,0 +1,87 @@ +#! /usr/bin/env ruby +# encoding: UTF-8 +# +# cpu-mpstat-metrics +# +# DESCRIPTION: +# Uses the linux/kstat rubygem to do the hard work in /proc/stat +# includes individual cpu and overall cpu usage +# +# OUTPUT: +# metric data +# +# PLATFORMS: +# Linux +# +# DEPENDENCIES: +# gem: sensu-plugin +# gem: linux/kstat +# +# USAGE: +# +# NOTES: +# +# LICENSE: +# Copyright 2012 Sonian, Inc +# Released under the same terms as Sensu (the MIT license); see LICENSE +# for details. +# + +require 'sensu-plugin/metric/cli' +require 'socket' +require 'linux/kstat' + +# +# CPU Graphite +# +class CpuGraphite < Sensu::Plugin::Metric::CLI::Graphite + option :scheme, + description: 'Metric naming scheme, text to prepend to metric', + short: '-s SCHEME', + long: '--scheme SCHEME', + default: "#{Socket.gethostname}.cpu" + + def acquire_mpstats + kstat = Linux::Kstat.new + mpstat = {} + i = '' + until kstat[:"cpu#{i}"].nil? + mpstat[:"cpu#{i}"] = kstat[:"cpu#{i}"] + if i == '' + i = 0 + else + i += 1 + end + end + mpstat + end + + def delta_cpu_metrics(baseline_cpus, sample_cpus) + delta_cpus = {} + baseline_cpus.each do |cpu, columns| + delta_cpus[:"#{cpu}"] = {} + columns.each do |task, time| + delta_cpus[:"#{cpu}"][:"#{task}"] = sample_cpus[:"#{cpu}"][:"#{task}"] - time + end + end + delta_cpus + end + + def run + baseline_cpus = acquire_mpstats + # measure for a second then get the deltas in jiffies + sleep(1) + sample_cpus = acquire_mpstats + delta_cpus = delta_cpu_metrics(baseline_cpus, sample_cpus) + cpu_count = sample_cpus.length - 1 + delta_cpus.each_pair do |cpu, columns| + # assumes architecture's jiffie is 1/100th of a second + columns.each_pair do |task, time| + # #YELLOW + time = time / cpu_count if cpu.to_s == 'cpu' # rubocop:disable Style/SelfAssignment + output "#{config[:scheme]}.#{cpu}.#{task}", time + end + end + ok + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/bin/metrics-cpu-pcnt-usage.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/bin/metrics-cpu-pcnt-usage.rb new file mode 100755 index 0000000..a72e2a4 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/bin/metrics-cpu-pcnt-usage.rb @@ -0,0 +1,85 @@ +#! /usr/bin/env ruby +# encoding: UTF-8 +# +# cpu-pct-usage-metrics +# +# DESCRIPTION: +# +# OUTPUT: +# metric data +# +# PLATFORMS: +# Linux +# +# DEPENDENCIES: +# gem: sensu-plugin +# +# USAGE: +# +# NOTES: +# +# LICENSE: +# Copyright 2012 Sonian, Inc +# Released under the same terms as Sensu (the MIT license); see LICENSE +# for details. +# +require 'sensu-plugin/metric/cli' +require 'socket' + +# +# CPU Graphite +# +class CpuGraphite < Sensu::Plugin::Metric::CLI::Graphite + option :scheme, + description: 'Metric naming scheme, text to prepend to metric', + short: '-s SCHEME', + long: '--scheme SCHEME', + default: "#{Socket.gethostname}.cpu" + + option :proc_path, + long: '--proc-path /proc', + proc: proc(&:to_f), + default: '/proc' + + def acquire_proc_stats + cpu_metrics = %w(user nice system idle iowait irq softirq steal guest) + File.open("#{config[:proc_path]}/stat", 'r').each_line do |line| + info = line.split(/\s+/) + next if info.empty? + name = info.shift + + # we are matching TOTAL stats and returning a hash of values + if name =~ /^cpu$/ + # return the CPU metrics sample as a hash + # filter out nil values, as some kernels don't have a 'guest' value + return Hash[cpu_metrics.zip(info.map(&:to_i))].reject { |_key, value| value.nil? } + end + end + end + + def sum_cpu_metrics(metrics) + # #YELLOW + metrics.values.reduce { |sum, metric| sum + metric } # rubocop:disable SingleLineBlockParams + end + + def run + cpu_sample1 = acquire_proc_stats + sleep(1) + cpu_sample2 = acquire_proc_stats + cpu_metrics = cpu_sample2.keys + + # we will sum all jiffy counts read in acquire_proc_stats + cpu_total1 = sum_cpu_metrics(cpu_sample1) + cpu_total2 = sum_cpu_metrics(cpu_sample2) + # total cpu usage in last second in CPU jiffs (1/100 s) + cpu_total_diff = cpu_total2 - cpu_total1 + # per CPU metric diff + cpu_sample_diff = Hash[cpu_sample2.map { |k, v| [k, v - cpu_sample1[k]] }] + + cpu_metrics.each do |metric| + metric_val = sprintf('%.02f', (cpu_sample_diff[metric] / cpu_total_diff.to_f) * 100) + output "#{config[:scheme]}.#{metric}", metric_val + end + ok + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/bin/metrics-cpu.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/bin/metrics-cpu.rb new file mode 100755 index 0000000..ccbeafe --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/bin/metrics-cpu.rb @@ -0,0 +1,71 @@ +#! /usr/bin/env ruby +# encoding: UTF-8 +# +# cpu-metrics +# +# DESCRIPTION: +# +# OUTPUT: +# metric data +# +# PLATFORMS: +# Linux +# +# DEPENDENCIES: +# gem: sensu-plugin +# +# USAGE: +# +# NOTES: +# +# LICENSE: +# Copyright 2012 Sonian, Inc +# Released under the same terms as Sensu (the MIT license); see LICENSE +# for details. +# +require 'sensu-plugin/metric/cli' +require 'socket' + +# +# CPU Graphite +# +class CpuGraphite < Sensu::Plugin::Metric::CLI::Graphite + option :scheme, + description: 'Metric naming scheme, text to prepend to metric', + short: '-s SCHEME', + long: '--scheme SCHEME', + default: "#{Socket.gethostname}.cpu" + + option :proc_path, + long: '--proc-path /proc', + proc: proc(&:to_f), + default: '/proc' + + def run + cpu_metrics = %w(user nice system idle iowait irq softirq steal guest) + other_metrics = %w(ctxt processes procs_running procs_blocked btime intr) + cpu_count = 0 + + File.open("#{config[:proc_path]}/stat", 'r').each_line do |line| + info = line.split(/\s+/) + next if info.empty? + name = info.shift + + if name =~ /cpu([0-9]+|)/ + # #YELLOW + cpu_count = cpu_count + 1 # rubocop:disable Style/SelfAssignment + name = 'total' if name == 'cpu' + info.size.times { |i| output "#{config[:scheme]}.#{name}.#{cpu_metrics[i]}", info[i] } + end + + output "#{config[:scheme]}.#{name}", info.last if other_metrics.include? name + end + if cpu_count > 0 + # writes the number of cpus, the minus 1 is because /proc/stat/ + # first line is a "cpu" which is stats for total cpus + output "#{config[:scheme]}.cpu_count", cpu_count - 1 + end + + ok + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/bin/metrics-numastat.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/bin/metrics-numastat.rb new file mode 100755 index 0000000..ef2c2a7 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/bin/metrics-numastat.rb @@ -0,0 +1,58 @@ +#!/usr/bin/env ruby +# +# metrics-numastat +# +# DESCRIPTION: +# Simple wrapper around `numastat` for getting per-NUMA-node memory stats. +# +# OUTPUT: +# metric data +# +# PLATFORMS: +# Linux +# +# DEPENDENCIES: +# gem: sensu-plugin +# +# USAGE: +# +# NOTES: +# +# LICENSE: +# Copyright 2016 Mitsutoshi Aoe +# Released under the same terms as Sensu (the MIT license); see LICENSE +# for details. +# + +require 'socket' +require 'sensu-plugin/metric/cli' + +class NumastatMetrics < Sensu::Plugin::Metric::CLI::Graphite + option :scheme, + description: 'Metric naming scheme, text to prepend to metric', + short: '-s SCHEME', + long: '--scheme SCHEME', + default: "#{Socket.gethostname}.numastat" + + def run + begin + output = `/usr/bin/numastat` + rescue Errno::ENOENT => err + unknown err + end + + nodes = [] + output.each_line do |line| + nodes = line.split(' ') if nodes.empty? + next unless /^([^\s]+)\s+(.+)$/ =~ line + key = Regexp.last_match[1] + vals = Regexp.last_match[2] + next if key.nil? || vals.nil? + nodes.zip(vals.split(' ')).each do |node, val| + output "#{config[:scheme]}.#{node}.#{key}", val + end + end + + ok + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/bin/metrics-user-pct-usage.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/bin/metrics-user-pct-usage.rb new file mode 100755 index 0000000..6577dfa --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/bin/metrics-user-pct-usage.rb @@ -0,0 +1,79 @@ +#! /usr/bin/env ruby +# +# System User Percentage Metric Plugin +# +# DESCRIPTION: +# Produces Graphite output of sum of %CPU over all processes by user. +# E.g., if user joe is running two processes, each using 10% CPU, and +# jane is running one process using 50% CPU, output will be: +# +# joe 20.0 (timestamp) +# jane 50.0 (timestamp) +# +# OUTPUT: +# Graphite metric data. +# +# PLATFORMS: +# Linux, BSD, OS X +# +# DEPENDENCIES: +# gem: sensu-plugin +# gem: socket +# +# USAGE: +# ./user-pct-usage-metrics.rb --ignore_inactive true +# NOTES: +# +# LICENSE: +# John VanDyk +# Released under the same terms as Sensu (the MIT license); see LICENSE +# for details. +# + +require 'sensu-plugin/metric/cli' +require 'socket' + +# +# User Percent +# +class UserPercent < Sensu::Plugin::Metric::CLI::Graphite + option :scheme, + description: 'Metric naming scheme prepended to .username', + long: '--scheme SCHEME', + default: "#{Socket.gethostname}.user_percent" + + option :ignore_inactive, + description: 'Boolean. If true, ignore users using 0% CPU', + long: '--ignore_inactive', + default: true + + option :uid, + description: 'Boolean. If true, uses uid instead of username', + long: '--uid', + default: false + + def run + timestamp = Time.now.to_i + usertype = config[:uid] ? 'uid' : 'user' + pslist = `ps -A -o #{usertype}= -o %cpu= -o %mem=` + + users = {} + pslist.lines.each do |line| + user, cpu, mem = line.split + users[user] = {} unless users[user] + h = { 'cpu' => cpu.to_f, 'mem' => mem.to_f } + users[user] = users[user].merge(h) { |_key, oldval, newval| newval + oldval } + end + + if config[:ignore_inactive] + users.delete_if { |_key, value| value['cpu'] == 0 } + end + + users.each do |user, h| + h.each do |key, value| + output [config[:scheme], user].join(".#{key}."), value, timestamp + end + end + ok + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/lib/sensu-plugins-cpu-checks.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/lib/sensu-plugins-cpu-checks.rb new file mode 100644 index 0000000..e98114f --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/lib/sensu-plugins-cpu-checks.rb @@ -0,0 +1 @@ +require 'sensu-plugins-cpu-checks/version' diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/lib/sensu-plugins-cpu-checks/version.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/lib/sensu-plugins-cpu-checks/version.rb new file mode 100644 index 0000000..d21de22 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/lib/sensu-plugins-cpu-checks/version.rb @@ -0,0 +1,9 @@ +module SensuPluginsCpuChecks + module Version + MAJOR = 1 + MINOR = 0 + PATCH = 0 + + VER_STRING = [MAJOR, MINOR, PATCH].compact.join('.') + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-influxdb-1.1.0/CHANGELOG.md b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-influxdb-1.1.0/CHANGELOG.md new file mode 100644 index 0000000..9fe4847 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-influxdb-1.1.0/CHANGELOG.md @@ -0,0 +1,77 @@ +#Change Log +This project adheres to [Semantic Versioning](http://semver.org/). + +This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachangelog.com/) + +## [Unreleased] + +## [1.1.0] - 2016-12-01 +### Added +- Added tags support for mutator-influxdb-line-protocol.rb +- Added retry support for check-influxdb-query.rb - The InfluxDB gem by default retries indefinitely and will cause the query to hang. A retry of 12 will retry for approx 37 seconds. + +### Changed +- Update to `influxdb` gem 0.3.13 + +## [1.0.0] - 2016-10-06 +### Added +- Ruby 2.3.0 support + +### Removed +- Ruby 1.9.3 support + +### Changed +- Update `influxdb` dep to 0.3.10 +- Update `dentaku` dep to 2.0.9 +- Update `sensu-plugin` dep to ~> 1.3 +- Update `jsonpath` dep to 0.5.8 +- Update to rubocop 0.40 and cleanup + +### [0.0.7] - 2016-04-26 +- Line protocol mutator extension +- added tags support for metrics-influxdb.rb +- Fixed option tag in check-influxdb-query +- added support for storing check status for metrics-influxdb.rb +- metrics-influxdb.rb will now create the database if needed +- metrics-influxdb.rb can now be configured to use a specific settings block + +### [0.0.6] - 2016-04-18 +- supress warning if only checking for an existing return value in check-influxdb-query. + +### [0.0.5] - 2015-10-19 +- added support for https in check-influxdb. +- pass ssl arguments to the influxdb object in check-influxdb-query. +- renamed the config option in check-influxdb from ssl to verify_ssl. +- changed README to update the config option ssl_ca_cert. + +### [0.0.4] - 2015-08-10 +- updated metrics-influxdb.rb to symbolize keys for InfluxDB::Client +- updated influxdb gem to 0.2.2 +- updated metrics-influxdb.rb to support influxdb 0.9.x +- updated check-influxdb.rb and check-influxdb-query.rb to support influxdb 0.9.x +- updated README.md file + +## [0.0.3] - 2015-07-14 +### Changed +- updated sensu-plugin gem to 1.2.0 + +## [0.0.2] - 2015-06-03 +### Fixed +- added binstubs + +### Changed +- removed cruft from /lib + +## 0.0.1 - 2015-04-29 +### Added +- initial release + +[Unreleased]: https://github.com/sensu-plugins/sensu-plugins-influxdb/compare/1.1.0...HEAD +[1.1.0]: https://github.com/sensu-plugins/sensu-plugins-influxdb/compare/1.0.0...1.1.0 +[1.0.0]: https://github.com/sensu-plugins/sensu-plugins-influxdb/compare/0.0.7...1.0.0 +[0.0.7]: https://github.com/sensu-plugins/sensu-plugins-influxdb/compare/0.0.6...0.0.7 +[0.0.6]: https://github.com/sensu-plugins/sensu-plugins-influxdb/compare/0.0.5...0.0.6 +[0.0.5]: https://github.com/sensu-plugins/sensu-plugins-influxdb/compare/0.0.4...0.0.5 +[0.0.4]: https://github.com/sensu-plugins/sensu-plugins-influxdb/compare/0.0.3...0.0.4 +[0.0.3]: https://github.com/sensu-plugins/sensu-plugins-influxdb/compare/0.0.2...0.0.3 +[0.0.2]: https://github.com/sensu-plugins/sensu-plugins-influxdb/compare/0.0.1...0.0.2 diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-influxdb-1.1.0/LICENSE b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-influxdb-1.1.0/LICENSE new file mode 100644 index 0000000..f661cbd --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-influxdb-1.1.0/LICENSE @@ -0,0 +1,22 @@ +Copyright (c) 2015 Sensu-Plugins + +MIT License + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-influxdb-1.1.0/README.md b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-influxdb-1.1.0/README.md new file mode 100644 index 0000000..a9a6306 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-influxdb-1.1.0/README.md @@ -0,0 +1,108 @@ +## Sensu-Plugins-influxdb + +[![Build Status](https://travis-ci.org/sensu-plugins/sensu-plugins-influxdb.svg?branch=master)](https://travis-ci.org/sensu-plugins/sensu-plugins-influxdb) +[![Gem Version](https://badge.fury.io/rb/sensu-plugins-influxdb.svg)](http://badge.fury.io/rb/sensu-plugins-influxdb) +[![Code Climate](https://codeclimate.com/github/sensu-plugins/sensu-plugins-influxdb/badges/gpa.svg)](https://codeclimate.com/github/sensu-plugins/sensu-plugins-influxdb) +[![Test Coverage](https://codeclimate.com/github/sensu-plugins/sensu-plugins-influxdb/badges/coverage.svg)](https://codeclimate.com/github/sensu-plugins/sensu-plugins-influxdb) +[![Dependency Status](https://gemnasium.com/sensu-plugins/sensu-plugins-influxdb.svg)](https://gemnasium.com/sensu-plugins/sensu-plugins-influxdb) + +## Functionality + +## Files + * bin/check-influxdb.rb + * bin/check-influxdb-query.rb + * bin/metrics-influxdb.rb + * bin/mutator-influxdb-line-protocol.rb + +## Usage - metrics-influxdb.rb +Add the following to `/etc/sensu/conf.d/influx.conf` "plugin expects `influxdb` to be a top level node in the json +**metrics-influxdb** +``` +{ + "influxdb": { + "hosts" : ["influxdb.familyguy.com"], + "host" : "influxdb.familyguy.com", + "port" : "8086", + "username" : "root", + "password" : "root", + "database" : "stats", + # OPTIONAL + "time_precision": "s", + "use_ssl" : false, + "verify_ssl" : true, + "ssl_ca_cert" : "path to the ca certificate file", + "auth_method" : "params", + "initial_delay" : 0.01, + "max_delay" : 30, + "open_timeout" : 5, + "read_timeout" : 300, + "retry" : null, + "prefix" : "", + "denormalize" : true, + "status" : true + } +} +``` +Then add the following to your `/ect/sensu/conf.d/handlers.conf`: +``` +{ + "handlers": { + "influx-tcp": { + "type": "pipe", + "command": "/opt/sensu/embedded/bin/metrics-influxdb.rb" + } + } +} +``` + +Setting "status" to true will store the metric using the status as the value and the check name as the series + +## Usage - mutator-influxdb-line-protocol.rb +Add the mutator-influxdb-line-protocol.rb file into /etc/sensu/extensions/ + +Then add the following to your `/ect/sensu/conf.d/handlers.conf`: +``` +{ + "handlers": { + "influxdb_udp": { + "type": "udp", + "socket": { + "host": "localhost", + "port": 8090 + }, + "mutator": "influxdb_line_protocol", + } + } +} +``` + +## Check configuration +To ship additional tags to your metrics via mutator-influxdb-line-protocol.rb (only available in influxdb >= 0.9), just add a tags block inside your check. + +``` +{ + "checks": { + "cpu-metrics": { + "command": "/opt/sensu/embedded/bin/metrics-cpu-pcnt-usage.rb", + "handlers": [ + "influxdb_udp" + ], + "interval": 60, + "subscribers": [ + "base" + ], + "type": "metric", + "standalone": false, + "tags": { + "group": "operations", + } + } + } +} +``` + +## Installation + +[Installation and Setup](http://sensu-plugins.io/docs/installation_instructions.html) + +## Notes diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-influxdb-1.1.0/bin/check-influxdb-query.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-influxdb-1.1.0/bin/check-influxdb-query.rb new file mode 100755 index 0000000..a5525e4 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-influxdb-1.1.0/bin/check-influxdb-query.rb @@ -0,0 +1,197 @@ +#! /usr/bin/env ruby +# +# check-influxdb-query +# +# DESCRIPTION: +# Check InfluxDB queries +# +# OUTPUT: +# plain text +# +# PLATFORMS: +# Linux +# +# DEPENDENCIES: +# gem: sensu-plugin +# gem: jsonpath +# gem: json +# gem: dentaku +# +# USAGE: +# example commands +# +# NOTES: +# See the README here https://github.com/zeroXten/check_influxdb_query +# +# LICENSE: +# Copyright 2014, Fraser Scott +# Released under the same terms as Sensu (the MIT license); see LICENSE +# for details. +# + +require 'influxdb' +require 'sensu-plugin/check/cli' +require 'json' +require 'jsonpath' +require 'dentaku' + +# VERSION = '0.1.0' + +# +# Check Influxdb Query +# +class CheckInfluxdbQuery < Sensu::Plugin::Check::CLI + check_name nil + option :host, + short: '-H HOST', + long: '--host HOST', + default: 'localhost', + description: 'InfluxDB host' + + option :port, + short: '-P PORT', + long: '--port PORT', + default: '8086', + description: 'InfluxDB port' + + option :use_ssl, + description: 'Turn on/off SSL (default: false)', + short: '-s', + long: '--use_ssl', + boolean: true, + default: false + + option :verify_ssl, + description: 'Turn on/off using SSL certificate (default: false)', + short: '-v', + long: '--verify_ssl', + boolean: true, + default: false + + option :ssl_ca_cert, + description: 'Path to the ssl ca certificate to connect to the InfluxDB server', + short: '-C CA_CERT', + long: '--ssl_ca_cert CA_CERT' + + option :database, + short: '-d DATABASE', + long: '--database DATABASE', + default: 'influxdb', + description: 'InfluxDB database name' + + option :retry, + short: '-r RETRY', + long: '--retry RETRY', + description: 'InfluxDB retry count with exponential back-off', + proc: proc(&:to_i), + default: 12 + + option :username, + short: '-u USERNAME', + long: '--username USERNAME', + default: 'root', + description: 'API username' + + option :password, + short: '-p PASSWORD', + long: '--password PASSWORD', + default: 'root', + description: 'API password' + + option :query, + short: '-q QUERY', + long: '--query QUERY', + required: true, + description: 'Query to run. See https://influxdb.com/docs/v0.9/query_language/query_syntax.html' + + option :alias, + short: '-a ALIAS', + long: '--alias ALIAS', + default: nil, + description: 'Alias of query (e.g. if query and output gets too long)' + + option :jsonpath, + short: '-j JSONPATH', + long: '--jsonpath JSONPATH', + default: nil, + description: 'Json path to select value. Takes the first value, or 0 if none. See http://goessner.net/articles/JsonPath/' + + option :noresult, + short: '-n', + long: '--noresult', + boolean: true, + description: 'Go critical for no result from query' + + option :warning, + short: '-w WARNING', + long: '--warning WARNING', + default: nil, + description: "Warning threshold expression. E.g. 'value >= 10'. See https://github.com/rubysolo/dentaku" + + option :critical, + short: '-c CRITICAL', + long: '--critical CRITICAL', + default: nil, + description: "Critical threshold expression. E.g. 'value >= 20'. See https://github.com/rubysolo/dentaku" + + option :help, + short: '-h', + long: '--help', + description: 'Show this message', + on: :tail, + boolean: true, + show_options: true, + exit: 0 + + # option :version, + # short: '-v', + # long: '--version', + # description: 'Show version', + # on: :tail, + # boolean: true, + # proc: proc { puts "Version #{VERSION}" }, + # exit: 0 + + def run + influxdb = InfluxDB::Client.new config[:database], + host: config[:host], + port: config[:port], + use_ssl: config[:use_ssl], + verify_ssl: config[:verify_ssl], + ssl_ca_cert: config[:ssl_ca_cert], + retry: config[:retry], + username: config[:username], + password: config[:password] + + value = influxdb.query config[:query] + + query_name = if config[:alias] + config[:alias] + else + config[:query] + end + + if config[:noresult] && value.empty? + critical "No result for query '#{query_name}'" + elsif config[:noresult] && !config[:jsonpath] && !value.empty? + ok "Value returned for query '#{query_name}'" + end + + if config[:jsonpath] + json_path = JsonPath.new(config[:jsonpath]) + value = json_path.on(value).first || 0 + + calc = Dentaku::Calculator.new + if config[:critical] && calc.evaluate(config[:critical], value: value) + critical "Value '#{value}' matched '#{config[:critical]}' for query '#{query_name}'" + elsif config[:warning] && calc.evaluate(config[:warning], value: value) + warning "Value '#{value}' matched '#{config[:warning]}' for query '#{query_name}'" + else + ok "Value '#{value}' ok for query '#{query_name}'" + end + else + puts 'Debug output. Use -j to check value...' + puts JSON.pretty_generate(value) + end + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-influxdb-1.1.0/bin/check-influxdb.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-influxdb-1.1.0/bin/check-influxdb.rb new file mode 100755 index 0000000..78860be --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-influxdb-1.1.0/bin/check-influxdb.rb @@ -0,0 +1,97 @@ +#! /usr/bin/env ruby +# +# check-influx +# +# DESCRIPTION: +# Check if /ping endopoint is responding +# +# OUTPUT: +# plain text +# +# PLATFORMS: +# Linux +# +# DEPENDENCIES: +# gem: sensu-plugin +# +# USAGE: +# #YELLOW +# +# NOTES: +# +# LICENSE: +# Copyright (C) 2014, Mitsutoshi Aoe +# Released under the same terms as Sensu (the MIT license); see LICENSE +# for details. +# + +require 'sensu-plugin/check/cli' +require 'net/https' + +# +# Check InfluxDB +# +class CheckInfluxDB < Sensu::Plugin::Check::CLI + option :host, + description: 'Host address of the InfluxDB server', + short: '-h HOST', + long: '--host HOST', + default: 'localhost' + + option :port, + description: 'Port number of the InfluxDB server', + short: '-p PORT', + long: '--port PORT', + proc: proc(&:to_i), + default: 8086 + + option :use_ssl, + description: 'Turn on/off SSL (default: false)', + short: '-s', + long: '--use_ssl', + boolean: true, + default: false + + option :verify_ssl, + description: 'Turn on/off using SSL certificate (default: false)', + short: '-v', + long: '--verify_ssl', + boolean: true, + default: false + + option :ssl_ca_cert, + description: 'Path to the ssl ca certificate to connect to the InfluxDB server', + short: '-c CA_CERT', + long: '--ssl_ca_cert CA_CERT' + + option :timeout, + description: 'Seconds to wait for the connection to open or read (default: 1.0s)', + short: '-t SECONDS', + long: '--timeout SECONDS', + proc: proc(&:to_f), + default: 1.0 + + def run + http = Net::HTTP.new(config[:host], config[:port]) + http.open_timeout = config[:timeout] + http.read_timeout = config[:timeout] + http.use_ssl = config[:use_ssl] + if config[:verify_ssl] + http.ca_file = config[:ssl_ca_cert] + http.verify_mode = OpenSSL::SSL::VERIFY_PEER + else + http.verify_mode = OpenSSL::SSL::VERIFY_NONE + end + http.start do + response = http.get('/ping') + status_line = "#{response.code} #{response.message}" + if response.is_a?(Net::HTTPSuccess) + ok status_line + else + critical status_line + end + end + rescue => e + critical e.to_s + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-influxdb-1.1.0/bin/metrics-influxdb.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-influxdb-1.1.0/bin/metrics-influxdb.rb new file mode 100755 index 0000000..f525c3a --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-influxdb-1.1.0/bin/metrics-influxdb.rb @@ -0,0 +1,90 @@ +#! /usr/bin/env ruby +# +# metrics-influx.rb +# +# DESCRIPTION: +# +# OUTPUT: +# plain text +# +# PLATFORMS: +# Linux +# +# DEPENDENCIES: +# gem: sensu-plugin +# gem: influxdb +# +# USAGE: +# #YELLOW +# +# NOTES: +# +# LICENSE: +# Copyright (C) 2015, Sensu Plugins +# Released under the same terms as Sensu (the MIT license); see LICENSE +# for details. +# + +require 'sensu-handler' +gem 'influxdb', '>=0.2.0' +require 'influxdb' + +# +# Sensu To Influxdb +# +class SensuToInfluxDB < Sensu::Handler + option :config, + description: 'Configuration information to use', + short: '-c CONFIG', + long: '--config CONFIG', + default: 'influxdb' + + def filter; end + + def create_point(series, value, time) + point = { series: series, + tags: { host: @event['client']['name'], metric: @event['check']['name'] }, + values: { value: value }, + timestamp: time } + point[:tags].merge!(@event['check']['tags']) unless @event['check']['tags'].nil? + point + end + + def parse_output + data = [] + metric_raw = @event['check']['output'] + metric_raw.split("\n").each do |metric| + m = metric.split + next unless m.count == 3 + key = m[0].split('.', 2)[1] + key.tr!('.', '_') + value = m[1].to_f + time = m[2] + point = create_point(key, value, time) + data.push(point) + end + data + end + + def check_status + data = [] + data.push(create_point(@event['check']['name'], @event['check']['status'], @event['client']['timestamp'])) + end + + def handle + opts = settings[config[:config]].each_with_object({}) do |(k, v), sym| + sym[k.to_sym] = v + end + database = opts[:database] + + influxdb_data = InfluxDB::Client.new database, opts + influxdb_data.create_database(database) # Ensure the database exists + + data = if opts[:status] == false || opts[:status].nil? + parse_output + else + check_status + end + influxdb_data.write_points(data) + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-influxdb-1.1.0/bin/mutator-influxdb-line-protocol.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-influxdb-1.1.0/bin/mutator-influxdb-line-protocol.rb new file mode 100755 index 0000000..d9a5b40 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-influxdb-1.1.0/bin/mutator-influxdb-line-protocol.rb @@ -0,0 +1,62 @@ +#! /usr/bin/env ruby +# +# mutator-influxdb-line-protocol +# +# DESCRIPTION: +# Mutates check results to conform to InfluxDB's line protocol format +# +# Place this file in /etc/sensu/extensions and modify your handlers JSON config +# +# handlers.json +# { +# "influxdb_udp": { +# "type": "udp", +# "mutator": "influxdb_line_protocol", +# "socket": { +# "host": "mgt-monitor-db1", +# "port": 8090 +# } +# } +# } + +require 'sensu/extension' + +module Sensu + module Extension + class InfluxDBLineProtocol < Mutator + def name + 'influxdb_line_protocol' + end + + def description + "returns check output formatted for InfluxDB's line protocol" + end + + def run(event) + tags = event[:check][:tags] + host = event[:client][:name] + metric = event[:check][:name] + output = event[:check][:output] + + data = [] + output.split("\n").each do |result| + m = result.split + next unless m.count == 3 + key = m[0].split('.', 2)[1] + key.tr!('.', '_') + value = m[1].to_f + time = m[2].ljust(19, '0') + linedata = "#{key},host=#{host},metric=#{metric}" + if tags + tags.each do |tagname, tagvalue| + linedata << ",#{tagname}=#{tagvalue}" + end + end + data << "#{linedata} value=#{value} #{time}" + end + + yield data.join("\n"), 0 + end + end + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-influxdb-1.1.0/lib/sensu-plugins-influxdb.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-influxdb-1.1.0/lib/sensu-plugins-influxdb.rb new file mode 100644 index 0000000..4864c4e --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-influxdb-1.1.0/lib/sensu-plugins-influxdb.rb @@ -0,0 +1 @@ +require 'sensu-plugins-influxdb/version' diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-influxdb-1.1.0/lib/sensu-plugins-influxdb/version.rb b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-influxdb-1.1.0/lib/sensu-plugins-influxdb/version.rb new file mode 100644 index 0000000..3797363 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-influxdb-1.1.0/lib/sensu-plugins-influxdb/version.rb @@ -0,0 +1,9 @@ +module SensuPluginsInfluxdb + module Version + MAJOR = 1 + MINOR = 1 + PATCH = 0 + + VER_STRING = [MAJOR, MINOR, PATCH].compact.join('.') + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/specifications/cause-0.1.gemspec b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/specifications/cause-0.1.gemspec new file mode 100644 index 0000000..132a541 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/specifications/cause-0.1.gemspec @@ -0,0 +1,21 @@ +# -*- encoding: utf-8 -*- +# stub: cause 0.1 ruby lib + +Gem::Specification.new do |s| + s.name = "cause".freeze + s.version = "0.1" + + s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version= + s.require_paths = ["lib".freeze] + s.authors = ["Conrad Irwin".freeze] + s.date = "2013-12-27" + s.description = "Allows you access to the error that was being handled when this exception was raised.".freeze + s.email = ["conrad@bugsnag.com".freeze] + s.homepage = "http://github.com/ConradIrwin/cause".freeze + s.licenses = ["MIT".freeze] + s.required_ruby_version = Gem::Requirement.new(">= 1.8.7".freeze) + s.rubygems_version = "2.6.7".freeze + s.summary = "A backport of Exception#cause from Ruby 2.1.0".freeze + + s.installed_by_version = "2.6.7" if s.respond_to? :installed_by_version +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/specifications/dentaku-2.0.9.gemspec b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/specifications/dentaku-2.0.9.gemspec new file mode 100644 index 0000000..bb160ce --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/specifications/dentaku-2.0.9.gemspec @@ -0,0 +1,39 @@ +# -*- encoding: utf-8 -*- +# stub: dentaku 2.0.9 ruby lib + +Gem::Specification.new do |s| + s.name = "dentaku".freeze + s.version = "2.0.9" + + s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version= + s.require_paths = ["lib".freeze] + s.authors = ["Solomon White".freeze] + s.date = "2016-09-19" + s.description = " Dentaku is a parser and evaluator for mathematical formulas\n".freeze + s.email = ["rubysolo@gmail.com".freeze] + s.homepage = "http://github.com/rubysolo/dentaku".freeze + s.licenses = ["MIT".freeze] + s.rubyforge_project = "dentaku".freeze + s.rubygems_version = "2.6.7".freeze + s.summary = "A formula language parser and evaluator".freeze + + s.installed_by_version = "2.6.7" if s.respond_to? :installed_by_version + + if s.respond_to? :specification_version then + s.specification_version = 4 + + if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then + s.add_development_dependency(%q.freeze, [">= 0"]) + s.add_development_dependency(%q.freeze, [">= 0"]) + s.add_development_dependency(%q.freeze, [">= 0"]) + else + s.add_dependency(%q.freeze, [">= 0"]) + s.add_dependency(%q.freeze, [">= 0"]) + s.add_dependency(%q.freeze, [">= 0"]) + end + else + s.add_dependency(%q.freeze, [">= 0"]) + s.add_dependency(%q.freeze, [">= 0"]) + s.add_dependency(%q.freeze, [">= 0"]) + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/specifications/influxdb-0.3.13.gemspec b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/specifications/influxdb-0.3.13.gemspec new file mode 100644 index 0000000..2209205 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/specifications/influxdb-0.3.13.gemspec @@ -0,0 +1,50 @@ +# -*- encoding: utf-8 -*- +# stub: influxdb 0.3.13 ruby lib + +Gem::Specification.new do |s| + s.name = "influxdb".freeze + s.version = "0.3.13" + + s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version= + s.require_paths = ["lib".freeze] + s.authors = ["Todd Persen".freeze] + s.date = "2016-11-23" + s.description = "This is the official Ruby library for InfluxDB.".freeze + s.email = ["influxdb@googlegroups.com".freeze] + s.homepage = "http://influxdb.org".freeze + s.licenses = ["MIT".freeze] + s.rubygems_version = "2.6.7".freeze + s.summary = "Ruby library for InfluxDB.".freeze + + s.installed_by_version = "2.6.7" if s.respond_to? :installed_by_version + + if s.respond_to? :specification_version then + s.specification_version = 4 + + if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then + s.add_runtime_dependency(%q.freeze, [">= 0"]) + s.add_runtime_dependency(%q.freeze, [">= 0"]) + s.add_development_dependency(%q.freeze, [">= 0"]) + s.add_development_dependency(%q.freeze, ["~> 1.3"]) + s.add_development_dependency(%q.freeze, ["~> 3.5.0"]) + s.add_development_dependency(%q.freeze, ["~> 2.1.0"]) + s.add_development_dependency(%q.freeze, ["~> 0.41.2"]) + else + s.add_dependency(%q.freeze, [">= 0"]) + s.add_dependency(%q.freeze, [">= 0"]) + s.add_dependency(%q.freeze, [">= 0"]) + s.add_dependency(%q.freeze, ["~> 1.3"]) + s.add_dependency(%q.freeze, ["~> 3.5.0"]) + s.add_dependency(%q.freeze, ["~> 2.1.0"]) + s.add_dependency(%q.freeze, ["~> 0.41.2"]) + end + else + s.add_dependency(%q.freeze, [">= 0"]) + s.add_dependency(%q.freeze, [">= 0"]) + s.add_dependency(%q.freeze, [">= 0"]) + s.add_dependency(%q.freeze, ["~> 1.3"]) + s.add_dependency(%q.freeze, ["~> 3.5.0"]) + s.add_dependency(%q.freeze, ["~> 2.1.0"]) + s.add_dependency(%q.freeze, ["~> 0.41.2"]) + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/specifications/jsonpath-0.5.8.gemspec b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/specifications/jsonpath-0.5.8.gemspec new file mode 100644 index 0000000..5e92911 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/specifications/jsonpath-0.5.8.gemspec @@ -0,0 +1,52 @@ +# -*- encoding: utf-8 -*- +# stub: jsonpath 0.5.8 ruby lib + +Gem::Specification.new do |s| + s.name = "jsonpath".freeze + s.version = "0.5.8" + + s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version= + s.require_paths = ["lib".freeze] + s.authors = ["Joshua Hull".freeze] + s.date = "2015-11-09" + s.description = "Ruby implementation of http://goessner.net/articles/JsonPath/.".freeze + s.email = "joshbuddy@gmail.com".freeze + s.executables = ["jsonpath".freeze] + s.extra_rdoc_files = ["README.md".freeze] + s.files = ["README.md".freeze, "bin/jsonpath".freeze] + s.homepage = "http://github.com/joshbuddy/jsonpath".freeze + s.licenses = ["MIT".freeze] + s.rdoc_options = ["--charset=UTF-8".freeze] + s.rubyforge_project = "jsonpath".freeze + s.rubygems_version = "2.6.7".freeze + s.summary = "Ruby implementation of http://goessner.net/articles/JsonPath/".freeze + + s.installed_by_version = "2.6.7" if s.respond_to? :installed_by_version + + if s.respond_to? :specification_version then + s.specification_version = 4 + + if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then + s.add_runtime_dependency(%q.freeze, [">= 0"]) + s.add_development_dependency(%q.freeze, [">= 0"]) + s.add_development_dependency(%q.freeze, [">= 0"]) + s.add_development_dependency(%q.freeze, ["~> 2.2.0"]) + s.add_development_dependency(%q.freeze, [">= 0"]) + s.add_development_dependency(%q.freeze, [">= 0"]) + else + s.add_dependency(%q.freeze, [">= 0"]) + s.add_dependency(%q.freeze, [">= 0"]) + s.add_dependency(%q.freeze, [">= 0"]) + s.add_dependency(%q.freeze, ["~> 2.2.0"]) + s.add_dependency(%q.freeze, [">= 0"]) + s.add_dependency(%q.freeze, [">= 0"]) + end + else + s.add_dependency(%q.freeze, [">= 0"]) + s.add_dependency(%q.freeze, [">= 0"]) + s.add_dependency(%q.freeze, [">= 0"]) + s.add_dependency(%q.freeze, ["~> 2.2.0"]) + s.add_dependency(%q.freeze, [">= 0"]) + s.add_dependency(%q.freeze, [">= 0"]) + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/specifications/multi_json-1.12.1.gemspec b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/specifications/multi_json-1.12.1.gemspec new file mode 100644 index 0000000..1540828 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/specifications/multi_json-1.12.1.gemspec @@ -0,0 +1,33 @@ +# -*- encoding: utf-8 -*- +# stub: multi_json 1.12.1 ruby lib + +Gem::Specification.new do |s| + s.name = "multi_json".freeze + s.version = "1.12.1" + + s.required_rubygems_version = Gem::Requirement.new(">= 1.3.5".freeze) if s.respond_to? :required_rubygems_version= + s.require_paths = ["lib".freeze] + s.authors = ["Michael Bleigh".freeze, "Josh Kalderimis".freeze, "Erik Michaels-Ober".freeze, "Pavel Pravosud".freeze] + s.cert_chain = ["-----BEGIN CERTIFICATE-----\nMIIDcDCCAligAwIBAgIBATANBgkqhkiG9w0BAQUFADA/MQ4wDAYDVQQDDAVwYXZl\nbDEYMBYGCgmSJomT8ixkARkWCHByYXZvc3VkMRMwEQYKCZImiZPyLGQBGRYDY29t\nMB4XDTE2MDQyNDIyMDk1MVoXDTE3MDQyNDIyMDk1MVowPzEOMAwGA1UEAwwFcGF2\nZWwxGDAWBgoJkiaJk/IsZAEZFghwcmF2b3N1ZDETMBEGCgmSJomT8ixkARkWA2Nv\nbTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAK+YCSpSUOeZvxOyp0Zm\nDhlQ9Kc8ZxgaB3ekCS6lp7hV+eE6nZ84j4RLEqhfx0Vffx+yCmSx0lWum6eY9aOy\nrr+uCtiSiL+HR7t6KHqQ5myXwIvT7B+SqMYw8223fMFZMUit73PfTaMlIon+EsZB\n9TWzVU7MSRIHLr8P92/kExOuDhVcqFgmz+pWLeZjCk7r0JI0vxacFEK+ONjXThHk\nW1IRwy8qaFNiUdnIfTRgZV45T/PHzuLttdkgySTDQkZp198t9Y0m0eEDhpPjHNlr\nKoXtqUIqk1lmgsKKrOj4vsSX004v869GT45C4qR4/Oa2OyUsWiPf8N3GCYDBnK9C\nRDcCAwEAAaN3MHUwCQYDVR0TBAIwADALBgNVHQ8EBAMCBLAwHQYDVR0OBBYEFKm/\njUdmc0kO/erio7IwB4zhYGmxMB0GA1UdEQQWMBSBEnBhdmVsQHByYXZvc3VkLmNv\nbTAdBgNVHRIEFjAUgRJwYXZlbEBwcmF2b3N1ZC5jb20wDQYJKoZIhvcNAQEFBQAD\nggEBAGZprwh9PfxTaukluduGO2NWJpI5NC7A/OpoVFrtLTlMKDeoPvCgmNdSejS3\n6CyH8P3SI3OEkymRnLtQiJeQ//WDb7QPPQDPG0ZuxAylc35ITz7jTPAFC41AoTWM\neSDWXP6yq0Gi6vlcvyIoBrvfFRPsg/gGhUp5DYKDLYzaEjNE30bME9fwDvlab7XR\nv4so5Zmmcof+9apAoaXDtj7HijhJWJcia8GWN5ycuDX38qMcpSU9/PF84s567W6e\nDe8xFEGqLG8vclcTv7gGjDJH5FJTXuwLg41wc8p4ONXEBgLiaC7+S/DVDXWpYxuB\nakI17ua4eRKTFNvBtzP1802SP1k=\n-----END CERTIFICATE-----\n".freeze] + s.date = "2016-05-18" + s.description = "A common interface to multiple JSON libraries, including Oj, Yajl, the JSON gem (with C-extensions), the pure-Ruby JSON gem, NSJSONSerialization, gson.rb, JrJackson, and OkJson.".freeze + s.email = ["michael@intridea.com".freeze, "josh.kalderimis@gmail.com".freeze, "sferik@gmail.com".freeze, "pavel@pravosud.com".freeze] + s.homepage = "http://github.com/intridea/multi_json".freeze + s.licenses = ["MIT".freeze] + s.rubygems_version = "2.6.7".freeze + s.summary = "A common interface to multiple JSON libraries.".freeze + + s.installed_by_version = "2.6.7" if s.respond_to? :installed_by_version + + if s.respond_to? :specification_version then + s.specification_version = 4 + + if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then + s.add_development_dependency(%q.freeze, ["~> 1.0"]) + else + s.add_dependency(%q.freeze, ["~> 1.0"]) + end + else + s.add_dependency(%q.freeze, ["~> 1.0"]) + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/specifications/sensu-plugins-influxdb-1.1.0.gemspec b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/specifications/sensu-plugins-influxdb-1.1.0.gemspec new file mode 100644 index 0000000..1cdc141 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/files/embedded/lib/ruby/gems/2.3.0/specifications/sensu-plugins-influxdb-1.1.0.gemspec @@ -0,0 +1,73 @@ +# -*- encoding: utf-8 -*- +# stub: sensu-plugins-influxdb 1.1.0 ruby lib + +Gem::Specification.new do |s| + s.name = "sensu-plugins-influxdb".freeze + s.version = "1.1.0" + + s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version= + s.metadata = { "development_status" => "active", "maintainer" => "sensu-plugin", "production_status" => "unstable - testing recommended", "release_draft" => "false", "release_prerelease" => "false" } if s.respond_to? :metadata= + s.require_paths = ["lib".freeze] + s.authors = ["Sensu-Plugins and contributors".freeze] + s.date = "2016-12-02" + s.description = "This plugin provides native InfluxDB instrumentation\n for monitoring and metrics collection, including:\n service health via `/ping`, running queries, and service\n metrics.".freeze + s.email = "".freeze + s.executables = ["check-influxdb-query.rb".freeze, "check-influxdb.rb".freeze, "metrics-influxdb.rb".freeze, "mutator-influxdb-line-protocol.rb".freeze] + s.files = ["bin/check-influxdb-query.rb".freeze, "bin/check-influxdb.rb".freeze, "bin/metrics-influxdb.rb".freeze, "bin/mutator-influxdb-line-protocol.rb".freeze] + s.homepage = "https://github.com/sensu-plugins/sensu-plugins-influxdb".freeze + s.licenses = ["MIT".freeze] + s.post_install_message = "You can use the embedded Ruby by setting EMBEDDED_RUBY=true in /etc/default/sensu".freeze + s.required_ruby_version = Gem::Requirement.new(">= 2.0.0".freeze) + s.rubygems_version = "2.6.7".freeze + s.summary = "Sensu plugins for influxdb".freeze + + s.installed_by_version = "2.6.7" if s.respond_to? :installed_by_version + + if s.respond_to? :specification_version then + s.specification_version = 4 + + if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then + s.add_runtime_dependency(%q.freeze, ["= 2.0.9"]) + s.add_runtime_dependency(%q.freeze, ["= 0.3.13"]) + s.add_runtime_dependency(%q.freeze, ["= 0.5.8"]) + s.add_runtime_dependency(%q.freeze, ["~> 1.3"]) + s.add_development_dependency(%q.freeze, ["~> 1.7"]) + s.add_development_dependency(%q.freeze, ["~> 0.4"]) + s.add_development_dependency(%q.freeze, ["~> 1.3"]) + s.add_development_dependency(%q.freeze, ["~> 0.10"]) + s.add_development_dependency(%q.freeze, ["~> 10.0"]) + s.add_development_dependency(%q.freeze, ["~> 3.2"]) + s.add_development_dependency(%q.freeze, ["~> 3.1"]) + s.add_development_dependency(%q.freeze, ["~> 0.40.0"]) + s.add_development_dependency(%q.freeze, ["~> 0.8"]) + else + s.add_dependency(%q.freeze, ["= 2.0.9"]) + s.add_dependency(%q.freeze, ["= 0.3.13"]) + s.add_dependency(%q.freeze, ["= 0.5.8"]) + s.add_dependency(%q.freeze, ["~> 1.3"]) + s.add_dependency(%q.freeze, ["~> 1.7"]) + s.add_dependency(%q.freeze, ["~> 0.4"]) + s.add_dependency(%q.freeze, ["~> 1.3"]) + s.add_dependency(%q.freeze, ["~> 0.10"]) + s.add_dependency(%q.freeze, ["~> 10.0"]) + s.add_dependency(%q.freeze, ["~> 3.2"]) + s.add_dependency(%q.freeze, ["~> 3.1"]) + s.add_dependency(%q.freeze, ["~> 0.40.0"]) + s.add_dependency(%q.freeze, ["~> 0.8"]) + end + else + s.add_dependency(%q.freeze, ["= 2.0.9"]) + s.add_dependency(%q.freeze, ["= 0.3.13"]) + s.add_dependency(%q.freeze, ["= 0.5.8"]) + s.add_dependency(%q.freeze, ["~> 1.3"]) + s.add_dependency(%q.freeze, ["~> 1.7"]) + s.add_dependency(%q.freeze, ["~> 0.4"]) + s.add_dependency(%q.freeze, ["~> 1.3"]) + s.add_dependency(%q.freeze, ["~> 0.10"]) + s.add_dependency(%q.freeze, ["~> 10.0"]) + s.add_dependency(%q.freeze, ["~> 3.2"]) + s.add_dependency(%q.freeze, ["~> 3.1"]) + s.add_dependency(%q.freeze, ["~> 0.40.0"]) + s.add_dependency(%q.freeze, ["~> 0.8"]) + end +end diff --git a/deployment_scripts/puppet/modules/sensu_config/manifests/init.pp b/deployment_scripts/puppet/modules/sensu_config/manifests/init.pp new file mode 100644 index 0000000..904ecb1 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/manifests/init.pp @@ -0,0 +1,116 @@ +class sensu_config { +$plugin_name = 'fuel-plugin-sensu' +$fuel_plugin_sensu = hiera($plugin_name, undef) + + notice('MODULAR: fuel-plugin-sensu/sensu_config.pp') + $influx_port = '8089' + $redis_vip = hiera('redis_vip') + $sensu_vhost = hiera('sensu_vhost') + $sensu_userid = hiera('sensu_userid') + $sensu_rabbit_pass = hiera('sensu_rabbit_pass') + $rabbitmq_vip = $fuel_plugin_sensu['rabbitmq_vip'] + file_line {"changing redis binding": + path => '/etc/redis/redis.conf', + line => "bind $ipaddress_br_mgmt", + match => '^bind .*', + } + file { 'sensu plugins': + path => "/opt/sensu/embedded", + source => "puppet:///modules/sensu_config/embedded", + recurse => true, + } + file { 'mutator copy': + path => '/etc/sensu/extensions/mutator-influxdb-line-protocol.rb', + source => "puppet:///modules/sensu_config/embedded/bin/mutator-influxdb-line-protocol.rb", + } + $handlers = inline_template (' + { + "handlers": { + "influxdb_udp": { + "type": "udp", + "socket": { + "host": "<%= @ipaddress_br_mgmt%>", + "port": <%= @influx_port%> + }, + "mutator": "influxdb_line_protocol" + } + } + } + ') + $config = inline_template (' + { + "redis": { + "host": "<%= @redis_vip%>" + }, + "transport": { + "name": "rabbitmq" + }, + "api": { + "host": "<%= @redis_vip%>", + "port": 4568 + } + } + ') + $rabbitmq = inline_template (' + { + "rabbitmq": { + "host": "<%= @rabbitmq_vip%>", + "port": 5673, + "vhost": "/<%= @sensu_vhost%>", + "user": "<%= @sensu_userid%>", + "password": "<%= @sensu_rabbit_pass%>" + } + } + ') + file {"rabbitmq.json": + path => '/etc/sensu/conf.d/rabbitmq.json', + content => $rabbitmq, + } + file {"config.json": + path => '/etc/sensu/conf.d/config.json', + content => $config, + } + file {"handlers.json": + path => '/etc/sensu/conf.d/handlers.json', + content => $handlers, + } + service{"sensu-server": + ensure => running, + enable => true, + subscribe => [File['sensu plugins'],File['mutator copy'],File['handlers.json'],File['config.json'],File['rabbitmq.json']], + } + service{"sensu-api": + ensure => running, + enable => true, + subscribe => [File['sensu plugins'],File['mutator copy'],File['handlers.json'],File['config.json'],File['rabbitmq.json']], + } + service{"sensu-client": + ensure => running, + enable => true, + subscribe => [File['sensu plugins'],File['mutator copy'],File['handlers.json'],File['config.json'],File['rabbitmq.json']], + } + service{"redis-server": + ensure => running, + enable => true, + subscribe => [File_line['changing redis binding'],File['sensu plugins'],File['mutator copy'],File['handlers.json'],File['config.json'],File['rabbitmq.json']], + } +} +class redis_sentinel_config { + $mgmt= $ipaddress_br_mgmt + $redis_vip = hiera('redis_vip') + + file { '/etc/init.d/redis-sentinel': + content => template('sensu_config/redis-sentinel.erb'), + mode => '0755', + notify => Service['redis-sentinel'], + } + file { '/etc/redis/sentinel.conf': + content => template('sensu_config/sentinel.conf.erb'), + notify => Service['redis-sentinel'], + } + + service {"redis-sentinel": + enable => true, + ensure => running, + } +} diff --git a/deployment_scripts/puppet/modules/sensu_config/templates/redis-sentinel.erb b/deployment_scripts/puppet/modules/sensu_config/templates/redis-sentinel.erb new file mode 100755 index 0000000..7947549 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/templates/redis-sentinel.erb @@ -0,0 +1,47 @@ +#!/bin/bash +### BEGIN INIT INFO +# Provides: redis sentinel +# Required-Start: $all +# Required-Stop: $all +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: Starts redis sentinel +# Description: Starts redis sentinel using start-stop-daemon +### END INIT INFO + +NAME=redis-sentinel +BIN=/usr/bin/redis-server +SENTINEL_PID=/tmp/redis-sentinel.pid +CMD=$1 + +start() { + echo "Starting $NAME ..." + exec 2>&1 $BIN /etc/redis/sentinel.conf --sentinel | logger -t sentinel & + echo pgrep -f "/usr/bin/redis-server <%= @mgmt %>:26379" > "${SENTINEL_PID}"; +} + +stop() { + PID=`cat $SENTINEL_PID` + echo "Stopping $NAME ($PID) ..." + kill $PID +} + +restart() { + echo "Restarting $NAME ..." + stop + start +} + +case "$CMD" in + start) + start + ;; + stop) + stop + ;; + restart) + restart + ;; + *) + echo "Usage $0 {start|stop|restart}" +esac diff --git a/deployment_scripts/puppet/modules/sensu_config/templates/sentinel.conf.erb b/deployment_scripts/puppet/modules/sensu_config/templates/sentinel.conf.erb new file mode 100644 index 0000000..98c7de0 --- /dev/null +++ b/deployment_scripts/puppet/modules/sensu_config/templates/sentinel.conf.erb @@ -0,0 +1,6 @@ +port 26379 +bind <%= @mgmt %> +sentinel monitor mymaster <%= @redis_vip %> 6379 2 +sentinel down-after-milliseconds mymaster 30000 +sentinel parallel-syncs mymaster 1 +sentinel failover-timeout mymaster 180000 diff --git a/deployment_tasks.yaml b/deployment_tasks.yaml new file mode 100644 index 0000000..68fab98 --- /dev/null +++ b/deployment_tasks.yaml @@ -0,0 +1,126 @@ +- id: fp-sensu-hiera-override + type: puppet + version: 2.0.0 + role: ['/.*/'] + requires: [post_deployment_start] + required_for: [post_deployment_end] + parameters: + puppet_manifest: "puppet/manifests/hiera_override.pp" + puppet_modules: "/etc/puppet/modules" + timeout: 120 +- id: fp-sensu-rabbit-firewall + type: puppet + version: 2.0.0 + role: ['/.*/'] + requires: [post_deployment_start, fp-sensu-hiera-override] + required_for: [post_deployment_end, fp-sensu-rabbit, fp-sensu-primary-rabbit] + parameters: + puppet_manifest: "puppet/manifests/rabbitmq_firewall.pp" + puppet_modules: /etc/puppet/modules + timeout: 300 +- id: fp-sensu-rabbit + type: puppet + version: 2.0.0 + role: ['/.*/'] + cross-depends: + - name: fp-sensu-primary-rabbit + required_for: [post_deployment_end] + requires: [post_deployment_start,fp-sensu-rabbit-firewall] + parameters: + puppet_manifest: /etc/puppet/modules/osnailyfacter/modular/rabbitmq/rabbitmq.pp + puppet_modules: /etc/puppet/modules + timeout: 1000 + test_post: + cmd: ruby /etc/puppet/modules/osnailyfacter/modular/rabbitmq/rabbitmq_post.rb +- id: fp-sensu-primary-rabbit + type: puppet + version: 2.0.0 + role: ['/.*/'] + required_for: [post_deployment_end] + requires: [post_deployment_start,fp-sensu-rabbit-firewall] + parameters: + puppet_manifest: /etc/puppet/modules/osnailyfacter/modular/rabbitmq/rabbitmq.pp + puppet_modules: /etc/puppet/modules + timeout: 1000 + test_post: + cmd: ruby /etc/puppet/modules/osnailyfacter/modular/rabbitmq/rabbitmq_post.rb +- id: fp-sensu-rabbit-vip + role: ['/.*/'] + type: puppet + version: 2.0.0 + requires: [post_deployment_start,fp-sensu-rabbit] + required_for: [post_deployment_end] + parameters: + puppet_manifest: "/etc/puppet/modules/osnailyfacter/modular/virtual_ips/virtual_ips.pp" + puppet_modules: /etc/puppet/modules + timeout: 300 +- id: fp-sensu-haproxy + role: ['/.*/'] + type: puppet + version: 2.0.0 + requires: [post_deployment_start,fp-sensu-rabbit-vip] + required_for: [post_deployment_end] + parameters: + puppet_manifest: "puppet/manifests/haproxy.pp" + puppet_modules: puppet/modules:/etc/puppet/modules + timeout: 300 +- id: fp-sensu-redis-haproxy + role: ['/.*/'] + type: puppet + version: 2.0.0 + requires: [post_deployment_start,fp-sensu-haproxy] + required_for: [post_deployment_end] + parameters: + puppet_manifest: "puppet/manifests/redis_haproxy.pp" + puppet_modules: puppet/modules:/etc/puppet/modules + timeout: 300 +- id: fp-sensu-packages + role: ['/.*/'] + type: puppet + version: 2.0.0 + requires: [post_deployment_start] + required_for: [post_deployment_end] + parameters: + puppet_manifest: "puppet/manifests/packages.pp" + puppet_modules: puppet/modules:/etc/puppet/modules + timeout: 1000 +- id: fp-sensu-rabbitmq-sensu + role: ['/.*/'] + type: puppet + version: 2.0.0 + requires: [post_deployment_start,fp-sensu-haproxy,fp-sensu-packages] + required_for: [post_deployment_end] + parameters: + puppet_manifest: "puppet/manifests/rabbitmq_sensu.pp" + puppet_modules: puppet/modules:/etc/puppet/modules + timeout: 400 +- id: fp-sensu-config-redis-sentinel + role: ['/.*/'] + type: puppet + version: 2.0.0 + requires: [post_deployment_start,fp-sensu-haproxy,fp-sensu-packages] + required_for: [post_deployment_end] + parameters: + puppet_manifest: "puppet/manifests/redis_sentinel_config.pp" + puppet_modules: puppet/modules:/etc/puppet/modules + timeout: 400 +- id: fp-sensu-config-sensu + role: ['/.*/'] + type: puppet + version: 2.0.0 + requires: [post_deployment_start,fp-sensu-haproxy,fp-sensu-packages,fp-sensu-rabbitmq-sensu] + required_for: [post_deployment_end] + parameters: + puppet_manifest: "puppet/manifests/sensu_config.pp" + puppet_modules: puppet/modules:/etc/puppet/modules + timeout: 400 +- id: fp-sensu-config-influxdb + role: ['/.*/'] + type: puppet + version: 2.0.0 + requires: [post_deployment_start,fp-sensu-haproxy,fp-sensu-packages,fp-sensu-rabbitmq-sensu,fp-sensu-config-sensu] + required_for: [post_deployment_end] + parameters: + puppet_manifest: "puppet/manifests/influxdb_config.pp" + puppet_modules: puppet/modules:/etc/puppet/modules + timeout: 600 diff --git a/environment_config.yaml b/environment_config.yaml new file mode 100644 index 0000000..05ab58b --- /dev/null +++ b/environment_config.yaml @@ -0,0 +1,14 @@ +attributes: + metadata: + label: "Sensu plugin" + weight: 12 + rabbitmq_vip: + type: "text" + weight: 13 + value: "xx.xx.xx.xx" + label: "rabbitmq mgmt vip" + redis_vip: + type: "text" + weight: 14 + value: "xx.xx.xx.xx" + label: "redis vip" diff --git a/metadata.yaml b/metadata.yaml new file mode 100644 index 0000000..a1e7a73 --- /dev/null +++ b/metadata.yaml @@ -0,0 +1,20 @@ +name: fuel-plugin-sensu +title: Sensu monitoring +version: '0.2.6' +description: Installs sensu, rabbitmq, redis on standalone (or LMA) hosts +fuel_version: ['9.0','9.1'] +licenses: ['Apache License, Version 2.0'] +authors: + - Danila Troschinsky +homepage: https://github.com/openstack/fuel-plugin-sensu +groups: ['monitoring'] +is_hotpluggable: true + +releases: + - os: ubuntu + version: mitaka-9.0 + mode: ['ha'] + deployment_scripts_path: deployment_scripts/ + repository_path: repositories/ubuntu + +package_version: '4.0.0' diff --git a/network_roles.yaml b/network_roles.yaml new file mode 100644 index 0000000..89ebad5 --- /dev/null +++ b/network_roles.yaml @@ -0,0 +1,12 @@ +- id: 'rabbtimq_management_vip' + default_mapping: 'mgmt' + properties: + subnet: true + gateway: false + vip: + - name: 'vip__rabbitmq' + namespace: 'haproxy' + alias: 'vip__rabbitmq' + node_roles: + - 'influxdb_grafana' + - 'primary-influxdb_grafana' diff --git a/repositories/centos/.gitkeep b/repositories/centos/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/repositories/ubuntu/.gitkeep b/repositories/ubuntu/.gitkeep new file mode 100644 index 0000000..e69de29