Class: UppityRobot::CLI::Commands::Monitors::Exec
- Inherits:
-
Dry::CLI::Command
- Object
- Dry::CLI::Command
- UppityRobot::CLI::Commands::Monitors::Exec
- Defined in:
- lib/uppityrobot/cli/commands/monitors/exec.rb
Overview
UppityRobot::CLI::Commands::Monitors::Exec pauses or starts monitors
Instance Method Summary collapse
-
#call(task:, search:, filter: "{}") ⇒ Object
rubocop:disable Metrics/AbcSize.
-
#check_task(task) ⇒ Object
rubocop:enable Metrics/AbcSize.
Instance Method Details
#call(task:, search:, filter: "{}") ⇒ Object
rubocop:disable Metrics/AbcSize
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/uppityrobot/cli/commands/monitors/exec.rb', line 22 def call(task:, search:, filter: "{}", **) status = check_task(task) filter = JSON.parse(filter) filtered = {stat: "ok", total: 0, monitors: []} params = {search: search} total = 0 UppityRobot::Client.new(:getMonitors, params).filter(filter).each do |m| data = {id: m["id"], status: status} filtered[:monitors] << UppityRobot::Client.new(:editMonitor, data).execute total += 1 end filtered[:total] = total puts filtered.to_json rescue JSON::ParserError => e puts JSON.generate({stat: "fail", error: "JSON parser #{e.message}"}) end |
#check_task(task) ⇒ Object
rubocop:enable Metrics/AbcSize
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/uppityrobot/cli/commands/monitors/exec.rb', line 42 def check_task(task) case task.downcase when "pause" UptimeRobot::Monitor::Status::Paused when "start" UptimeRobot::Monitor::Status::NotCheckedYet else abort({stat: "fail", error: "Task not recognized, must be one of: [pause, start]"}.to_json) end end |