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 +4 -4
- data/.codex +0 -0
- data/README.md +58 -16
- data/api.json +12202 -439
- data/bin/ds_checker.rb +178 -161
- data/bin/graphgrab.rb +41 -0
- data/bin/system_category_cleaner.rb +3 -3
- data/lib/lm_rest/api_client.rb +409 -170
- data/lib/lm_rest/request_params.rb +13 -5
- data/lib/lm_rest/resource.rb +68 -17
- data/lib/lm_rest/version.rb +1 -1
- data/lm_rest.gemspec +2 -1
- metadata +21 -8
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3a4f87a7e7c93fa4a82609673f1f8e2d83838a4a66204aaff72c9bf4009dcaf6
|
|
4
|
+
data.tar.gz: b9c12122bab2c4d6dabfa8d3edefcd60e863d082238c0e456c50dd86ef15ce27
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
+
[](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
|
|
24
|
-
|
|
25
|
-
|
|
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
|
-
|
|
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_*`
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
|
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
|
-
|
|
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
|