lib/doggy/models/monitor.rb in doggy-2.0.30 vs lib/doggy/models/monitor.rb in doggy-2.0.31

- old
+ new

@@ -3,31 +3,20 @@ module Doggy module Models class Monitor < Doggy::Model class Options include Virtus.model - attr_accessor :monitor attribute :silenced, Hash attribute :thresholds, Hash attribute :notify_audit, Boolean attribute :notify_no_data, Boolean attribute :no_data_timeframe, Integer attribute :timeout_h, Integer attribute :escalation_message, String attribute :renotify_interval, Integer attribute :locked, Boolean - - def to_h - if monitor.id && monitor.loading_source == :local - # Pull remote silenced state. If we don't send this value, Datadog - # assumes that we want to unmute the monitor. - remote_monitor = Monitor.find(monitor.id) - self.silenced = remote_monitor.options.silenced if remote_monitor.options - end - super - end end attribute :id, Integer attribute :org_id, Integer attribute :name, String @@ -63,16 +52,10 @@ "https://app.datadoghq.com/api/v1/monitor".tap do |base_url| base_url << "/#{ id }" if id end end - def initialize(attributes = nil) - super(attributes) - - options.monitor = self if options - end - def managed? !(name =~ Doggy::DOG_SKIP_REGEX) end def ensure_managed_emoji! @@ -83,17 +66,18 @@ def validate ensure_renotify_interval_valid end - def mute - return unless id - request(:post, "#{ resource_url(id) }/mute") - end - - def unmute - return unless id - request(:post, "#{ resource_url(id) }/unmute") + def toggle_mute!(action) + return unless ['mute', 'unmute'].include?(action) && id + attributes = request(:post, "#{ resource_url(id) }/#{action}") + if message = attributes['errors'] + Doggy.ui.error(message) + else + self.attributes = attributes + save_local + end end def human_url "https://app.datadoghq.com/monitors##{ id }" end