lm_rest 1.0.5 → 1.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3c01ece27d96964546705d1d5a610b33e5a5c173d63a44f9a20252846192cb23
4
- data.tar.gz: 8ab3dc099b5088d46d0d752de09c73a273a662d17b05b2a753363f6f9498ed6b
3
+ metadata.gz: 3a4f87a7e7c93fa4a82609673f1f8e2d83838a4a66204aaff72c9bf4009dcaf6
4
+ data.tar.gz: b9c12122bab2c4d6dabfa8d3edefcd60e863d082238c0e456c50dd86ef15ce27
5
5
  SHA512:
6
- metadata.gz: c6180a42bdb7fdd738651da70f41c5a4158dd5ecd177e37bc45ce67434f4ec711183743526dea241d0a99ab73c247bfd13d879cf8119c5b89af88250c9f81f35
7
- data.tar.gz: b9e563ccf97f75174a23dd88e4d58222fa40b58a1078a22ba06d2f199ae8252cd8ed4249b007ee1efbbaa3b73c3c30fe43edde48bd395d962d41e78c6751e005
6
+ metadata.gz: 8b33d7e50310ea6f7a1d679f8bf4385839c3226b41830ef513ada313423aa6b2227988f40e1403e4e05be56d5d96fd51af8008a451311faec1d498ff4b990576
7
+ data.tar.gz: f2553bdb581abd17695a47e56aa23bf5790272a3ad57475ae42dd13b92a19a786ae404e09acecf40a43b3bd14bc4ebc8aeba11d31edbb648871a51394e399426
data/.codex ADDED
File without changes
data/README.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  An Unofficial Ruby gem for the LogicMonitor REST API.
4
4
 
5
+ [![Gem Version](https://badge.fury.io/rb/lm_rest.svg)](https://badge.fury.io/rb/lm_rest)
6
+
7
+ [LogicMonitor REST API v3 Swagger Docs](https://www.logicmonitor.com/support/rest-api-v3-swagger-documentation)
8
+
5
9
  ## Installation
6
10
 
7
11
  Add this line to your application's Gemfile:
@@ -18,29 +22,57 @@ Or install it yourself as:
18
22
 
19
23
  `$ gem install lm_rest`
20
24
 
25
+ ## Remove system.categories
26
+
27
+ If you accidentally applied system.categories all over your LogicMonitor
28
+ environment, or just need to clean out some old categories, there's an included
29
+ demo script just for you.
30
+
31
+ Install this gem, then check in the `/bin` folder of this repo for the
32
+ `system_category_cleaner.rb` script. It's very simple, you'll just need to pass
33
+ it the following arguments in order, preferrably in single quotes:
34
+ * Your portal name, like `'hooli'`
35
+ * Your API access ID like `'long_api_access_id'`
36
+ * Your API access Key like `'long_api_access_key'`
37
+ * The AppliesTo matching devices you want to scrub like
38
+ `'hascategory("collector")&& system.collectorversion>=24106'`
39
+ * The category you want to remove, like `'BadCategory'`
40
+
41
+ Your devices should be all cleaned up. The script will respect rate limits and
42
+ it splits all system.categories on ',' before removing the entry you specify.
43
+
44
+ It should go without saying that this is unofficial, unsupported, and may mess
45
+ your system up even more.
46
+
47
+
21
48
  ## Supported API Resources
22
49
 
23
- Every API resource is defined in the `api.json` file and its associated defined
24
- methods are supported. You can easily add your own if you can't wait for me
25
- to update this.
50
+ Every API resource and operation is defined in `api.json`, which is generated
51
+ from the LogicMonitor REST API v3 Swagger surface. Generated operation methods
52
+ and legacy convenience aliases are both supported.
26
53
 
27
- Each method (`get_*, add_*, update_*, delete_*`) works the same
28
- for each resource. Each method name follows the pattern `method_resource`.
54
+ Each method (`get_*, add_*, update_*, delete_*`) works the same for each
55
+ resource. Each method name follows the pattern `method_resource`.
29
56
 
30
- Every method except for `delete_*` will return an `LMRest::Resource` object.
31
- It is essentially just a PORO with dynamically created property accessors
32
- (constructed from the API JSON response). This makes it easy to access
33
- attributes, edit them, and update objects. You can get a `Hash` version of the
34
- object with `#to_h`.
57
+ Every method except for `delete_*` returns `LMRest::Resource` objects. A
58
+ resource is a hash-backed wrapper around the API JSON response with dynamic
59
+ attribute-style access, so both `resource.name` and `resource['name']` work.
60
+ Use `#to_h` to get a deep-copied `Hash` version suitable for updates.
35
61
 
36
- Note: This library handles pagination for you! Use `size` and `offset` request
37
- parameters and get sane results. Default `size` is the total number of existing
38
- objects. The default `offset` is 0.
62
+ Paginated GET endpoints are handled automatically. If you omit `size`, the
63
+ client will keep requesting pages until all items have been collected. If you
64
+ set `size`, the client will fetch up to that many items even when it spans
65
+ multiple 1000-item API pages. `offset` defaults to `0`.
39
66
 
40
67
  ## Usage
41
68
 
42
69
  See the example `ds_checker.rb` script in `bin` to get a better feel for how to
43
- use the gem.
70
+ use the gem. It expects:
71
+
72
+ * LogicMonitor account name
73
+ * API access ID
74
+ * API access key
75
+ * Datasource name or filter glob
44
76
 
45
77
  ```ruby
46
78
  require 'lm_rest'
@@ -50,7 +82,7 @@ require 'lm_rest'
50
82
 
51
83
  lm = LMRest::APIClient.new('company', 'access_id', 'access_key')
52
84
 
53
- # returns array of Resource objects
85
+ # returns all datasource resources across every API page
54
86
  lm.get_datasources
55
87
 
56
88
 
@@ -59,7 +91,9 @@ lm.get_datasource(721)
59
91
 
60
92
 
61
93
  # return array of Resource objects whose names begin with "VMware"
62
- lm.get_datasources(filter: 'name:VMware*')
94
+ # NOTE: when using filter, you need quotes around the filter's "value":
95
+ # This is incorrect in the LogicMonitor API docs as of this writing (8/10/2021)
96
+ lm.get_datasources(filter: 'name:"VMware*"')
63
97
 
64
98
 
65
99
  # add a device to your account
@@ -105,6 +139,14 @@ lm.ack_collector_down(id, comment)
105
139
  lm.run_report(id)
106
140
 
107
141
 
142
+ # Handle API failures without leaking response bodies to stdout
143
+ begin
144
+ lm.get_device(999999)
145
+ rescue LMRest::APIError => e
146
+ warn "#{e.status}: #{e.body}"
147
+ end
148
+
149
+
108
150
  ```
109
151
 
110
152
  ## TODO