rubber-ducky 1.2.2__py3-none-any.whl → 1.4.0__py3-none-any.whl
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.
- crumbs/disk-usage/disk-usage.sh +12 -0
- crumbs/disk-usage/info.txt +3 -0
- crumbs/git-log/git-log.sh +24 -0
- crumbs/git-log/info.txt +3 -0
- crumbs/git-status/git-status.sh +21 -0
- crumbs/git-status/info.txt +3 -0
- crumbs/process-list/info.txt +3 -0
- crumbs/process-list/process-list.sh +20 -0
- crumbs/recent-files/info.txt +3 -0
- crumbs/recent-files/recent-files.sh +13 -0
- crumbs/system-health/info.txt +3 -0
- crumbs/system-health/system-health.sh +58 -0
- ducky/__init__.py +3 -1
- ducky/config.py +60 -0
- ducky/ducky.py +731 -90
- examples/POLLING_USER_GUIDE.md +470 -0
- examples/mock-logs/info.txt +7 -0
- examples/mock-logs/mock-logs.sh +39 -0
- rubber_ducky-1.4.0.dist-info/METADATA +210 -0
- rubber_ducky-1.4.0.dist-info/RECORD +24 -0
- rubber_ducky-1.4.0.dist-info/top_level.txt +3 -0
- rubber_ducky-1.2.2.dist-info/METADATA +0 -72
- rubber_ducky-1.2.2.dist-info/RECORD +0 -8
- rubber_ducky-1.2.2.dist-info/top_level.txt +0 -1
- {rubber_ducky-1.2.2.dist-info → rubber_ducky-1.4.0.dist-info}/WHEEL +0 -0
- {rubber_ducky-1.2.2.dist-info → rubber_ducky-1.4.0.dist-info}/entry_points.txt +0 -0
- {rubber_ducky-1.2.2.dist-info → rubber_ducky-1.4.0.dist-info}/licenses/LICENSE +0 -0
|
@@ -0,0 +1,470 @@
|
|
|
1
|
+
# Polling Feature User Guide
|
|
2
|
+
|
|
3
|
+
This guide explains how to use the AI-driven background polling feature in Rubber Ducky.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
The polling feature allows you to run a crumb script at regular intervals and have AI analyze the output automatically. This is useful for:
|
|
8
|
+
- Monitoring server logs for errors or anomalies
|
|
9
|
+
- Tracking system metrics over time
|
|
10
|
+
- Watching for specific patterns in data streams
|
|
11
|
+
- Getting AI-powered insights on repeating data sources
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## Quick Start Example
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
# Start polling with a pre-configured crumb
|
|
19
|
+
ducky --poll mock-logs
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Output:
|
|
23
|
+
```
|
|
24
|
+
Starting interval polling for 'mock-logs' (interval: 5s)...
|
|
25
|
+
Poll prompt: Analyze these mock logs and identify any errors, warnings, or
|
|
26
|
+
interesting patterns. Keep it brief.
|
|
27
|
+
Press Ctrl+C to stop polling.
|
|
28
|
+
|
|
29
|
+
[2025-12-28 23:02:43] Polling mock-logs...
|
|
30
|
+
Script output: 54 bytes
|
|
31
|
+
AI: Brief analysis of the mock log entry:
|
|
32
|
+
... (AI analysis) ...
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
## Creating a Polling Crumb
|
|
38
|
+
|
|
39
|
+
### Step 1: Create the Crumb Directory
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
mkdir -p ~/.ducky/crumbs/my-logs
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Step 2: Create the Configuration File
|
|
46
|
+
|
|
47
|
+
Create `~/.ducky/crumbs/my-logs/info.txt`:
|
|
48
|
+
|
|
49
|
+
```
|
|
50
|
+
name: my-logs
|
|
51
|
+
type: shell
|
|
52
|
+
description: Fetch and analyze application logs
|
|
53
|
+
poll: true
|
|
54
|
+
poll_type: interval # Can be "interval" or "continuous"
|
|
55
|
+
poll_interval: 10 # Poll every 10 seconds
|
|
56
|
+
poll_prompt: Analyze these logs for errors, warnings, or unusual patterns. Be concise.
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### Step 3: Create the Script
|
|
60
|
+
|
|
61
|
+
Create `~/.ducky/crumbs/my-logs/my-logs.sh`:
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
#!/usr/bin/env bash
|
|
65
|
+
# Fetch last 50 lines of application logs
|
|
66
|
+
tail -50 /var/log/app.log
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Step 4: Make the Script Executable
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
chmod +x ~/.ducky/crumbs/my-logs/my-logs.sh
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### Step 5: Test the Crumb
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
# Test the script directly
|
|
79
|
+
~/.ducky/crumbs/my-logs/my-logs.sh
|
|
80
|
+
|
|
81
|
+
# Test with ducky polling
|
|
82
|
+
ducky --poll my-logs
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
## Configuration Reference
|
|
88
|
+
|
|
89
|
+
### info.txt Fields
|
|
90
|
+
|
|
91
|
+
| Field | Type | Required | Default | Description |
|
|
92
|
+
|-------|------|----------|---------|-------------|
|
|
93
|
+
| `name` | string | Yes | - | Crumb name used to reference it |
|
|
94
|
+
| `type` | string | Yes | `shell` | Crumb type (currently only `shell` supported) |
|
|
95
|
+
| `description` | string | No | - | Human-readable description |
|
|
96
|
+
| `poll` | boolean | No | `false` | Enable polling for this crumb |
|
|
97
|
+
| `poll_type` | string | No | `interval` | Either `"interval"` (run repeatedly) or `"continuous"` (run once, stream) |
|
|
98
|
+
| `poll_interval` | integer | No | `2` | Seconds between polls (for `interval` type) |
|
|
99
|
+
| `poll_prompt` | string | No | `"Analyze this output."` | The prompt sent to AI with each poll's output |
|
|
100
|
+
|
|
101
|
+
### Poll Types
|
|
102
|
+
|
|
103
|
+
#### Interval Polling (default)
|
|
104
|
+
The script runs from scratch at each interval:
|
|
105
|
+
- ✅ Good for: Fetching logs, checking system resources, running commands
|
|
106
|
+
- ✅ Clean state: Each run starts fresh
|
|
107
|
+
- ⚠️ Higher resource usage if script is expensive
|
|
108
|
+
|
|
109
|
+
```
|
|
110
|
+
poll_type: interval
|
|
111
|
+
poll_interval: 10
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
Example:
|
|
115
|
+
```bash
|
|
116
|
+
#!/bin/bash
|
|
117
|
+
# Runs completely every 10 seconds
|
|
118
|
+
tail -50 /var/log/nginx/access.log
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
#### Continuous Polling
|
|
122
|
+
The script runs once in the background and output is streamed:
|
|
123
|
+
- ✅ Good for: Tail -f, real-time streams, long-running processes
|
|
124
|
+
- ✅ Lower resource: Process runs continuously without restarting
|
|
125
|
+
- ⚠️ Accumulated output grows over time
|
|
126
|
+
|
|
127
|
+
```
|
|
128
|
+
poll_type: continuous
|
|
129
|
+
poll_interval: 5
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
Example:
|
|
133
|
+
```bash
|
|
134
|
+
#!/bin/bash
|
|
135
|
+
# Runs once, continuously streams output
|
|
136
|
+
tail -f /var/log/app.log
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
---
|
|
140
|
+
|
|
141
|
+
## Using Polling
|
|
142
|
+
|
|
143
|
+
### Method 1: Command Line Interface
|
|
144
|
+
|
|
145
|
+
Start polling immediately without entering interactive mode:
|
|
146
|
+
|
|
147
|
+
```bash
|
|
148
|
+
# Use crumb's default settings
|
|
149
|
+
ducky --poll my-logs
|
|
150
|
+
|
|
151
|
+
# Override interval (every 10 seconds)
|
|
152
|
+
ducky --poll my-logs --interval 10
|
|
153
|
+
|
|
154
|
+
# Override prompt with custom instruction
|
|
155
|
+
ducky --poll my-logs --prompt "Extract only error messages and show counts"
|
|
156
|
+
|
|
157
|
+
# Combine overrides
|
|
158
|
+
ducky --poll my-logs --interval 15 --prompt "Summarize critical issues only"
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
### Method 2: Interactive Mode
|
|
162
|
+
|
|
163
|
+
Start ducky in interactive mode, then trigger polling:
|
|
164
|
+
|
|
165
|
+
```bash
|
|
166
|
+
ducky
|
|
167
|
+
|
|
168
|
+
# Start polling with defaults
|
|
169
|
+
>> /poll my-logs
|
|
170
|
+
|
|
171
|
+
# Override interval
|
|
172
|
+
>> /poll my-logs -i 10
|
|
173
|
+
|
|
174
|
+
# Override prompt
|
|
175
|
+
>> /poll my-logs -p "Count error types"
|
|
176
|
+
|
|
177
|
+
# Combine options
|
|
178
|
+
>> /poll my-logs -i 15 -p "Show only warnings and errors"
|
|
179
|
+
|
|
180
|
+
# Stop polling and return to interactive mode
|
|
181
|
+
>> /stop-poll
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
### Stopping Polling
|
|
185
|
+
|
|
186
|
+
From CLI:
|
|
187
|
+
- Press `Ctrl+C` at any time
|
|
188
|
+
|
|
189
|
+
From Interactive Mode:
|
|
190
|
+
- Press `Ctrl+C` at any time
|
|
191
|
+
- Or type `/stop-poll`
|
|
192
|
+
|
|
193
|
+
---
|
|
194
|
+
|
|
195
|
+
## Example Crumbs
|
|
196
|
+
|
|
197
|
+
### Example 1: Server Log Monitor
|
|
198
|
+
|
|
199
|
+
**Directory:** `~/.ducky/crumbs/server-logs/`
|
|
200
|
+
|
|
201
|
+
**info.txt:**
|
|
202
|
+
```
|
|
203
|
+
name: server-logs
|
|
204
|
+
type: shell
|
|
205
|
+
description: Monitor server logs for issues
|
|
206
|
+
poll: true
|
|
207
|
+
poll_type: interval
|
|
208
|
+
poll_interval: 5
|
|
209
|
+
poll_prompt: Analyze these logs for errors, warnings, or anomalies. Identify patterns if any.
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
**server-logs.sh:**
|
|
213
|
+
```bash
|
|
214
|
+
#!/bin/bash
|
|
215
|
+
curl -s http://localhost:8080/api/logs | tail -50
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
---
|
|
219
|
+
|
|
220
|
+
### Example 2: System Resource Monitor
|
|
221
|
+
|
|
222
|
+
**Directory:** `~/.ducky/crumbs/system-check/`
|
|
223
|
+
|
|
224
|
+
**info.txt:**
|
|
225
|
+
```
|
|
226
|
+
name: system-check
|
|
227
|
+
type: shell
|
|
228
|
+
description: Check system resources
|
|
229
|
+
poll: true
|
|
230
|
+
poll_type: interval
|
|
231
|
+
poll_interval: 30
|
|
232
|
+
poll_prompt: Analyze system health. Is anything concerning?
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
**system-check.sh:**
|
|
236
|
+
```bash
|
|
237
|
+
#!/bin/bash
|
|
238
|
+
echo "CPU Usage:"
|
|
239
|
+
top -l 1 | grep "CPU usage"
|
|
240
|
+
echo -e "\nMemory Usage:"
|
|
241
|
+
vm_stat | perl -ne '/page size of (\d+)/ and $ps=$1; /Pages\s+([^:]+)[^\d]+(\d+)/ and printf("%-16s % 16.2f Mi\n", "$1:", $2 * $ps / 1048576);'
|
|
242
|
+
echo -e "\nDisk Usage:"
|
|
243
|
+
df -h
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
---
|
|
247
|
+
|
|
248
|
+
### Example 3: Continuous Log Stream
|
|
249
|
+
|
|
250
|
+
**Directory:** `~/.ducky/crumbs/live-logs/`
|
|
251
|
+
|
|
252
|
+
**info.txt:**
|
|
253
|
+
```
|
|
254
|
+
name: live-logs
|
|
255
|
+
type: shell
|
|
256
|
+
description: Continuously monitor live logs
|
|
257
|
+
poll: true
|
|
258
|
+
poll_type: continuous
|
|
259
|
+
poll_interval: 3
|
|
260
|
+
poll_prompt: Summarize the latest log changes. Alert on critical issues.
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
**live-logs.sh:**
|
|
264
|
+
```bash
|
|
265
|
+
#!/bin/bash
|
|
266
|
+
tail -f /var/log/app.log
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
---
|
|
270
|
+
|
|
271
|
+
### Example 4: API Health Check
|
|
272
|
+
|
|
273
|
+
**Directory:** `~/.ducky/crumbs/api-health/`
|
|
274
|
+
|
|
275
|
+
**info.txt:**
|
|
276
|
+
```
|
|
277
|
+
name: api-health
|
|
278
|
+
type: shell
|
|
279
|
+
description: Check API endpoints
|
|
280
|
+
poll: true
|
|
281
|
+
poll_type: interval
|
|
282
|
+
poll_interval: 60
|
|
283
|
+
poll_prompt: Are there any failing endpoints or error spikes?
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
**api-health.sh:**
|
|
287
|
+
```bash
|
|
288
|
+
#!/bin/bash
|
|
289
|
+
echo "Main API:"
|
|
290
|
+
curl -s -w "\nHTTP Status: %{http_code}\nResponse Time: %{time_total}s\n" http://api.example.com/health -o /dev/null
|
|
291
|
+
|
|
292
|
+
echo -e "\nAuth Service:"
|
|
293
|
+
curl -s -w "\nHTTP Status: %{http_code}\nResponse Time: %{time_total}s\n" http://api.example.com/auth/health -o /dev/null
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
---
|
|
297
|
+
|
|
298
|
+
## Tips and Best Practices
|
|
299
|
+
|
|
300
|
+
### 1. Choose Appropriate Intervals
|
|
301
|
+
- **Fast-changing data:** 2-5 seconds (logs, metrics)
|
|
302
|
+
- **Medium-frequency changes:** 10-30 seconds (API checks, resource monitoring)
|
|
303
|
+
- **Slow-changing data:** 60+ seconds (long-running trends)
|
|
304
|
+
|
|
305
|
+
### 2. Write Efficient Scripts
|
|
306
|
+
- **For interval polling:** Scripts run from scratch each time
|
|
307
|
+
- Limit output size (use `tail` instead of `cat`)
|
|
308
|
+
- Avoid expensive operations (network calls, heavy computation)
|
|
309
|
+
- Cache results if possible
|
|
310
|
+
|
|
311
|
+
- **For continuous polling:** Script runs once and streams
|
|
312
|
+
- The process should be long-running (like `tail -f`)
|
|
313
|
+
- Output should be finite (don't accumulate indefinitely)
|
|
314
|
+
|
|
315
|
+
### 3. Craft Effective Poll Prompts
|
|
316
|
+
Good prompts:
|
|
317
|
+
- ✅ "Analyze these logs for errors, warnings, or anomalies. Be concise."
|
|
318
|
+
- ✅ "Summarize the key findings and recommend next steps."
|
|
319
|
+
- ✅ "Identify any performance issues or resource constraints."
|
|
320
|
+
|
|
321
|
+
Avoid:
|
|
322
|
+
- ❌ Too generic: "Analyze this"
|
|
323
|
+
- ❌ Too complex: "Review every line, compare with historical data, generate reports, check for five different error types, and create a detailed analysis with recommendations..."
|
|
324
|
+
|
|
325
|
+
### 4. Test Locally First
|
|
326
|
+
```bash
|
|
327
|
+
# Verify your script works
|
|
328
|
+
~/.ducky/crumbs/my-logs/my-logs.sh
|
|
329
|
+
|
|
330
|
+
# Check output size
|
|
331
|
+
~/.ducky/crumbs/my-logs/my-logs.sh | wc -l
|
|
332
|
+
|
|
333
|
+
# Test with short interval
|
|
334
|
+
ducky --poll my-logs --interval 2
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
### 5. Manage Conversation History
|
|
338
|
+
Polling adds messages to the conversation history. For long-running sessions:
|
|
339
|
+
```bash
|
|
340
|
+
# Clear history periodically to keep AI context focused
|
|
341
|
+
ducky
|
|
342
|
+
>> /poll my-logs
|
|
343
|
+
# ... let it run ...
|
|
344
|
+
>> /stop-poll
|
|
345
|
+
>> /clear
|
|
346
|
+
>> /poll my-logs # Continue with fresh context
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
---
|
|
350
|
+
|
|
351
|
+
## Troubleshooting
|
|
352
|
+
|
|
353
|
+
### Polling Not Starting
|
|
354
|
+
|
|
355
|
+
**Problem:** Command returns immediately without polling
|
|
356
|
+
|
|
357
|
+
**Possible causes:**
|
|
358
|
+
1. Crumb not found
|
|
359
|
+
```bash
|
|
360
|
+
# Check available crumbs
|
|
361
|
+
ducky --poll
|
|
362
|
+
# See available crumbs listed
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
2. Script not executable
|
|
366
|
+
```bash
|
|
367
|
+
chmod +x ~/.ducky/crumbs/my-logs/my-logs.sh
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
3. Ollama not running
|
|
371
|
+
```bash
|
|
372
|
+
# Start Ollama
|
|
373
|
+
ollama serve
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
### AI Returns Commands Instead of Analysis
|
|
377
|
+
|
|
378
|
+
**Problem:** AI responds with bash commands
|
|
379
|
+
|
|
380
|
+
**Status:** This should be fixed (added in version 1.3.0)
|
|
381
|
+
|
|
382
|
+
If you experience this:
|
|
383
|
+
```bash
|
|
384
|
+
# Check version
|
|
385
|
+
ducky --help # Should show version 1.3.0+
|
|
386
|
+
```
|
|
387
|
+
|
|
388
|
+
### High Memory Usage
|
|
389
|
+
|
|
390
|
+
**Problem:** Memory grows over time during polling
|
|
391
|
+
|
|
392
|
+
**Solutions:**
|
|
393
|
+
1. Use continuous polling for data streams
|
|
394
|
+
2. Limit output size in your script
|
|
395
|
+
3. Clear conversation history periodically
|
|
396
|
+
|
|
397
|
+
### Script Takes Too Long
|
|
398
|
+
|
|
399
|
+
**Problem:** Polling interval shorter than script execution time
|
|
400
|
+
|
|
401
|
+
**Solutions:**
|
|
402
|
+
1. Increase `poll_interval` in info.txt
|
|
403
|
+
2. Optimize your script (limit data fetched)
|
|
404
|
+
3. Consider continuous polling instead
|
|
405
|
+
|
|
406
|
+
---
|
|
407
|
+
|
|
408
|
+
## Advanced Use Cases
|
|
409
|
+
|
|
410
|
+
### Multiple Concurrent Polls
|
|
411
|
+
|
|
412
|
+
Currently, only one polling session can run at a time. To monitor multiple sources:
|
|
413
|
+
1. Create a single crumb that aggregates multiple sources
|
|
414
|
+
2. Or run multiple ducky instances in separate terminals
|
|
415
|
+
|
|
416
|
+
```bash
|
|
417
|
+
# Terminal 1
|
|
418
|
+
ducky --poll logs
|
|
419
|
+
|
|
420
|
+
# Terminal 2
|
|
421
|
+
ducky --poll metrics
|
|
422
|
+
```
|
|
423
|
+
|
|
424
|
+
### Combining with Standard Ducky
|
|
425
|
+
|
|
426
|
+
Use polling for monitoring, then switch to interactive mode for deeper analysis:
|
|
427
|
+
|
|
428
|
+
```bash
|
|
429
|
+
# Monitor for issues
|
|
430
|
+
ducky --poll my-logs
|
|
431
|
+
|
|
432
|
+
# Press Ctrl+C when you see an issue, then:
|
|
433
|
+
ducky --directory /var/log
|
|
434
|
+
>> Show me the error logs from the last hour
|
|
435
|
+
>> Analyze these errors and suggest fixes
|
|
436
|
+
```
|
|
437
|
+
|
|
438
|
+
### Custom Poll Prompts for Different Contexts
|
|
439
|
+
|
|
440
|
+
Override prompts based on what you're looking for:
|
|
441
|
+
|
|
442
|
+
```bash
|
|
443
|
+
# Focus on errors
|
|
444
|
+
ducky --poll my-logs -p "Show only ERROR level logs"
|
|
445
|
+
|
|
446
|
+
# Focus on performance
|
|
447
|
+
ducky --poll my-logs -p "Analyze performance metrics and bottlenecks"
|
|
448
|
+
|
|
449
|
+
# Get a summary
|
|
450
|
+
ducky --poll my-logs -p "Give me a 2-sentence summary"
|
|
451
|
+
```
|
|
452
|
+
|
|
453
|
+
---
|
|
454
|
+
|
|
455
|
+
## File Locations
|
|
456
|
+
|
|
457
|
+
- **Crumbs directory:** `~/.ducky/crumbs/`
|
|
458
|
+
- **Conversation log:** `~/.ducky/conversation.log`
|
|
459
|
+
- **Prompt history:** `~/.ducky/prompt_history`
|
|
460
|
+
- **Configuration:** `~/.ducky/config`
|
|
461
|
+
|
|
462
|
+
---
|
|
463
|
+
|
|
464
|
+
## Support and Resources
|
|
465
|
+
|
|
466
|
+
- Main README: [README.md](README.md)
|
|
467
|
+
- Test Output Examples: [POLLING_TEST_OUTPUTS.md](POLLING_TEST_OUTPUTS.md)
|
|
468
|
+
- GitHub Issues: For bugs and feature requests
|
|
469
|
+
|
|
470
|
+
Happy polling! 🦆
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
name: mock-logs
|
|
2
|
+
type: shell
|
|
3
|
+
description: Generate mock log data for testing polling functionality
|
|
4
|
+
poll: true
|
|
5
|
+
poll_type: interval
|
|
6
|
+
poll_interval: 3
|
|
7
|
+
poll_prompt: Analyze these mock logs and identify any errors, warnings, or interesting patterns. Keep it brief.
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
|
|
3
|
+
# Generate mock log data for testing polling
|
|
4
|
+
|
|
5
|
+
# Random timestamps
|
|
6
|
+
TIMESTAMP=$(date '+%Y-%m-%d %H:%M:%S')
|
|
7
|
+
|
|
8
|
+
# Array of log levels and messages
|
|
9
|
+
LEVELS=("INFO" "WARNING" "ERROR" "DEBUG")
|
|
10
|
+
MESSAGES=(
|
|
11
|
+
"User login successful: user_id=USER_123"
|
|
12
|
+
"Database query completed in 45ms"
|
|
13
|
+
"API request from IP_ADDRESS"
|
|
14
|
+
"Cache hit for key: user_settings_KEY"
|
|
15
|
+
"Connection timeout to external service"
|
|
16
|
+
"Disk usage at 85%"
|
|
17
|
+
"Payment processed: order_id=ORDER_789"
|
|
18
|
+
"Scheduled task 'daily_backup' started"
|
|
19
|
+
"Failed to send email notification"
|
|
20
|
+
"New user registration: email=user@example.local"
|
|
21
|
+
"Memory usage: 2.4GB / 8GB"
|
|
22
|
+
"Request rate: 150 req/s"
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
# Select random level and message
|
|
26
|
+
LEVEL=${LEVELS[$RANDOM % ${#LEVELS[@]}]}
|
|
27
|
+
MESSAGE=${MESSAGES[$RANDOM % ${#MESSAGES[@]}]}
|
|
28
|
+
|
|
29
|
+
# Add some variety - occasionally include errors
|
|
30
|
+
if [ $RANDOM -lt 4 ]; then
|
|
31
|
+
LEVEL="ERROR"
|
|
32
|
+
MESSAGE="Failed to process request: timeout"
|
|
33
|
+
elif [ $RANDOM -lt 4 ]; then
|
|
34
|
+
LEVEL="WARNING"
|
|
35
|
+
MESSAGE="High latency detected: response time > 500ms"
|
|
36
|
+
fi
|
|
37
|
+
|
|
38
|
+
# Format the log entry
|
|
39
|
+
echo "[$TIMESTAMP] $LEVEL - $MESSAGE"
|