Class: IP21

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

Overview

Aspentech IP21 Adapter for executing queries using SQLPlus

This library uses Windows Authentication for connecting to SQLPlus

Examples:

IP21.new(
  auth: {
    account: 'john.doe',
    domain: 'contoso.com',
    password: 'set_your_own_password'
  },
  sqlplus_address: '127.0.0.1',
  ip21_address: '127.0.0.1',
).query('SELECT IP_PLANT_AREA, Name, IP_DESCRIPTION FROM IP_AnalogDef')

Instance Method Summary collapse

Constructor Details

#initialize(auth: { account: 'john.doe', domain: 'contoso.com', password: 'set_your_own_password' }, sqlplus_address: '127.0.0.1', ip21_address: '127.0.0.1', debug: false) ⇒ IP21

Initializes the connection

Parameters:

  • auth (Hash) (defaults to: { account: 'john.doe', domain: 'contoso.com', password: 'set_your_own_password' })

    The Windows account, domain and password for connecting to SQLPLus

  • sqlplus_address (String) (defaults to: '127.0.0.1')

    The hostname or IP address for connecting to SQLPlus

  • ip21_address (String) (defaults to: '127.0.0.1')

    The hostname or IP address for connecting to the IP21 Database

  • debug (Boolean) (defaults to: false)

    Set this parameter to true for enabling debug information



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/ip21.rb', line 30

def initialize(
  auth: {
    account: 'john.doe',
    domain: 'contoso.com',
    password: 'set_your_own_password'
  },
  sqlplus_address: '127.0.0.1',
  ip21_address: '127.0.0.1',
  debug: false
)
  @account = auth[:account]
  @domain = auth[:domain]
  @password = auth[:password]
  @sqlplus_address = sqlplus_address
  @ip21_address = ip21_address
  @debug = debug
end

Instance Method Details

#history(tag, start_time, end_time, opts = { limit: 1000, outsiders: 0, history_format: 0, retrieval_type: 0 }) ⇒ Hash

Fetch data from IP21 History

Parameters:

  • tag (String)

    The tag to be queried

  • start_time (Integer)

    The unix timestamp in miliseconds for the start of the query period

  • end_time (Integer)

    The unix timestamp in miliseconds for the end of the query period

  • opts (Hash) (defaults to: { limit: 1000, outsiders: 0, history_format: 0, retrieval_type: 0 })

    Optional extra values

Options Hash (opts):

  • limit (Integer)

    The maximum number of items to be retrieved

  • outsiders (Integer)

    The maximum number of items to be retrieved

  • history_format (Integer)

    The value format during retrieval. Possible values are:

    • 0: Raw

    • 1: Record as String

  • retrieval_type (Integer)

    The retrieval type of the query. Possible values are:

    • 0 - Actual

    • 1 - Interpolated

    • 2 - Best Fit

    • 3 - Manual

    • 10 - Not Good

    • 11 - Good

    • 12 - Average

    • 13 - Maximum

    • 14 - Minimum

    • 15 - Range

    • 16 - Sum

    • 17 - Standard Deviation

    • 18 - Variance

    • 19 - Good Only

    • 20 - Suspect Only

    • 21 - First

    • 22 - Last

  • outsiders (Integer)

    Whether or not to include the closest values outside the date/time range

    • 0 - False

    • 1 - True

Returns:

  • (Hash)

    Response from IP21



99
100
101
102
103
104
105
106
107
108
# File 'lib/ip21.rb', line 99

def history(tag, start_time, end_time, opts = {
  limit: 1000, outsiders: 0, history_format: 0, retrieval_type: 0
})
  parse_rest(
    rest_request(
      'History',
      history_query_body(tag, start_time, end_time, opts)
    )
  )
end

#kpi(tag) ⇒ Object



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

def kpi(tag)
  parse_rest(rest_request('KPI', kpi_query_body(tag)))
end

#query(sql, limit = 100) ⇒ Hash

Executes a direct query against the database

Parameters:

  • sql (String)

    The query to be executed

  • limit (Integer) (defaults to: 100)

    The maximum number of rows that the query will output

Returns:

  • (Hash)

    Response from the query



54
55
56
57
58
# File 'lib/ip21.rb', line 54

def query(sql, limit = 100)
  parse_rest(
    rest_request('SQL', sql_query_body(sql, limit))
  )
end