Class: Intranet::System::Responder

Inherits:
AbstractResponder
  • Object
show all
Includes:
Core::HamlWrapper
Defined in:
lib/intranet/system/responder.rb

Overview

The responder for the System monitor module of the Intranet.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(provider, in_menu = true) ⇒ Responder

Initializes a new System responder instance.

Parameters:

  • provider (Object)

    The system statistics provider, responding to #stats.

  • in_menu (Boolean) (defaults to: true)

    Whether the module instance should be displayed in the main navigation menu or not.



37
38
39
40
# File 'lib/intranet/system/responder.rb', line 37

def initialize(provider, in_menu = true)
  @provider = provider
  @in_menu = in_menu
end

Class Method Details

.module_homepageString

The homepage of the module.

Returns:

  • (String)

    The homepage URL of the module.



29
30
31
# File 'lib/intranet/system/responder.rb', line 29

def self.module_homepage
  HOMEPAGE_URL
end

.module_nameString

Returns the name of the module.

Returns:

  • (String)

    The name of the module



17
18
19
# File 'lib/intranet/system/responder.rb', line 17

def self.module_name
  NAME
end

.module_versionString

The version of the module, according to semantic versionning.

Returns:

  • (String)

    The version of the module



23
24
25
# File 'lib/intranet/system/responder.rb', line 23

def self.module_version
  VERSION
end

Instance Method Details

#css_dependenciesArray

Provides the list of Cascade Style Sheets (CSS) dependencies for this module.

Returns:

  • (Array)

    The list of CSS dependencies.



98
99
100
# File 'lib/intranet/system/responder.rb', line 98

def css_dependencies
  super + ['design/style.css']
end

#generate_page(path, query) ⇒ Array

Generates the HTML content associated to the given path and query.

REST API Description:

Read-only access to system statistics under /api using GET method. Response is in JSON format with the following structure:

{
  "hostname": "trantor",
  "loadavg": [0.42,0.48,0.56],
  "cpu": {
    "model": "Intel(R) Core(TM) i5-6500 CPU @ 3.20GHz",
    "nb_cores": 4
  },
  "ram": { "total": 8243249152, "used": 3149385728 },
  "swaps": {
    "/dev/sdb1": { "total": 19999485952, "used": 0 }
  },
  "partitions": {
    "/boot/efi": { "total": 509640704, "used": 135168 },
    "/": { "total": 58306199552, "used": 11482054656 }
  }
}

Parameters:

  • path (String)

    The requested URI, relative to that module root URI.

  • query (Hash)

    The URI variable/value pairs, if any.

Returns:

  • (Array)

    The HTTP return code, the MIME type and the answer body.



78
79
80
81
82
83
84
85
86
87
88
# File 'lib/intranet/system/responder.rb', line 78

def generate_page(path, query)
  case path
  when %r{^/index\.html$}
    return 206, 'text/html', generate_home_html
  when %r{^/api$}
    return 200, 'application/json', @provider.stats.to_json
  when %r{^/i18n\.js$}
    return 200, 'text/javascript', generate_i18n_js
  end
  super(path, query)
end

#in_menu?Boolean

Specifies if the responder instance should be displayed in the main navigation menu or not.

Returns:

  • (Boolean)

    True if the responder instance should be added to the main navigation menu, False otherwise.



45
46
47
# File 'lib/intranet/system/responder.rb', line 45

def in_menu?
  @in_menu
end

#js_dependenciesArray

Provides the list of Javascript files (JS) dependencies for this module.

Returns:

  • (Array)

    The list of JS dependencies.



104
105
106
# File 'lib/intranet/system/responder.rb', line 104

def js_dependencies
  super + ['i18n.js', 'design/jsystem.js']
end

#resources_dirString

Specifies the absolute path to the resources directory for that module.

Returns:

  • (String)

    The absolute path to the resources directory for the module.



51
52
53
# File 'lib/intranet/system/responder.rb', line 51

def resources_dir
  File.absolute_path(File.join('..', 'resources'), __dir__)
end

#titleString

The title of the System monitor module, as displayed on the web page.

Returns:

  • (String)

    The title of the System monitor web page.



92
93
94
# File 'lib/intranet/system/responder.rb', line 92

def title
  I18n.t('system.monitor')
end