Class: Seer::Hosts

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

Overview

Hosts API controller

Instance Method Summary collapse

Constructor Details

#initialize(token: '', version: '2.0', host: '') ⇒ Hosts

Initialize a Hosts object

Parameters:

  • token (string) (defaults to: '')

    API token

  • version (string) (defaults to: '2.0')

    API version you want use (defaut 1)

  • host (string) (defaults to: '')

    API host



8
9
10
11
12
13
14
15
# File 'lib/seer/hosts.rb', line 8

def initialize(token: '', version: '2.0', host: '')
  @host = host + '/hosts'
  @header = {
      content_type: 'application/json',
      x_seer_token: token,
      x_seer_version: version
  }
end

Instance Method Details

#aggs(query, fields) ⇒ Hash

Aggregations by query and field

Parameters:

  • query (String)

    Custom query

  • fields (String)

    The field you want to aggs

Returns:

  • (Hash)

    Result



83
84
85
86
87
88
89
90
91
# File 'lib/seer/hosts.rb', line 83

def aggs(query, fields)
  body = {
    query: query,
    fields: fields
  }
  url = @host + '/aggs'

  Seer.request(url, body, @header)
end

#ip(ip, minify: false) ⇒ Hash

Get host by ip

Parameters:

  • ip (String)

    IP Address

  • minify (Boolean) (defaults to: false)

    Only return IP address (default false)

Returns:

  • (Hash)

    Result



21
22
23
24
25
26
27
28
29
# File 'lib/seer/hosts.rb', line 21

def ip(ip, minify: false)
  body = {
    ip: ip,
    minify: minify
  }
  url = @host + '/ip'

  Seer.request(url, body, @header)
end

#port(port, page: 1, minify: false) ⇒ Hash

Get hosts by port

Parameters:

  • port (Fixnum)

    Port you want to search

  • page (Fixnum) (defaults to: 1)

    The page of results

  • minify (Boolean) (defaults to: false)

    Only return IP address (default false)

Returns:

  • (Hash)

    Result



36
37
38
39
40
41
42
43
44
45
# File 'lib/seer/hosts.rb', line 36

def port(port, page: 1, minify: false)
  body = {
    port: port,
    page: page,
    minify: minify
  }
  url = @host + '/port'

  Seer.request(url, body, @header)
end

#search(query, page: 1, minify: false) ⇒ Hash

Get hosts by custom search

Parameters:

  • query (String)

    Custom query

  • page (Fixnum) (defaults to: 1)

    The page of results

  • minify (Boolean) (defaults to: false)

    Only return IP address (default false)

Returns:

  • (Hash)

    Result



68
69
70
71
72
73
74
75
76
77
# File 'lib/seer/hosts.rb', line 68

def search(query, page: 1, minify: false)
  body = {
    query: query,
    page: page,
    minify: minify
  }
  url = @host + '/search'

  Seer.request(url, body, @header)
end

#service(service, page: 1, minify: false) ⇒ Hash

Get hosts by service

Parameters:

  • service (String)

    Service you want to search

  • page (Fixnum) (defaults to: 1)

    The page of results

  • minify (Boolean) (defaults to: false)

    Only return IP address (default false)

Returns:

  • (Hash)

    Result



52
53
54
55
56
57
58
59
60
61
# File 'lib/seer/hosts.rb', line 52

def service(service, page: 1, minify: false)
  body = {
    service: service,
    page: page,
    minify: minify
  }
  url = @host + '/service'

  Seer.request(url, body, @header)
end