Skip to content

Commit aed4d6c

Browse files
committed
Update .gitignore to exclude reports directory, add new demo script for setting default CPU utilization values, and enhance README with instructions for the new demo. Include npm scripts for running the demo in both normal and dry-run modes.
1 parent f503b2c commit aed4d6c

File tree

4 files changed

+556
-1
lines changed

4 files changed

+556
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ plans/
22
TODO.md
33
backups/
44
data/
5+
reports/
56

67
# Dependencies
78
node_modules/

examples/README.md

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
# Tidal API Bulk Operations Examples
2+
3+
This directory contains example scripts demonstrating various bulk operations with the Tidal API.
4+
5+
## Prerequisites
6+
7+
1. Create a `.env` file in the project root based on `.env.example`
8+
2. Set the required environment variables:
9+
- `TIDAL_WORKSPACE`
10+
- `TIDAL_USERNAME`
11+
- `TIDAL_PASSWORD`
12+
- Additional variables as needed for specific examples
13+
14+
## Available Examples
15+
16+
### 1. Server Backup Demo (`server-backup-demo.ts`)
17+
Creates a comprehensive backup of all servers in your Tidal workspace.
18+
19+
```bash
20+
npm run demo:server-backup
21+
```
22+
23+
### 2. Hostname to FQDN Demo (`hostname-to-fqdn-demo.ts`)
24+
Demonstrates updating server hostnames to fully qualified domain names.
25+
26+
```bash
27+
npm run demo:hostname-fqdn
28+
```
29+
30+
### 3. CPU Utilization Update Demo (`cpu-utilization-update-demo.ts`)
31+
Updates server CPU utilization values from a CSV file.
32+
33+
**Prerequisites:**
34+
- Set `CPU_UTILIZATION_CSV_PATH` in your `.env` file
35+
- Ensure the CSV file has the required format with columns: `Name`, `CPU Utilization %`, `Memory Utilization %`, `Disk Utilization % (Peak)`
36+
37+
```bash
38+
# Run with actual updates
39+
npm run demo:cpu-utilization
40+
41+
# Run in dry-run mode to preview changes
42+
npm run demo:cpu-utilization:dry-run
43+
```
44+
45+
### 4. CPU Utilization Default Value Demo (`cpu-util-default-value-demo.ts`)
46+
Sets the `cpu-util-manual-pct` custom field to 100 for all servers where it's not already set.
47+
48+
This example:
49+
- Fetches all servers from the Tidal API
50+
- Identifies servers without a CPU utilization value
51+
- Sets the default value to 100% for those servers
52+
- Provides detailed reporting and batch processing
53+
54+
```bash
55+
# Run with actual updates
56+
npm run demo:cpu-util-default
57+
58+
# Run in dry-run mode to preview changes
59+
npm run demo:cpu-util-default:dry-run
60+
```
61+
62+
## Common Features
63+
64+
All examples include:
65+
- **Dry Run Mode**: Use `--dry-run` flag or set `DRY_RUN=true` to preview changes without making actual updates
66+
- **Batch Processing**: Configurable batch sizes to avoid API rate limits
67+
- **Error Handling**: Comprehensive error reporting and retry logic
68+
- **Progress Reporting**: Real-time progress updates during processing
69+
- **Detailed Logging**: Structured logging for debugging and monitoring
70+
- **Report Generation**: JSON reports saved to the `reports/` directory
71+
72+
## Configuration
73+
74+
Examples use configuration from `src/config/environment.ts` which loads from:
75+
- Environment variables
76+
- `.env` file
77+
- Default values
78+
79+
Key configuration options:
80+
- `bulk.batchSize`: Number of items to process in each batch
81+
- `bulk.retryAttempts`: Number of retry attempts for failed operations
82+
- `bulk.retryDelay`: Delay between retry attempts (milliseconds)
83+
84+
## Running Examples
85+
86+
You can run examples in several ways:
87+
88+
1. **Using npm scripts** (recommended):
89+
```bash
90+
npm run demo:cpu-util-default
91+
npm run demo:cpu-util-default:dry-run
92+
```
93+
94+
2. **Using ts-node directly**:
95+
```bash
96+
npx ts-node examples/cpu-util-default-value-demo.ts
97+
npx ts-node examples/cpu-util-default-value-demo.ts --dry-run
98+
```
99+
100+
3. **Using environment variables**:
101+
```bash
102+
DRY_RUN=true npm run demo:cpu-util-default
103+
```
104+
105+
## Output
106+
107+
Examples generate:
108+
- Console output with progress updates and summaries
109+
- JSON reports in the `reports/` directory
110+
- Detailed logging (configurable level)
111+
112+
## Error Handling
113+
114+
All examples include robust error handling for:
115+
- Authentication failures
116+
- API errors (rate limits, server errors)
117+
- Network connectivity issues
118+
- Data validation errors
119+
- File system operations
120+
121+
## Support
122+
123+
For questions or issues with these examples, please refer to the main project documentation or create an issue in the repository.

0 commit comments

Comments
 (0)