lm-cloud-inventory 2.0.0__tar.gz

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.
Files changed (36) hide show
  1. lm_cloud_inventory-2.0.0/.github/workflows/publish.yml +73 -0
  2. lm_cloud_inventory-2.0.0/.gitignore +36 -0
  3. lm_cloud_inventory-2.0.0/LICENSE +22 -0
  4. lm_cloud_inventory-2.0.0/MANIFEST.in +5 -0
  5. lm_cloud_inventory-2.0.0/PKG-INFO +449 -0
  6. lm_cloud_inventory-2.0.0/README.md +432 -0
  7. lm_cloud_inventory-2.0.0/docs/ARCHITECTURE.md +269 -0
  8. lm_cloud_inventory-2.0.0/docs/PERMISSIONS.md +513 -0
  9. lm_cloud_inventory-2.0.0/legacy-v1/README.md +204 -0
  10. lm_cloud_inventory-2.0.0/legacy-v1/get_aws_resource_counts.ps1 +2198 -0
  11. lm_cloud_inventory-2.0.0/legacy-v1/get_azure_resource_counts.ps1 +301 -0
  12. lm_cloud_inventory-2.0.0/lm_cloud_inventory.egg-info/PKG-INFO +449 -0
  13. lm_cloud_inventory-2.0.0/lm_cloud_inventory.egg-info/SOURCES.txt +34 -0
  14. lm_cloud_inventory-2.0.0/lm_cloud_inventory.egg-info/dependency_links.txt +1 -0
  15. lm_cloud_inventory-2.0.0/lm_cloud_inventory.egg-info/entry_points.txt +3 -0
  16. lm_cloud_inventory-2.0.0/lm_cloud_inventory.egg-info/top_level.txt +1 -0
  17. lm_cloud_inventory-2.0.0/pyproject.toml +60 -0
  18. lm_cloud_inventory-2.0.0/requirements.txt +24 -0
  19. lm_cloud_inventory-2.0.0/setup.cfg +4 -0
  20. lm_cloud_inventory-2.0.0/setup.py +41 -0
  21. lm_cloud_inventory-2.0.0/src/__init__.py +8 -0
  22. lm_cloud_inventory-2.0.0/src/_version.py +34 -0
  23. lm_cloud_inventory-2.0.0/src/calculator/__init__.py +5 -0
  24. lm_cloud_inventory-2.0.0/src/calculator/license_calculator.py +417 -0
  25. lm_cloud_inventory-2.0.0/src/cli.py +424 -0
  26. lm_cloud_inventory-2.0.0/src/collectors/__init__.py +19 -0
  27. lm_cloud_inventory-2.0.0/src/collectors/aws_collector.py +420 -0
  28. lm_cloud_inventory-2.0.0/src/collectors/azure_collector.py +328 -0
  29. lm_cloud_inventory-2.0.0/src/collectors/base.py +158 -0
  30. lm_cloud_inventory-2.0.0/src/collectors/gcp_collector.py +275 -0
  31. lm_cloud_inventory-2.0.0/src/collectors/oci_collector.py +322 -0
  32. lm_cloud_inventory-2.0.0/src/config/__init__.py +1 -0
  33. lm_cloud_inventory-2.0.0/src/config/license_rules.json +80 -0
  34. lm_cloud_inventory-2.0.0/src/config/resource_mappings.json +191 -0
  35. lm_cloud_inventory-2.0.0/src/utils/__init__.py +5 -0
  36. lm_cloud_inventory-2.0.0/src/utils/config_loader.py +153 -0
