@gazzehamine/armada-watch-agent 1.4.7 → 1.4.9

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.
package/README.md CHANGED
@@ -10,6 +10,35 @@ Lightweight monitoring agent for EC2 instances. Collects and sends system metric
10
10
  npm install -g @gazzehamine/armada-watch-agent
11
11
  ```
12
12
 
13
+ ### Automated Setup (Easiest)
14
+
15
+ After installing the agent, run the setup wizard:
16
+
17
+ ```bash
18
+ armada-watch-setup
19
+ ```
20
+
21
+ This interactive script will:
22
+ - ✅ Verify Node.js and PM2 installation
23
+ - ✅ Configure the agent (.env file)
24
+ - ✅ Start the agent with PM2
25
+ - ✅ Optionally configure Nginx monitoring
26
+ - ✅ Optionally configure SSL certificate monitoring
27
+ - ✅ Optionally configure security monitoring
28
+ - ✅ Set up PM2 auto-start on boot
29
+
30
+ **Note:** For SSL monitoring to work, you need to restart PM2 daemon after setup:
31
+ ```bash
32
+ pm2 kill
33
+ cd ~/armada-watch-agent
34
+ pm2 start armada-watch-agent --name armada-watch
35
+ pm2 save
36
+ ```
37
+
38
+ ## Manual Setup
39
+
40
+ If you prefer to configure manually:
41
+
13
42
  ## Quick Start
14
43
 
15
44
  ### 1. Set Environment Variables
package/dist/index.js CHANGED
@@ -21,6 +21,11 @@ try {
21
21
  catch (error) {
22
22
  console.warn("Could not read agent version from package.json");
23
23
  }
24
+ // Handle --version flag
25
+ if (process.argv.includes("--version") || process.argv.includes("-v")) {
26
+ console.log(AGENT_VERSION);
27
+ process.exit(0);
28
+ }
24
29
  const SERVER_URL = process.env.SERVER_URL || "http://localhost:4000";
25
30
  const INSTANCE_NAME = process.env.INSTANCE_NAME || os_1.default.hostname();
26
31
  const REGION = process.env.REGION || "unknown";
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "@gazzehamine/armada-watch-agent",
3
- "version": "1.4.7",
3
+ "version": "1.4.9",
4
4
  "description": "Monitoring agent for Armada Watch - EC2 instance monitoring with SSL, PM2, Nginx, Systemd, and Security monitoring",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
7
- "armada-watch-agent": "dist/index.js"
7
+ "armada-watch-agent": "dist/index.js",
8
+ "armada-watch-setup": "setup.sh"
8
9
  },
9
10
  "scripts": {
10
11
  "build": "tsc",
@@ -30,7 +31,8 @@
30
31
  "files": [
31
32
  "dist",
32
33
  "README.md",
33
- ".env.example"
34
+ ".env.example",
35
+ "setup.sh"
34
36
  ],
35
37
  "dependencies": {
36
38
  "axios": "^1.6.0",
package/setup.sh ADDED
@@ -0,0 +1,560 @@
1
+ #!/bin/bash
2
+
3
+ ################################################################################
4
+ # Armada Watch Agent - Automated Installation Script
5
+ #
6
+ # This script automates the complete installation and configuration of the
7
+ # Armada Watch monitoring agent on EC2 instances.
8
+ #
9
+ # Supports: Ubuntu 20.04+, Amazon Linux 2, Amazon Linux 2023
10
+ ################################################################################
11
+
12
+ set -e # Exit on error
13
+
14
+ # Color codes for output
15
+ RED='\033[0;31m'
16
+ GREEN='\033[0;32m'
17
+ YELLOW='\033[1;33m'
18
+ BLUE='\033[0;34m'
19
+ NC='\033[0m' # No Color
20
+
21
+ # Helper functions
22
+ print_success() {
23
+ echo -e "${GREEN}✅ $1${NC}"
24
+ }
25
+
26
+ print_error() {
27
+ echo -e "${RED}❌ $1${NC}"
28
+ }
29
+
30
+ print_warning() {
31
+ echo -e "${YELLOW}⚠️ $1${NC}"
32
+ }
33
+
34
+ print_info() {
35
+ echo -e "${BLUE}ℹ️ $1${NC}"
36
+ }
37
+
38
+ print_header() {
39
+ echo -e "\n${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
40
+ echo -e "${BLUE}$1${NC}"
41
+ echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}\n"
42
+ }
43
+
44
+ # Check if running with sudo
45
+ if [ "$EUID" -eq 0 ]; then
46
+ print_error "Please do not run this script as root or with sudo"
47
+ print_info "Run as: ./setup-agent.sh"
48
+ exit 1
49
+ fi
50
+
51
+ # Clear screen and show banner
52
+ clear
53
+ echo -e "${GREEN}"
54
+ cat << "EOF"
55
+ _ _ __ __ _ _
56
+ / \ _ __ _ __ ___ __ _ | | \ \ / /_ _| |_ ___| |__
57
+ / _ \ | '__| '_ ` _ \ / _` | | | _____\ \ /\ / / _` | __/ __| '_ \
58
+ / ___ \| | | | | | | | (_| | | |__|_____\ V V / (_| | || (__| | | |
59
+ /_/ \_\_| |_| |_| |_|\__,_| |___| \_/\_/ \__,_|\__\___|_| |_|
60
+
61
+ Automated Agent Installation Script
62
+
63
+ EOF
64
+ echo -e "${NC}"
65
+
66
+ print_info "This script will install and configure the Armada Watch monitoring agent"
67
+ echo ""
68
+
69
+ ################################################################################
70
+ # Step 1: System Detection
71
+ ################################################################################
72
+
73
+ print_header "📋 Step 1: System Detection"
74
+
75
+ # Detect OS
76
+ if [ -f /etc/os-release ]; then
77
+ . /etc/os-release
78
+ OS=$ID
79
+ OS_VERSION=$VERSION_ID
80
+ print_success "Operating System: $PRETTY_NAME"
81
+ else
82
+ print_error "Cannot detect operating system"
83
+ exit 1
84
+ fi
85
+
86
+ # Check if OS is supported
87
+ if [[ "$OS" != "ubuntu" && "$OS" != "amzn" ]]; then
88
+ print_error "Unsupported OS: $OS"
89
+ print_info "Supported: Ubuntu 20.04+, Amazon Linux 2, Amazon Linux 2023"
90
+ exit 1
91
+ fi
92
+
93
+ # Detect current user
94
+ CURRENT_USER=$(whoami)
95
+ print_success "Running as user: $CURRENT_USER"
96
+
97
+ # Check for sudo access
98
+ if sudo -n true 2>/dev/null; then
99
+ print_success "Sudo access: Available"
100
+ else
101
+ print_warning "Sudo access may require password"
102
+ fi
103
+
104
+ # Try to detect instance metadata (if running on EC2)
105
+ print_info "Attempting to detect EC2 instance metadata..."
106
+
107
+ # Get IMDSv2 token
108
+ TOKEN=$(curl -X PUT "http://169.254.169.254/latest/api/token" \
109
+ -H "X-aws-ec2-metadata-token-ttl-seconds: 21600" \
110
+ --max-time 2 --silent 2>/dev/null) || true
111
+
112
+ if [ -n "$TOKEN" ]; then
113
+ AUTO_INSTANCE_ID=$(curl -H "X-aws-ec2-metadata-token: $TOKEN" \
114
+ http://169.254.169.254/latest/meta-data/instance-id \
115
+ --max-time 2 --silent 2>/dev/null) || true
116
+
117
+ AUTO_REGION=$(curl -H "X-aws-ec2-metadata-token: $TOKEN" \
118
+ http://169.254.169.254/latest/meta-data/placement/region \
119
+ --max-time 2 --silent 2>/dev/null) || true
120
+
121
+ AUTO_HOSTNAME=$(curl -H "X-aws-ec2-metadata-token: $TOKEN" \
122
+ http://169.254.169.254/latest/meta-data/hostname \
123
+ --max-time 2 --silent 2>/dev/null) || true
124
+
125
+ if [ -n "$AUTO_INSTANCE_ID" ]; then
126
+ print_success "Detected Instance ID: $AUTO_INSTANCE_ID"
127
+ print_success "Detected Region: $AUTO_REGION"
128
+ fi
129
+ else
130
+ print_warning "Could not detect EC2 metadata (not running on EC2?)"
131
+ AUTO_INSTANCE_ID=$(hostname)
132
+ AUTO_REGION="us-east-1"
133
+ fi
134
+
135
+ ################################################################################
136
+ # Step 2: Node.js Installation
137
+ ################################################################################
138
+
139
+ print_header "📥 Step 2: Node.js Installation"
140
+
141
+ # Check if Node.js is already installed
142
+ if command -v node &> /dev/null; then
143
+ NODE_VERSION=$(node -v | cut -d'v' -f2 | cut -d'.' -f1)
144
+ print_info "Node.js $(node -v) is already installed"
145
+
146
+ if [ "$NODE_VERSION" -ge 16 ]; then
147
+ print_success "Node.js version is sufficient (v16+)"
148
+ SKIP_NODE_INSTALL=true
149
+ else
150
+ print_warning "Node.js version is too old (requires v16+)"
151
+ read -p "Do you want to upgrade Node.js to v20? (y/n): " UPGRADE_NODE
152
+ if [[ "$UPGRADE_NODE" =~ ^[Yy]$ ]]; then
153
+ SKIP_NODE_INSTALL=false
154
+ else
155
+ print_error "Cannot proceed without Node.js 16+"
156
+ exit 1
157
+ fi
158
+ fi
159
+ else
160
+ print_info "Node.js not found"
161
+ SKIP_NODE_INSTALL=false
162
+ fi
163
+
164
+ if [ "$SKIP_NODE_INSTALL" != "true" ]; then
165
+ print_info "Installing Node.js 20.x..."
166
+
167
+ if [ "$OS" == "ubuntu" ]; then
168
+ # Ubuntu installation
169
+ sudo apt-get update -qq
170
+ sudo apt-get install -y -qq ca-certificates curl gnupg
171
+ curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
172
+ sudo apt-get install -y -qq nodejs
173
+ elif [ "$OS" == "amzn" ]; then
174
+ # Amazon Linux installation
175
+ curl -fsSL https://rpm.nodesource.com/setup_20.x | sudo bash -
176
+ sudo yum install -y nodejs
177
+ fi
178
+
179
+ if command -v node &> /dev/null; then
180
+ print_success "Node.js $(node -v) installed successfully"
181
+ print_success "NPM $(npm -v) installed successfully"
182
+ else
183
+ print_error "Node.js installation failed"
184
+ exit 1
185
+ fi
186
+ fi
187
+
188
+ ################################################################################
189
+ # Step 3: Agent Verification
190
+ ################################################################################
191
+
192
+ print_header "📦 Step 3: Armada Watch Agent Verification"
193
+
194
+ # Debug: Show current PATH
195
+ print_info "Checking PATH..."
196
+ echo "Current PATH: $PATH"
197
+
198
+ # Ensure npm user-local directory is in PATH
199
+ if [[ ":$PATH:" != *":$HOME/.npm-global/bin:"* ]]; then
200
+ print_info "Adding ~/.npm-global/bin to PATH"
201
+ export PATH="$HOME/.npm-global/bin:$PATH"
202
+ else
203
+ print_info "~/.npm-global/bin already in PATH"
204
+ fi
205
+
206
+ # Debug: Check if armada-watch-agent exists
207
+ print_info "Searching for armada-watch-agent..."
208
+ AGENT_LOCATION=$(which armada-watch-agent 2>/dev/null || echo "not found")
209
+ echo "Agent location: $AGENT_LOCATION"
210
+
211
+ # Check if agent is installed
212
+ if [ "$AGENT_LOCATION" != "not found" ]; then
213
+ print_info "Checking agent version..."
214
+ AGENT_VERSION=$(armada-watch-agent --version 2>/dev/null || echo "unknown")
215
+ print_success "Agent found: $AGENT_VERSION"
216
+ else
217
+ print_error "Agent is not installed!"
218
+ echo ""
219
+ print_info "Please install the agent first using:"
220
+ echo ""
221
+ echo " # Option 1: User-local install (recommended)"
222
+ echo " mkdir -p ~/.npm-global"
223
+ echo " npm config set prefix '~/.npm-global'"
224
+ echo " export PATH=\"\$HOME/.npm-global/bin:\$PATH\""
225
+ echo " npm install -g @gazzehamine/armada-watch-agent@latest"
226
+ echo ""
227
+ echo " # Option 2: System-wide install"
228
+ echo " sudo npm install -g @gazzehamine/armada-watch-agent@latest"
229
+ echo ""
230
+ print_info "Then run this script again."
231
+ exit 1
232
+ fi
233
+
234
+ ################################################################################
235
+ # Step 4: Configuration
236
+ ################################################################################
237
+
238
+ print_header "⚙️ Step 4: Agent Configuration"
239
+
240
+ # Create agent directory
241
+ AGENT_DIR="$HOME/armada-watch-agent"
242
+ mkdir -p "$AGENT_DIR"
243
+ cd "$AGENT_DIR"
244
+
245
+ print_info "Configuration will be saved to: $AGENT_DIR/.env"
246
+ echo ""
247
+
248
+ # Prompt for SERVER_URL
249
+ read -p "Enter SERVER_URL (e.g., http://your-server:4000): " SERVER_URL
250
+ while [ -z "$SERVER_URL" ]; do
251
+ print_warning "SERVER_URL is required"
252
+ read -p "Enter SERVER_URL: " SERVER_URL
253
+ done
254
+
255
+ # Prompt for INSTANCE_NAME
256
+ if [ -n "$AUTO_HOSTNAME" ]; then
257
+ read -p "Enter INSTANCE_NAME [default: $AUTO_HOSTNAME]: " INSTANCE_NAME
258
+ INSTANCE_NAME=${INSTANCE_NAME:-$AUTO_HOSTNAME}
259
+ else
260
+ read -p "Enter INSTANCE_NAME (e.g., Production Web Server): " INSTANCE_NAME
261
+ while [ -z "$INSTANCE_NAME" ]; do
262
+ print_warning "INSTANCE_NAME is required"
263
+ read -p "Enter INSTANCE_NAME: " INSTANCE_NAME
264
+ done
265
+ fi
266
+
267
+ # Prompt for REGION
268
+ if [ -n "$AUTO_REGION" ]; then
269
+ read -p "Enter REGION [default: $AUTO_REGION]: " REGION
270
+ REGION=${REGION:-$AUTO_REGION}
271
+ else
272
+ read -p "Enter REGION (e.g., us-east-1): " REGION
273
+ while [ -z "$REGION" ]; do
274
+ print_warning "REGION is required"
275
+ read -p "Enter REGION: " REGION
276
+ done
277
+ fi
278
+
279
+ # Prompt for INSTANCE_ID
280
+ if [ -n "$AUTO_INSTANCE_ID" ]; then
281
+ read -p "Enter INSTANCE_ID [default: $AUTO_INSTANCE_ID]: " INSTANCE_ID
282
+ INSTANCE_ID=${INSTANCE_ID:-$AUTO_INSTANCE_ID}
283
+ else
284
+ read -p "Enter INSTANCE_ID (e.g., i-0abc123def): " INSTANCE_ID
285
+ while [ -z "$INSTANCE_ID" ]
286
+ do
287
+ print_warning "INSTANCE_ID is required"
288
+ read -p "Enter INSTANCE_ID: " INSTANCE_ID
289
+ done
290
+ fi
291
+
292
+ # Prompt for COLLECTION_INTERVAL
293
+ read -p "Enter COLLECTION_INTERVAL in seconds [default: 10]: " COLLECTION_INTERVAL
294
+ COLLECTION_INTERVAL=${COLLECTION_INTERVAL:-10}
295
+
296
+ # Create .env file
297
+ cat > .env <<EOF
298
+ SERVER_URL=$SERVER_URL
299
+ INSTANCE_NAME=$INSTANCE_NAME
300
+ REGION=$REGION
301
+ INSTANCE_ID=$INSTANCE_ID
302
+ COLLECTION_INTERVAL=$COLLECTION_INTERVAL
303
+ EOF
304
+
305
+ print_success "Configuration saved to .env"
306
+
307
+ # Display configuration
308
+ echo ""
309
+ print_info "Configuration Summary:"
310
+ echo " SERVER_URL: $SERVER_URL"
311
+ echo " INSTANCE_NAME: $INSTANCE_NAME"
312
+ echo " REGION: $REGION"
313
+ echo " INSTANCE_ID: $INSTANCE_ID"
314
+ echo " COLLECTION_INTERVAL: ${COLLECTION_INTERVAL}s"
315
+ echo ""
316
+
317
+ ################################################################################
318
+ # Step 5: PM2 Installation and Setup
319
+ ################################################################################
320
+
321
+ print_header "🚀 Step 5: PM2 Process Manager"
322
+
323
+ # Check if PM2 is installed
324
+ if command -v pm2 &> /dev/null; then
325
+ print_success "PM2 is already installed: $(pm2 -v)"
326
+ else
327
+ print_info "Installing PM2..."
328
+ if sudo npm install -g pm2 --silent; then
329
+ print_success "PM2 installed successfully: $(pm2 -v)"
330
+ else
331
+ print_error "PM2 installation failed"
332
+ exit 1
333
+ fi
334
+ fi
335
+
336
+ # Check if agent is already running in PM2
337
+ if pm2 list | grep -q "armada-watch"; then
338
+ print_warning "Agent is already running in PM2"
339
+ read -p "Do you want to restart it? (y/n): " RESTART_PM2
340
+ if [[ "$RESTART_PM2" =~ ^[Yy]$ ]]; then
341
+ pm2 delete armada-watch 2>/dev/null || true
342
+ pm2 start armada-watch-agent --name armada-watch
343
+ print_success "Agent restarted in PM2"
344
+ fi
345
+ else
346
+ print_info "Starting agent with PM2..."
347
+ cd "$AGENT_DIR"
348
+ if pm2 start armada-watch-agent --name armada-watch; then
349
+ print_success "Agent started successfully"
350
+ else
351
+ print_error "Failed to start agent"
352
+ exit 1
353
+ fi
354
+ fi
355
+
356
+ # Save PM2 process list
357
+ pm2 save >/dev/null 2>&1
358
+ print_success "PM2 process list saved"
359
+
360
+ # Generate PM2 startup script
361
+ echo ""
362
+ print_info "To enable PM2 auto-start on system boot, run this command:"
363
+ echo ""
364
+ pm2 startup 2>/dev/null | grep "sudo" || true
365
+ echo ""
366
+ print_warning "Copy and run the command above to enable auto-start"
367
+ echo ""
368
+
369
+ # Show PM2 status
370
+ print_info "Current PM2 Status:"
371
+ pm2 list
372
+
373
+ ################################################################################
374
+ # Step 6: Optional Components
375
+ ################################################################################
376
+
377
+ print_header "🔧 Step 6: Optional Components"
378
+
379
+ read -p "Do you want to configure optional components (Nginx, SSL, Security)? (y/n): " CONFIGURE_OPTIONAL
380
+ echo ""
381
+
382
+ if [[ "$CONFIGURE_OPTIONAL" =~ ^[Yy]$ ]]; then
383
+
384
+ # Nginx Monitoring
385
+ print_info "Checking for Nginx..."
386
+ if command -v nginx &> /dev/null; then
387
+ print_success "Nginx detected"
388
+
389
+ # Check if stub_status is configured
390
+ if curl -s http://127.0.0.1/nginx_status >/dev/null 2>&1; then
391
+ print_success "Nginx stub_status is already configured"
392
+ else
393
+ print_warning "Nginx stub_status is not configured"
394
+ read -p "Do you want to automatically configure Nginx monitoring? (y/n): " CONFIGURE_NGINX
395
+
396
+ if [[ "$CONFIGURE_NGINX" =~ ^[Yy]$ ]]; then
397
+ print_info "Configuring Nginx stub_status..."
398
+
399
+ # Backup the config
400
+ sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/default.backup.$(date +%Y%m%d%H%M%S)
401
+
402
+ # Add stub_status location block
403
+ sudo sed -i '/server {/a\ location /nginx_status {\n stub_status on;\n access_log off;\n allow 127.0.0.1;\n deny all;\n }\n' /etc/nginx/sites-available/default
404
+
405
+ # Test configuration
406
+ if sudo nginx -t >/dev/null 2>&1; then
407
+ sudo systemctl reload nginx
408
+ sleep 2
409
+
410
+ # Verify it works
411
+ if curl -s http://127.0.0.1/nginx_status >/dev/null 2>&1; then
412
+ print_success "Nginx stub_status configured successfully"
413
+ else
414
+ print_warning "Configuration added but endpoint not responding"
415
+ fi
416
+ else
417
+ print_error "Nginx configuration test failed, reverting changes"
418
+ sudo mv /etc/nginx/sites-available/default.backup.* /etc/nginx/sites-available/default 2>/dev/null || true
419
+ fi
420
+ else
421
+ print_info "Skipping Nginx configuration - you can add it manually later"
422
+ fi
423
+ fi
424
+ else
425
+ print_info "Nginx not detected - skipping"
426
+ fi
427
+
428
+ echo ""
429
+
430
+ # SSL Certificate Access
431
+ print_info "Checking for SSL certificates..."
432
+ if [ -d "/etc/letsencrypt/live" ]; then
433
+ print_success "Certbot/Let's Encrypt detected"
434
+
435
+ # Grant read access to adm group (PM2 preserves this group)
436
+ print_info "Granting SSL certificate access to adm group..."
437
+ sudo chgrp -R adm /etc/letsencrypt
438
+ sudo chmod -R g+rX /etc/letsencrypt
439
+ print_success "SSL certificate access configured for adm group"
440
+ print_info "The agent will be able to monitor SSL certificates"
441
+
442
+ elif [ -d "/etc/letsencrypt" ]; then
443
+ print_warning "Certbot directory exists but no certificates found"
444
+ else
445
+ print_info "Certbot not detected - skipping SSL monitoring"
446
+ fi
447
+
448
+ echo ""
449
+
450
+ # Security Monitoring
451
+ print_info "Configuring security monitoring..."
452
+
453
+ # Add user to adm group for log access
454
+ if ! groups $CURRENT_USER | grep -q "\\badm\\b"; then
455
+ print_info "Adding $CURRENT_USER to adm group..."
456
+ sudo usermod -aG adm $CURRENT_USER
457
+ print_success "User added to adm group"
458
+ else
459
+ print_success "User already in adm group"
460
+ fi
461
+
462
+ # Restart PM2 to apply new groups
463
+ print_info "Restarting PM2 to apply new group memberships..."
464
+ pm2 restart armada-watch >/dev/null 2>&1
465
+ print_success "PM2 restarted"
466
+
467
+ echo ""
468
+
469
+ # SSM Agent Check
470
+ print_info "Checking SSM Agent..."
471
+ if [ "$OS" == "ubuntu" ]; then
472
+ # Ubuntu uses snap
473
+ if snap list amazon-ssm-agent >/dev/null 2>&1; then
474
+ SSM_STATUS=$(sudo snap services amazon-ssm-agent | grep amazon-ssm-agent | awk '{print $3}')
475
+ if [ "$SSM_STATUS" == "active" ]; then
476
+ print_success "SSM Agent is running (snap)"
477
+ else
478
+ print_warning "SSM Agent is not active"
479
+ sudo snap restart amazon-ssm-agent 2>/dev/null || true
480
+ fi
481
+ else
482
+ print_info "SSM Agent not installed (snap)"
483
+ fi
484
+ elif [ "$OS" == "amzn" ]; then
485
+ # Amazon Linux uses systemd
486
+ if systemctl is-active --quiet amazon-ssm-agent; then
487
+ print_success "SSM Agent is running (systemd)"
488
+ else
489
+ print_warning "SSM Agent is not active"
490
+ sudo systemctl restart amazon-ssm-agent 2>/dev/null || true
491
+ fi
492
+ fi
493
+
494
+ else
495
+ print_info "Skipping optional components"
496
+ fi
497
+
498
+ ################################################################################
499
+ # Step 7: Final Verification
500
+ ################################################################################
501
+
502
+ print_header "✅ Step 7: Final Verification"
503
+
504
+ # Test server connectivity
505
+ print_info "Testing connection to monitoring server..."
506
+ if curl -s --max-time 5 "$SERVER_URL/health" >/dev/null 2>&1; then
507
+ print_success "Successfully connected to monitoring server"
508
+ else
509
+ print_warning "Could not connect to monitoring server"
510
+ print_info "Make sure the server URL is correct and accessible"
511
+ fi
512
+
513
+ # Show PM2 status
514
+ echo ""
515
+ print_info "Agent Status:"
516
+ pm2 show armada-watch 2>/dev/null || pm2 list
517
+
518
+ # Show recent logs
519
+ echo ""
520
+ print_info "Recent Agent Logs:"
521
+ pm2 logs armada-watch --lines 10 --nostream 2>/dev/null || echo "No logs available yet"
522
+
523
+ ################################################################################
524
+ # Installation Complete
525
+ ################################################################################
526
+
527
+ echo ""
528
+ print_header "🎉 Installation Complete!"
529
+
530
+ echo ""
531
+ print_success "Armada Watch Agent is now installed and running!"
532
+ echo ""
533
+ print_info "Useful Commands:"
534
+ echo " • View status: pm2 list"
535
+ echo " • View logs: pm2 logs armada-watch"
536
+ echo " • Restart agent: pm2 restart armada-watch"
537
+ echo " • Stop agent: pm2 stop armada-watch"
538
+ echo ""
539
+ print_info "Configuration file: $AGENT_DIR/.env"
540
+ echo ""
541
+
542
+ # Show SSL restart warning if SSL was configured
543
+ if [ -d "/etc/letsencrypt/live" ] && [[ "$CONFIGURE_OPTIONAL" =~ ^[Yy]$ ]]; then
544
+ print_warning "⚠️ IMPORTANT: SSL Certificate Monitoring"
545
+ echo ""
546
+ echo " To enable SSL monitoring, you must restart the PM2 daemon:"
547
+ echo ""
548
+ echo " pm2 kill"
549
+ echo " cd ~/armada-watch-agent"
550
+ echo " pm2 start armada-watch-agent --name armada-watch"
551
+ echo " pm2 save"
552
+ echo ""
553
+ print_info " This allows PM2 to pick up the new SSL permissions."
554
+ echo ""
555
+ fi
556
+
557
+ print_info "Check your Armada Watch dashboard to verify the instance appears online."
558
+ echo ""
559
+
560
+ exit 0