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

- old
+ new

@@ -13,18 +13,19 @@ 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 - return super unless 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 + 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 @@ -36,10 +37,30 @@ attribute :options, Options attribute :tags, Array[String] attribute :type, String attribute :multi, Boolean + def prefix + 'monitor' + end + + def ensure_read_only! + if options + self.options.locked = true + else + self.options = Options.new(locked: true) + end + end + + def refute_read_only! + if options + self.options.locked = false + else + self.options = Options.new(locked: false) + end + end + def self.resource_url(id = nil) "https://app.datadoghq.com/api/v1/monitor".tap do |base_url| base_url << "/#{ id }" if id end end @@ -81,10 +102,10 @@ def human_edit_url "https://app.datadoghq.com/monitors##{ id }/edit" end def to_h - super.merge(options: options.to_h) + Doggy::Model.sort_by_key(super.merge(options: options.to_h)) end private def ensure_renotify_interval_valid