Class: Sappy::Monitor

Inherits:
Object
  • Object
show all
Defined in:
lib/sappy/monitor.rb

Constant Summary collapse

SERVICES =

Name (required)

Service name.

Service (required)

Service type. Available values are: http, smtp, ftp, pop3, https, ping, dns
%w(http smtp ftp pop3 https ping dns)
LOCATIONS =

Location (required)

Check location. Available values are: sf, ny, ch, ln (i.e. San Francisco, New York, Chicago, London).
{'sf' => 'San Francisco', 'ny' => 'New York', 'ch' => 'Chicago', 'ln' => 'London'}.sort
CHECK_PERIODS =

HostName (required)

Monitored Host name, IP or Page URL.

CheckPeriod (required)

Monitoring check period. Available values are: 2, 5, 15, 30, 60
[2, 5, 15, 30, 60]
SEND_ALERT_AFTER =

PortNumber (optional)

Custom port number. Default service port using by default.

Login (optional)

HTTP Authentication login. Used for 'http' and https services only.

Password (optional)

HTTP Authentication password. Used for 'http' and https services only.

Content (optional)

Monitored page content. Used for 'http' and 'https' services only.

Domain (optional)

Lookup domain. Used for 'dns' services only.

IP (optional)

Lookup domain. Used for 'dns' services only. Required if 'Domain' is not empty.

SendSms (optional)

0 or 1. Send SMS alerts on failures. Default value is '0'.

SendUrlAlert (optional)

0 or 1. Send Url (JSON) alerts on failures to Url specified on My Profile section. Default value is '0'.

SendJabberAlert (optional)

0 or 1. Send XMPP/Jabber alerts on failures to Jabber ID specified on My Profile section. Default value is '0'.

AltEmailAlerts (optional)

Alternative Email alerts addresses separated with comma.

DontSendUpAlert (optional)

0 or 1. Set to 1 if you do not what to receive Up alerts for a monitor. Default value is '0'.

SendAllDownAlerts (optional)

0 or 1. Set to 1 if you what to receive Down alert on each failure check. Default value is '0'.

Enabled (optional)

0 or 1. Monitor is enabled on not. Default value is '1'.

SendAlertAfter (optional)

Send alerts after specified number of failures. Available values are: 1, 2, 3, 4, 5. Default value is 1.
[1, 2, 3, 4, 5]
TIMEOUTS =

DownSubject (optional)

Email subject value for Down alerts. Default subject will be used if empty.

UpSubject (optional)

Email subject value for Up alerts. Default subject will be used if empty.

EnablePublicStatistics (optional)

0 or 1. Allow/Deny visitor to see public statistics report. Default value is '1' (allow).

AddToStatusPage (optional)

0 or 1. Add/remove monitor to/from your public summary status report. Default value is '1' (add).

Timeout (optional)

Monitor socket connection timeout value in seconds. Available values are: 15, 20, 25, 30, 35. Default value is 25.
[15, 20, 25, 30, 35]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(account, attrs) ⇒ Monitor

Returns a new instance of Monitor.



64
65
66
67
# File 'lib/sappy/monitor.rb', line 64

def initialize(, attrs)
  @account = 
  self.attributes = attrs
end

Instance Attribute Details

#accountObject (readonly)

Returns the value of attribute account.



62
63
64
# File 'lib/sappy/monitor.rb', line 62

def 
  @account
end

#altemailalertsObject

Returns the value of attribute altemailalerts.



57
58
59
# File 'lib/sappy/monitor.rb', line 57

def altemailalerts
  @altemailalerts
end

#contentObject

Returns the value of attribute content.



57
58
59
# File 'lib/sappy/monitor.rb', line 57

def content
  @content
end

#current_statusObject

Returns the value of attribute current_status.



57
58
59
# File 'lib/sappy/monitor.rb', line 57

def current_status
  @current_status
end

#domainObject

Returns the value of attribute domain.



57
58
59
# File 'lib/sappy/monitor.rb', line 57

def domain
  @domain
end

#downsubjectObject

Returns the value of attribute downsubject.



57
58
59
# File 'lib/sappy/monitor.rb', line 57

def downsubject
  @downsubject
end

#hostObject

Returns the value of attribute host.



57
58
59
# File 'lib/sappy/monitor.rb', line 57

def host
  @host
end

#idObject

Returns the value of attribute id.



57
58
59
# File 'lib/sappy/monitor.rb', line 57

def id
  @id
end

#ipObject

Returns the value of attribute ip.



57
58
59
# File 'lib/sappy/monitor.rb', line 57

def ip
  @ip
end

#locationObject

Returns the value of attribute location.



57
58
59
# File 'lib/sappy/monitor.rb', line 57

def location
  @location
end

#loginObject

Returns the value of attribute login.



57
58
59
# File 'lib/sappy/monitor.rb', line 57

def 
  @login
end

#nameObject

Returns the value of attribute name.



57
58
59
# File 'lib/sappy/monitor.rb', line 57

def name
  @name
end

#passwordObject

Returns the value of attribute password.



