Network Connectivity Test - Container App Job

📋 Overview

This solution is an Azure Container App Job that tests network connectivity to a remote server using an SSL/TLS connection. It validates network connectivity at the Azure Container Apps infrastructure level.

🎯 Objective

The application tests different layers of network connectivity:

🚀 How to Get Started

Create a New Container App Job

Create a new Container App Job within the same Container App environment for isolated testing.

Choose Your Deployment Style

You can either:

Option 1: Build from Source

Option 2: Pull from Docker Hub

# Pull the image
docker pull yass101010/containerappjob_networktester:latest

# Or use directly in Azure Container Apps Job
az containerapp job create \
  --name network-connectivity-test \
  --resource-group <your-resource-group> \
  --environment <your-environment> \
  --trigger-type Manual \
  --image docker.io/yass101010/containerappjob_networktester:latest \
  --cpu 0.25 --memory 0.5Gi \
  --env-vars SERVER_FQDN=<server-to-test> SERVER_PORT=<port>

🏗️ Solution

┌─────────────────────────────────────────┐
│   Azure Container Apps Environment      │
│                                         │
│  ┌──────────────────────────────────┐  │
│  │  Container App Job               │  │
│  │  (Trigger: Manual)               │  │
│  │                                  │  │
│  │  ┌────────────────────────────┐ │  │
│  │  │ .NET 8 Console App         │ │  │
│  │  │ - Test DNS                 │ │  │
│  │  │ - Test TCP                 │ │  │
│  │  │ - Test SSL/TLS             │ │  │
│  │  │ - Test Server Response     │ │  │
│  │  └────────────────────────────┘ │  │
│  └──────────────────────────────────┘  │
│                 │                       │
└─────────────────┼───────────────────────┘
                  │
                  ▼
        ┌─────────────────────┐
        │  Log Analytics      │
        │  Workspace          │
        └─────────────────────┘

📦 Project Components

1. Program.cs - Main Application

The C# (.NET 8) application performs the following connectivity tests:

Step 1: DNS Resolution

var addresses = await System.Net.Dns.GetHostAddressesAsync(server);

Step 2: TCP Connection

tcpClient.ConnectAsync(server, port);

Step 3: SSL/TLS Handshake

sslStream.AuthenticateAsClientAsync(server);

Step 4: Server Response Reading

var bytesRead = await sslStream.ReadAsync(buffer, 0, buffer.Length);

2. Environment Variables

The application uses two configurable environment variables:

Variable Description Default Value
SERVER_FQDN Server FQDN to test imap.gmail.com
SERVER_PORT Server port 993

📊 Verifying Logs in Log Analytics

KQL Queries in Log Analytics

1. View all logs from a recent execution

ContainerAppConsoleLogs_CL
| where ContainerAppName_s == "container-app-job"
| where TimeGenerated > ago(1h)
| order by TimeGenerated desc
| project TimeGenerated, Log_s

2. Search for errors or failures

ContainerAppConsoleLogs_CL
| where ContainerAppName_s == "container-app-job"
| where Log_s contains "❌" or Log_s contains "failed" or Log_s contains "Error"
| order by TimeGenerated desc
| project TimeGenerated, Log_s

3. Extract successful test results

ContainerAppConsoleLogs_CL
| where ContainerAppName_s == "container-app-job"
| where Log_s contains "✅"
| order by TimeGenerated desc
| project TimeGenerated, Log_s

4. View configuration used

ContainerAppConsoleLogs_CL
| where ContainerAppName_s == "container-app-job"
| where Log_s contains "Server FQDN:" or Log_s contains "Port:"
| order by TimeGenerated desc
| project TimeGenerated, Log_s

5. Analyze response times

ContainerAppConsoleLogs_CL
| where ContainerAppName_s == "container-app-job"
| where Log_s contains "ms)"
| order by TimeGenerated desc
| project TimeGenerated, Log_s
| extend Milliseconds = extract(@"(\d+)ms\)", 1, Log_s)

6. Track a specific execution by ID

let executionId = "container-app-job-<execution-id>";
ContainerAppConsoleLogs_CL
| where ContainerGroupName_s contains executionId
| order by TimeGenerated asc
| project TimeGenerated, Log_s

7. Success/failure statistics

ContainerAppConsoleLogs_CL
| where ContainerAppName_s == "container-app-job"
| where TimeGenerated > ago(7d)
| where Log_s contains "Test Summary"
| summarize 
    TotalRuns = count(),
    SuccessfulRuns = countif(Log_s contains "✅ All connectivity tests passed"),
    FailedRuns = countif(Log_s contains "failed")
| extend SuccessRate = (SuccessfulRuns * 100.0) / TotalRuns

8. View SSL/TLS details

ContainerAppConsoleLogs_CL
| where ContainerAppName_s == "container-app-job"
| where Log_s contains "SSL Protocol:" 
    or Log_s contains "Cipher Algorithm:" 
    or Log_s contains "Certificate"
| order by TimeGenerated desc
| project TimeGenerated, Log_s

Access via Azure Portal

  1. Navigate to Log Analytics Workspace

    • Azure Portal → Log Analytics workspaces
    • Select the workspace associated with your Container Apps Environment
  2. Open the query editor

    • Left menu → Logs
    • Close the suggestions window if necessary
  3. Execute a KQL query

    • Copy one of the queries above
    • Click "Run"
  4. Analyze results

    • View results in the table
    • Export to CSV if needed
    • Pin to dashboard for monitoring

📈 Example of Successful Output

=== Network Connectivity Test ===
Starting test at: 2025-12-12 10:30:00 UTC

Configuration:
  Server FQDN: imap.gmail.com
  Port: 993
  Timeout: 30s

📡 Testing connectivity to: imap.gmail.com:993
⏱️  Timeout: 30 seconds

Step 1: DNS Resolution
✅ DNS resolution successful (45ms)
   Resolved IP addresses:
   - 142.250.185.109 (InterNetwork)
   - 2a00:1450:4007:80d::6d (InterNetworkV6)

Step 2: TCP Connection
✅ TCP connection established (23ms)
   Local endpoint: 10.0.0.4:54321
   Remote endpoint: 142.250.185.109:993
   Connected: True

Step 3: SSL/TLS Handshake
   📜 Certificate validation callback triggered
      Subject: CN=imap.gmail.com
      Issuer: CN=GTS CA 1C3, O=Google Trust Services LLC, C=US
      Valid from: 11/20/2025 8:00:00 AM
      Valid to: 2/12/2026 8:00:00 AM
      SSL Policy Errors: None
✅ SSL/TLS handshake successful (87ms)
   SSL Protocol: Tls13
   Cipher Algorithm: Aes256 (256 bits)
   Hash Algorithm: Sha384 (384 bits)
   Key Exchange Algorithm: None (0 bits)
   Is Authenticated: True
   Is Encrypted: True
   Is Signed: True

Step 4: Reading IMAP Server Greeting
✅ Received IMAP greeting (12ms, 45 bytes)
   Response: * OK Gimap ready for requests from 10.0.0.4

=== Test Summary ===
✅ All connectivity tests passed!
   Server: imap.gmail.com:993
   Status: REACHABLE
   SSL/TLS: WORKING
   IMAP Protocol: RESPONDING

Test completed at: 2025-12-12 10:30:01 UTC
=== End of Test ===

Version: 1.0
Last updated: December 12, 2025