@@ -0,0 +1,73 @@
1
+ name: Publish to PyPI
2
+
3
+ on:
4
+ release:
5
+ types: [published]
6
+
7
+ jobs:
8
+ build:
9
+ name: Build distribution
10
+ runs-on: ubuntu-latest
11
+ steps:
12
+ - uses: actions/checkout@v4
13
+
14
+ - name: Set up Python
15
+ uses: actions/setup-python@v5
16
+ with:
17
+ python-version: "3.11"
18
+
19
+ - name: Install build dependencies
20
+ run: python -m pip install --upgrade pip build
21
+
22
+ - name: Build package
23
+ run: python -m build
24
+
25
+ - name: Upload distribution artifacts
26
+ uses: actions/upload-artifact@v4
27
+ with:
28
+ name: python-package-distributions
29
+ path: dist/
30
+
31
+ publish-testpypi:
32
+ name: Publish to TestPyPI
33
+ needs: build
34
+ if: github.event.release.prerelease
35
+ runs-on: ubuntu-latest
36
+ environment:
37
+ name: testpypi
38
+ url: https://test.pypi.org/p/lm-cloud-inventory
39
+ permissions:
40
+ id-token: write
41
+
42
+ steps:
43
+ - name: Download distribution artifacts
44
+ uses: actions/download-artifact@v4
45
+ with:
46
+ name: python-package-distributions
47
+ path: dist/
48
+
49
+ - name: Publish to TestPyPI
50
+ uses: pypa/gh-action-pypi-publish@release/v1
51
+ with:
52
+ repository-url: https://test.pypi.org/legacy/
53
+
54
+ publish-pypi:
55
+ name: Publish to PyPI
56
+ needs: build
57
+ if: ${{ !github.event.release.prerelease }}
58
+ runs-on: ubuntu-latest
59
+ environment:
60
+ name: pypi
61
+ url: https://pypi.org/p/lm-cloud-inventory
62
+ permissions:
63
+ id-token: write
64
+
65
+ steps:
66
+ - name: Download distribution artifacts
67
+ uses: actions/download-artifact@v4
68
+ with:
69
+ name: python-package-distributions
70
+ path: dist/
71
+
72
+ - name: Publish to PyPI
73
+ uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,36 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[codz]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+ *.manifest
29
+ *.spec
30
+
31
+ .DS_Store
32
+ /*.csv
33
+ /*.json
34
+
35
+ # Generated version file (created by setuptools-scm)
36
+ src/_version.py
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 LogicMonitor, Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
@@ -0,0 +1,5 @@
1
+ include LICENSE
2
+ include README.md
3
+ include requirements.txt
4
+ recursive-include src *.py *.json
5
+
@@ -0,0 +1,449 @@
1
+ Metadata-Version: 2.4
2
+ Name: lm-cloud-inventory
3
+ Version: 2.0.0
4
+ Summary: Cloud resource inventory collection for LogicMonitor licensing
5
+ Home-page: https://github.com/logicmonitor/lm-cloud-resource-inventory
6
+ Author: LogicMonitor
7
+ Author-email: support@logicmonitor.com
8
+ License: MIT
9
+ Requires-Python: >=3.9
10
+ Description-Content-Type: text/markdown
11
+ License-File: LICENSE
12
+ Dynamic: author
13
+ Dynamic: author-email
14
+ Dynamic: home-page
15
+ Dynamic: license-file
16
+ Dynamic: requires-python
17
+
18
+ # LM Cloud Resource Inventory
19
+
20
+ A unified solution for collecting cloud resource counts across AWS, Azure, GCP, and OCI for LogicMonitor licensing purposes.
21
+
22
+ ## Overview
23
+
24
+ This tool collects resource inventory from cloud providers and calculates LogicMonitor license requirements by categorizing resources into:
25
+
26
+ - **IaaS** - Virtual machines and compute instances
27
+ - **PaaS** - Managed services, containers, serverless functions
28
+ - **Non-Compute** - Storage, networking, and other infrastructure resources
29
+
30
+ ## Quick Start
31
+
32
+ ### Installation
33
+
34
+ ```bash
35
+ pip install lm-cloud-inventory
36
+ ```
37
+
38
+ Or install from source:
39
+
40
+ ```bash
41
+ git clone https://github.com/logicmonitor/lm-cloud-resource-inventory.git
42
+ cd lm-cloud-resource-inventory
43
+ pip install .
44
+ ```
45
+
46
+ ### Basic Usage
47
+
48
+ ```bash
49
+ # Run inventory and calculate licenses
50
+ lmci run -p aws -o aws_summary.csv
51
+ lmci run -p azure -o azure_summary.csv
52
+ lmci run -p gcp -o gcp_summary.csv
53
+ lmci run -p oci -o oci_summary.csv
54
+ ```
55
+
56
+ ---
57
+
58
+ ## CLI Reference
59
+
60
+ ### Global Options
61
+
62
+ | Option | Description |
63
+ |--------|-------------|
64
+ | `-v, --verbose` | Enable verbose logging (shows debug info and full tracebacks) |
65
+ | `--version` | Show version and exit |
66
+ | `--help` | Show help message |
67
+
68
+ ### `run` Command (Recommended)
69
+
70
+ Collect inventory and calculate licenses in one step. This is the primary command for most users.
71
+
72
+ ```bash
73
+ lmci run -p <provider> [options]
74
+ ```
75
+
76
+ | Option | Provider | Description |
77
+ |--------|----------|-------------|
78
+ | `-p, --provider` | All | Cloud provider: `aws`, `azure`, `gcp`, `oci` **(required)** |
79
+ | `-o, --output` | All | Output CSV file (default: `license_summary.csv`) |
80
+ | `-d, --detailed` | All | Generate detailed CSV with per-region breakdown |
81
+ | `--show-unmapped` | All | List resource types not mapped to license categories |
82
+ | `--profile` | AWS | AWS CLI profile name |
83
+ | `-s, --subscription` | Azure | Subscription ID (can be repeated for multiple) |
84
+ | `--project` | GCP | GCP project ID |
85
+ | `--compartment` | OCI | OCI compartment OCID |
86
+
87
+ **Examples:**
88
+
89
+ ```bash
90
+ # AWS - basic
91
+ lmci run -p aws
92
+
93
+ # AWS - with named profile
94
+ lmci run -p aws --profile production -o aws_prod.csv
95
+
96
+ # Azure - all subscriptions
97
+ lmci run -p azure
98
+
99
+ # Azure - specific subscriptions
100
+ lmci run -p azure -s "sub-id-1" -s "sub-id-2"
101
+
102
+ # GCP - auto-detect project from credentials
103
+ lmci run -p gcp
104
+
105
+ # GCP - explicit project
106
+ lmci run -p gcp --project my-project-id
107
+
108
+ # OCI - entire tenancy
109
+ lmci run -p oci
110
+
111
+ # OCI - specific compartment
112
+ lmci run -p oci --compartment ocid1.compartment.oc1..xxx
113
+
114
+ # Any provider - with detailed output
115
+ lmci run -p aws -d -o detailed_report.csv
116
+ ```
117
+
118
+ ### `collect` Command
119
+
120
+ Collect inventory only (saves JSON for later calculation).
121
+
122
+ ```bash
123
+ lmci collect -p <provider> [options]
124
+ ```
125
+
126
+ | Option | Provider | Description |
127
+ |--------|----------|-------------|
128
+ | `-p, --provider` | All | Cloud provider **(required)** |
129
+ | `-o, --output` | All | Output JSON file (default: `inventory.json`) |
130
+ | `--profile` | AWS | AWS CLI profile name |
131
+ | `--region` | AWS | AWS region for API calls (default: `us-east-1`) |
132
+ | `--organization` | AWS | IAM role name for cross-account access |
133
+ | `--organization` | GCP | GCP organization ID for org-wide inventory |
134
+ | `-s, --subscription` | Azure | Subscription ID (repeatable) |
135
+ | `--project` | GCP | GCP project ID |
136
+ | `--compartment` | OCI | OCI compartment OCID |
137
+
138
+ ### `calculate` Command
139
+
140
+ Calculate licenses from an existing inventory JSON file.
141
+
142
+ ```bash
143
+ lmci calculate -i <inventory.json> [options]
144
+ ```
145
+
146
+ | Option | Description |
147
+ |--------|-------------|
148
+ | `-i, --input` | Input inventory JSON file **(required)** |
149
+ | `-o, --output` | Output CSV file (default: `license_summary.csv`) |
150
+ | `-d, --detailed` | Generate detailed CSV |
151
+ | `--show-unmapped` | List unmapped resource types |
152
+
153
+ ### `permissions` Command
154
+
155
+ Show required permissions for each cloud provider.
156
+
157
+ ```bash
158
+ lmci permissions -p aws
159
+ lmci permissions -p azure
160
+ lmci permissions -p gcp
161
+ lmci permissions -p oci
162
+ ```
163
+
164
+ ---
165
+
166
+ ## Supported Cloud Providers
167
+
168
+ | Provider | API Used | Performance |
169
+ |----------|----------|-------------|
170
+ | **AWS** | AWS Resource Explorer | ~2-5 minutes |
171
+ | **Azure** | Azure Resource Graph | ~1-2 minutes |
172
+ | **GCP** | Cloud Asset Inventory | ~1-2 minutes |
173
+ | **OCI** | OCI Search Service | ~1 minute |
174
+
175
+ For a complete list of supported resources, see [LogicMonitor Cloud Services Documentation](https://www.logicmonitor.com/support/cloud-services-and-resource-units).
176
+
177
+ ### AWS Resource Explorer Limitations
178
+
179
+ The following AWS services are **not indexed** by AWS Resource Explorer and will not be collected:
180
+
181
+ | Service | Resource Type |
182
+ |---------|---------------|
183
+ | CloudSearch | Domain |
184
+ | MediaConnect | Flow |
185
+ | MediaConvert | Queue |
186
+ | OpsWorks | Stack |
187
+ | Q Business | Application |
188
+ | QuickSight | Dashboard (dataset/datasource are supported) |
189
+ | Simple Workflow (SWF) | Domain |
190
+ | Application Migration Service | Source Server |
191
+ | ElasticTranscoder | Pipeline |
192
+
193
+ If you have significant usage of these services, contact your LogicMonitor representative for manual inventory assistance.
194
+
195
+ ---
196
+
197
+ ## Requirements
198
+
199
+ - **Python 3.9+**
200
+ - Cloud provider credentials configured
201
+ - Read-only permissions (see [Permissions Documentation](https://github.com/logicmonitor/lm-cloud-resource-inventory/blob/main/docs/PERMISSIONS.md))
202
+
203
+ ---
204
+
205
+ ## Credential Setup
206
+
207
+ Configure credentials for each cloud provider before running the inventory.
208
+
209
+ ### AWS Credentials
210
+
211
+ **Option 1: AWS CLI (Recommended)**
212
+
213
+ ```bash
214
+ # Install AWS CLI and configure
215
+ aws configure
216
+
217
+ # Verify
218
+ aws sts get-caller-identity
219
+ ```
220
+
221
+ **Option 2: Environment Variables**
222
+
223
+ ```bash
224
+ export AWS_ACCESS_KEY_ID="your-access-key"
225
+ export AWS_SECRET_ACCESS_KEY="your-secret-key"
226
+ export AWS_DEFAULT_REGION="us-east-1"
227
+ ```
228
+
229
+ **Option 3: Named Profiles**
230
+
231
+ ```bash
232
+ # Use a specific profile
233
+ lmci run -p aws --profile production
234
+ ```
235
+
236
+ **Resources:** [AWS CLI Configuration](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html)
237
+
238
+ ---
239
+
240
+ ### Azure Credentials
241
+
242
+ **Option 1: Azure CLI (Recommended)**
243
+
244
+ ```bash
245
+ # Sign in
246
+ az login
247
+
248
+ # Verify
249
+ az account list --output table
250
+ ```
251
+
252
+ **Option 2: Service Principal**
253
+
254
+ ```bash
255
+ export AZURE_CLIENT_ID="appId"
256
+ export AZURE_CLIENT_SECRET="password"
257
+ export AZURE_TENANT_ID="tenant"
258
+ ```
259
+
260
+ **Resources:** [Azure CLI Authentication](https://learn.microsoft.com/en-us/cli/azure/authenticate-azure-cli)
261
+
262
+ ---
263
+
264
+ ### GCP Credentials
265
+
266
+ **Option 1: gcloud CLI (Recommended)**
267
+
268
+ ```bash
269
+ # Initialize and authenticate
270
+ gcloud init
271
+ gcloud auth application-default login
272
+
273
+ # Verify
274
+ gcloud config list
275
+ ```
276
+
277
+ **Option 2: Service Account Key**
278
+
279
+ ```bash
280
+ export GOOGLE_APPLICATION_CREDENTIALS="/path/to/service-account-key.json"
281
+ ```
282
+
283
+ The tool will automatically extract the `project_id` from the service account JSON file.
284
+
285
+ **Resources:** [GCP Application Default Credentials](https://cloud.google.com/docs/authentication/application-default-credentials)
286
+
287
+ ---
288
+
289
+ ### OCI Credentials
290
+
291
+ **Option 1: OCI CLI (Recommended)**
292
+
293
+ ```bash
294
+ # Run setup wizard
295
+ oci setup config
296
+
297
+ # Verify
298
+ oci iam region list
299
+ ```
300
+
301
+ Configuration is stored in `~/.oci/config`.
302
+
303
+ **Resources:** [OCI CLI Quickstart](https://docs.oracle.com/en-us/iaas/Content/API/SDKDocs/cliinstall.htm)
304
+
305
+ ---
306
+
307
+ ## Running in Cloud Shell
308
+
309
+ Each cloud provider offers a browser-based shell with credentials pre-configured - **the fastest way to run the inventory tool**.
310
+
311
+ | Provider | Cloud Shell | Notes |
312
+ |----------|-------------|-------|
313
+ | AWS | [AWS CloudShell](https://console.aws.amazon.com/cloudshell/) | Python pre-installed, credentials automatic |
314
+ | Azure | [Azure Cloud Shell](https://shell.azure.com/) | Python pre-installed, `az` authenticated |
315
+ | GCP | [Google Cloud Shell](https://shell.cloud.google.com/) | Python & gcloud pre-installed |
316
+ | OCI | [OCI Cloud Shell](https://cloud.oracle.com/?cloudshell=true) | OCI CLI pre-installed |
317
+
318
+ ---
319
+
320
+ ## Output Files
321
+
322
+ ### Summary CSV
323
+
324
+ The default output includes resource type breakdown by category:
325
+
326
+ ```csv
327
+ Provider,Account,Category,ResourceType,Region,Count
328
+ aws,123456789012,IaaS,ec2:instance,us-east-1,42
329
+ aws,123456789012,IaaS,ec2:instance,us-west-2,15
330
+ aws,123456789012,PaaS,lambda:function,us-east-1,28
331
+
332
+ TOTAL,,IaaS,,,57
333
+ TOTAL,,PaaS,,,28
334
+ TOTAL,,Non-Compute,,,125
335
+ ```
336
+
337
+ ### Detailed CSV (with `-d` flag)
338
+
339
+ Same as summary but saved to a separate `_detailed.csv` file.
340
+
341
+ ### Raw Inventory JSON
342
+
343
+ The `_inventory.json` file contains raw resource data for analysis:
344
+
345
+ ```json
346
+ [
347
+ {
348
+ "provider": "aws",
349
+ "account_id": "123456789012",
350
+ "region": "us-east-1",
351
+ "resource_type": "ec2:instance",
352
+ "count": 42,
353
+ "timestamp": "2024-12-22T10:30:00Z"
354
+ }
355
+ ]
356
+ ```
357
+
358
+ ---
359
+
360
+ ## Troubleshooting
361
+
362
+ ### AWS: "Resource Explorer not enabled"
363
+
364
+ AWS Resource Explorer is required. Enable it in your account:
365
+ 1. Go to [AWS Resource Explorer Console](https://console.aws.amazon.com/resource-explorer/)
366
+ 2. Enable Resource Explorer
367
+ 3. Create an aggregator index for cross-region queries
368
+
369
+ ### AWS: "Access Denied"
370
+
371
+ ```bash
372
+ # Verify credentials
373
+ aws sts get-caller-identity
374
+ ```
375
+
376
+ Check [Permissions Documentation](https://github.com/logicmonitor/lm-cloud-resource-inventory/blob/main/docs/PERMISSIONS.md) for required IAM permissions.
377
+
378
+ ### Azure: "AuthorizationFailed"
379
+
380
+ ```bash
381
+ # Verify login
382
+ az account show
383
+ ```
384
+
385
+ Ensure you have the `Reader` role on the subscription(s).
386
+
387
+ ### GCP: "Permission denied"
388
+
389
+ ```bash
390
+ # Verify auth
391
+ gcloud auth list
392
+ ```
393
+
394
+ Ensure you have the `roles/cloudasset.viewer` role.
395
+
396
+ ### OCI: "NotAuthorizedOrNotFound"
397
+
398
+ ```bash
399
+ # Verify config
400
+ cat ~/.oci/config
401
+ ```
402
+
403
+ Ensure the policy allows: `Allow group <group> to inspect all-resources in tenancy`
404
+
405
+ ### General: "ModuleNotFoundError"
406
+
407
+ ```bash
408
+ pip install .
409
+ ```
410
+
411
+ ---
412
+
413
+ ## Security & Privacy
414
+
415
+ **Security:**
416
+ - Read-only access only - no write/modify/delete operations
417
+ - Uses provider credential chains - no credential storage
418
+ - Only communicates with cloud provider APIs
419
+
420
+ **Data Collected:**
421
+ - Resource type counts
422
+ - Account/subscription identifiers
423
+ - Region/location information
424
+
425
+ **NOT Collected:**
426
+ - Resource names or IDs
427
+ - Resource content or data
428
+ - Configuration details
429
+ - Credentials or secrets
430
+
431
+ ---
432
+
433
+ ## Documentation
434
+
435
+ - [Required Permissions](https://github.com/logicmonitor/lm-cloud-resource-inventory/blob/main/docs/PERMISSIONS.md)
436
+ - [LogicMonitor Cloud Services](https://www.logicmonitor.com/support/cloud-services-and-resource-units)
437
+
438
+ ---
439
+
440
+ ## Support
441
+
442
+ - **Pre-sales:** Contact your LogicMonitor Sales Engineer
443
+ - **Customers:** Contact your Customer Success Manager
444
+
445
+ ---
446
+
447
+ ## License
448
+
449
+ MIT License - See [LICENSE](https://github.com/logicmonitor/lm-cloud-resource-inventory/blob/main/LICENSE) file for details.