57
58
59
# File 'lib/sappy/monitor.rb', line 57

def password
  @password
end

#periodObject

Returns the value of attribute period.



57
58
59
# File 'lib/sappy/monitor.rb', line 57

def period
  @period
end

#portObject

Returns the value of attribute port.



57
58
59
# File 'lib/sappy/monitor.rb', line 57

def port
  @port
end

#serviceObject

Returns the value of attribute service.



57
58
59
# File 'lib/sappy/monitor.rb', line 57

def service
  @service
end

#timeoutObject

Returns the value of attribute timeout.



57
58
59
# File 'lib/sappy/monitor.rb', line 57

def timeout
  @timeout
end

#upsubjectObject

Returns the value of attribute upsubject.



57
58
59
# File 'lib/sappy/monitor.rb', line 57

def upsubject
  @upsubject
end

Class Method Details

.create(account, attrs) ⇒ Object



75
76
77
78
79
# File 'lib/sappy/monitor.rb', line 75

def self.create(, attrs)
  monitor = new(, attrs)
  monitor.save
  monitor
end

.parse(account, attrs) ⇒ Object



69
70
71
72
73
# File 'lib/sappy/monitor.rb', line 69

def self.parse(, attrs)
  a = new(, attrs)
  a.current_status = attrs["current_status"]
  a
end

Instance Method Details

#annual_statistics(year = "") ⇒ Object



151
152
153
# File 'lib/sappy/monitor.rb', line 151

def annual_statistics(year = "")
  Statistics::Annual.new(@account.request('annualstatistics', "MonitorId" => id, "Year" => year).statistics)
end

#attributesObject



81
82
83
84
85
86
87
88
89
# File 'lib/sappy/monitor.rb', line 81

def attributes
  { "Name" => name, "Service" => service, "Location" => location, "HostName" => host,
    "CheckPeriod" => period, "PortNumber" => port, "Login" => , "Password" => password,
    "Content" => content, "Domain" => domain, "IP" => ip, "SendSms" => sendsms, "SendUrlAlert" => sendurlalert,
    "SendJabberAlert" => sendjabberalert, "AltEmailAlerts" => altemailalerts, "DontSendUpAlert" => dontsendupalert,
    "SendAllDownAlerts" => sendalldownalerts, "Enabled" => active, "SendAlertAfter" => sendalertafter,
    "DownSubject" => downsubject, "UpSubject" => upsubject, "EnablePublicStatistics" => enablepublicstatistics,
    "AddToStatusPage" => addtostatuspage, "Timeout" => timeout }
end

#attributes=(attrs) ⇒ Object



91
92
93
94
95
# File 'lib/sappy/monitor.rb', line 91

def attributes=(attrs)
  attrs.each do |attribute,value|
    send("#{attribute.to_s}=", value) if respond_to? "#{attribute.to_s}="
  end
end

#createObject



131
132
133
# File 'lib/sappy/monitor.rb', line 131

def create
  self.id = @account.request("addmonitor", attributes).id
end

#daily_statistics(year, month, day) ⇒ Object



143
144
145
# File 'lib/sappy/monitor.rb', line 143

def daily_statistics(year, month, day)
  Statistics::Daily.new(@account.request('dailystatistics', "MonitorId" => id, "Year" => year, "Month" => month, "Day" => day).statistics)
end

#destroyObject



139
140
141
# File 'lib/sappy/monitor.rb', line 139

def destroy
  @account.request('removemonitor', "MonitorId" => id)
end

#disable!Object



105
106
107
108
# File 'lib/sappy/monitor.rb', line 105

def disable!
  @account.request('disablemonitor', "MonitorId" => id)
  @active = 0
end

#disabled?Boolean

Returns:

  • (Boolean)


110
111
112
# File 'lib/sappy/monitor.rb', line 110

def disabled?
  @active != 1
end

#enable!Object



114
115
116
117
# File 'lib/sappy/monitor.rb', line 114

def enable!
  @account.request('enablemonitor', "MonitorId" => id)
  @active = 1
end

#enabled?Boolean

Returns:

  • (Boolean)


119
120
121
# File 'lib/sappy/monitor.rb', line 119

def enabled?
  @active == 1
end

#monthly_statistics(year, month) ⇒ Object



147
148
149
# File 'lib/sappy/monitor.rb', line 147

def monthly_statistics(year, month)
  Statistics::Monthly.new(@account.request('monthlystatistics', "MonitorId" => id, "Year" => year, "Month" => month).statistics)
end

#new_record?Boolean

Returns:

  • (Boolean)


123
124
125
# File 'lib/sappy/monitor.rb', line 123

def new_record?
  id.nil?
end

#saveObject



127
128
129
# File 'lib/sappy/monitor.rb', line 127

def save
  new_record? ? create : update
end

#updateObject



135
136
137
# File 'lib/sappy/monitor.rb', line 135

def update
  @account.request("editmonitor", attributes.merge({ "MonitorId" => id }))
end

#urlObject



101
102
103
# File 'lib/sappy/monitor.rb', line 101

def url
  "#{service}://#{host}"
end