• Facebook
  • Twitter
  • Youtube
  • LinedIn
  • RSS
  • Docs
  • Comparisons
  • Blogs
  • Download
  • Contact Us
Download
Show / Hide Table of Contents

Get NCache Alerts on MS Teams

NCache events can be sent to Microsoft Teams so administrators can receive important cache notifications directly in a Teams channel. This helps teams stay informed about cache failures, node connectivity issues, service interruptions, and other important runtime events without continuously monitoring dashboards or logs. This page guides you through configuring Microsoft Teams alerts for NCache on both Windows and Linux environments.

Prerequisites

Before you begin, ensure that:

  • NCache is installed and configured.
  • You have a Microsoft Teams work or organizational account.
  • You have permission to create Teams workflows.
  • A Team and Channel already exist in Microsoft Teams.
  • The server has outbound internet access to communicate with Microsoft Teams workflows.

Step 1: Create a Microsoft Teams Workflow

Microsoft Teams workflows can generate webhook endpoints that allow external applications or scripts to send notifications directly to a Teams channel. In this setup, the webhook endpoint is used by NCache alert scripts to post Windows or Linux event notifications to Microsoft Teams. For more information, see Create an Incoming Webhook Microsoft Docs.

To create a Microsoft Teams workflow:

  • Open Microsoft Teams.

  • Navigate to the Team and Channel where you want to receive NCache alerts. For example, NCache-Test3 > General.

  • Click the three dots (...) in the top-right corner of the channel and select Workflows.

    Three dots

  • In the Workflows window, search for and select the Send webhook alerts to a channel template.

    Send webhook alerts to a channel

  • Choose the Team and Channel where the alerts should be posted and click Save.

    Save webhooks

  • Once the workflow is created, Microsoft Teams generates a webhook URL.

  • Click Copy webhook link and save the generated URL securely.

    Webhook URL

Important

Treat the webhook URL like a password. Anyone with access to this URL can send messages to your Teams channel.

The generated webhook URL is used to send alert notifications to the selected Microsoft Teams channel.

Step 2: Decide What Alerts You Want from NCache

NCache writes operational and runtime events that can be used to trigger Microsoft Teams alerts. On Windows, these events are available in the Windows Application log. On Linux, similar event information is available in the NCache event log file.

Common alerts include:

  • Cache started or stopped
  • Cache node joined or left
  • Service failures
  • Network or connectivity issues
  • Cache synchronization failures
  • Critical runtime exceptions

This page uses the CacheStart event with Event ID 1000 and source NCache as an example for both Windows and Linux.

Important

You can learn more about NCache Event IDs from the NCache Administrators Guide.

Step 3: Create a Teams Alert Script

  • Windows
  • Linux

In this step, you will create a PowerShell script that reads the latest NCache event from the Windows Application log and sends it to the Microsoft Teams webhook URL created earlier. This script acts as the bridge between Windows Event Log and Microsoft Teams.

  • Create a PowerShell script, for example at C:\Scripts\Send-NCacheEventToTeams.ps1, add the following content to it, and replace PASTE_YOUR_WEBHOOK_URL_HERE with the webhook URL generated by Microsoft Teams:
$webhookUrl = "PASTE_YOUR_WEBHOOK_URL_HERE"

$event = Get-WinEvent -MaxEvents 1 -FilterHashtable @{
    LogName      = 'Application'
    ProviderName = 'NCache'
}

$messageText = $event.Message
$cacheName = if ($messageText -match '"([^"]+)"') { $matches[1] }

$eventMessage = @"
Cache Name: $cacheName
Node: $env:COMPUTERNAME
Event: NCache Event (Event ID $($event.Id))
Time: $($event.TimeCreated)

Message:
$messageText
"@

$body = @{
    type = "message"
    attachments = @(
        @{
            contentType = "application/vnd.microsoft.card.adaptive"
            content = @{
                '$schema' = "http://adaptivecards.io/schemas/adaptive-card.json"
                type = "AdaptiveCard"
                version = "1.2"
                body = @(
                    @{
                        type = "TextBlock"
                        text = "NCache Event Alert"
                        weight = "Bolder"
                        size = "Large"
                    },
                    @{
                        type = "TextBlock"
                        text = $eventMessage
                        wrap = $true
                    }
                )
            }
        }
    )
} | ConvertTo-Json -Depth 10

Invoke-RestMethod `
    -Uri $webhookUrl `
    -Method Post `
    -Body $body `
    -ContentType "application/json"
Note

The ProviderName in the script can be changed depending on the event source you want to monitor. Common sources include:

  • NCache
  • NCacheSvc
  • NCache Bridge
Note

You can customize this script based on the event source, Event ID, severity level, or message details you want to send.

  • The above script reads the latest NCache event from the Windows Application log, extracts the cache name, node name, event ID, event time, and message, formats these details as a Microsoft Teams adaptive card, and sends the alert to the selected Teams channel through the webhook URL.

  • To verify the script, run the following command in PowerShell:

powershell -ExecutionPolicy Bypass -File "C:\Scripts\Send-NCacheEventToTeams.ps1"

After the script runs successfully, an alert message appears in the selected Microsoft Teams channel.

In this step, you will create a shell script that reads NCache Linux event logs and sends alert notifications to the Microsoft Teams webhook URL created earlier. This script acts as the bridge between NCache Linux event logs and Microsoft Teams.

  • Create a directory to store the alert script using the following command:
sudo mkdir -p /opt/ncache/scripts
  • Create and open the shell script file using the following command:
sudo nano /opt/ncache/scripts/send_ncache_teams_alert.sh
  • Copy the following script into the file. This example monitors NCache Event ID 1000, which corresponds to cache startup events. Replace PASTE_TEAMS_WEBHOOK_URL_HERE with the webhook URL generated by Microsoft Teams:
#!/bin/bash

WEBHOOK="PASTE_TEAMS_WEBHOOK_URL_HERE"
LOG_FILE="/opt/ncache/log-files/eventlogs/eventlogs.txt"
STATE_FILE="/tmp/ncache_last_teams_event.txt"

EVENT=$(grep -E 'NCache.*1000.*"[^"]+"\s+started successfully\.' "$LOG_FILE" | tail -n 1)

if [ -n "$EVENT" ]; then

    LAST_EVENT=$(cat "$STATE_FILE" 2>/dev/null)

    if [ "$EVENT" != "$LAST_EVENT" ]; then

        echo "$EVENT" > "$STATE_FILE"

        CACHE_NAME=$(echo "$EVENT" | grep -oP '"\K[^"]+(?=")')
        EVENT_TIME=$(echo "$EVENT" | awk '{print $1" "$2}' | sed 's/,$//')
        EVENT_MESSAGE=$(echo "$EVENT" | sed -E 's/^.*NCache[[:space:]]+1000[[:space:]]+[A-Za-z]+[[:space:]]+//')

        MESSAGE="Cache Name: $CACHE_NAME
Node: $(hostname)
Event: Cache Started (Event ID 1000)
Time: $EVENT_TIME

Message:
$EVENT_MESSAGE"

        PAYLOAD=$(python3 - <<EOF
import json
message = """$MESSAGE"""
payload = {
    "type": "message",
    "attachments": [
        {
            "contentType": "application/vnd.microsoft.card.adaptive",
            "content": {
                "\$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
                "type": "AdaptiveCard",
                "version": "1.2",
                "body": [
                    {
                        "type": "TextBlock",
                        "text": "NCache Event Alert",
                        "weight": "Bolder",
                        "size": "Large"
                    },
                    {
                        "type": "TextBlock",
                        "text": message,
                        "wrap": True
                    }
                ]
            }
        }
    ]
}
print(json.dumps(payload))
EOF
)

        curl -s -X POST \
            -H "Content-Type: application/json" \
            --data "$PAYLOAD" \
            "$WEBHOOK"

    fi
fi
Note

You can customize the script to monitor different event IDs, cache events, or message patterns depending on the alerts you want to receive.

  • The above script reads the latest matching NCache Linux event log entry, extracts the required event details, formats them as a Microsoft Teams adaptive card, sends the alert through the webhook URL, and prevents duplicate alerts for the same event.

  • Install the required dependencies using the following command:

sudo apt update
sudo apt install curl python3 -y
  • Make the script executable using the following command:
sudo chmod +x /opt/ncache/scripts/send_ncache_teams_alert.sh
  • Verify the script manually using the following command:
sudo /opt/ncache/scripts/send_ncache_teams_alert.sh
  • After the script runs successfully, an alert message appears in the selected Microsoft Teams channel.

Step 4: Set Up A Trigger

  • Windows
  • Linux
  • Press Windows + R, type taskschd.msc, and press Enter.

Image showing how to access the taskschd.msc application

  • In Task Scheduler, click Create Task.
Warning

Do not use Create Basic Task, as it does not support advanced event filtering properly.

Image showing how to create a task using Task Scheduler

  • In the General tab, specify the task name, for example, NCache Teams Alerts. Then enable Run whether user is logged on or not and Run with highest privileges.

Image showing the General tab while creating a task

  • In the Triggers tab, click New.

Image showing the Triggers tab while creating a task

  • In the New Trigger window, configure the event trigger:
    • Set Begin the task to On an event.
    • Set Log to Application.
    • Set Source to NCache.
    • Enter the required Event ID, if you want to trigger alerts only for a specific event.
    • Click OK.

Image showing the process for creating a task trigger.

  • In the Actions tab, click New.

Image showing the Actions tab while creating a task

  • In the New Action window:
    • Set Action to Start a program.
    • Set Program/script to powershell.exe.
    • Add the following arguments to run the Teams alert script:
-ExecutionPolicy Bypass -File "C:\Scripts\Send-NCacheEventToTeams.ps1"

Image showing the process for creating the task action

Note

In the Conditions tab, you can enable Start only if on AC power, which is recommended for servers.

  • In the Settings tab, enable Allow task to be run on demand and Run task as soon as possible after a scheduled start is missed.

Image showing the Settings tab while creating a task

  • Click OK to save the task.

  • To verify that the task has been created successfully, run the following PowerShell command:

Get-ScheduledTask -TaskName "NCache Teams Alerts"

Image showing the PowerShell verification after creating a task

Once the selected NCache event occurs, Windows Task Scheduler runs the PowerShell script and sends the alert to the configured Microsoft Teams channel.

On Linux, systemd can monitor the NCache Linux event log file and automatically execute the Teams alert script whenever the log file changes.

  • Create the following systemd service file:
sudo nano /etc/systemd/system/ncache-teams-alert.service
  • Add the following content:
[Unit]
Description=NCache Teams Alert Service

[Service]
Type=oneshot
ExecStart=/opt/ncache/scripts/send_ncache_teams_alert.sh
  • Create the following systemd path monitoring file:
sudo nano /etc/systemd/system/ncache-teams-alert.path
  • Add the following content:
[Unit]
Description=Watch NCache event log for Teams alerts

[Path]
PathModified=/opt/ncache/log-files/eventlogs/eventlogs.txt

[Install]
WantedBy=multi-user.target
  • Reload the systemd configuration:
sudo systemctl daemon-reload
  • Enable and start the path monitor:
sudo systemctl enable ncache-teams-alert.path
sudo systemctl start ncache-teams-alert.path
  • Verify that the path monitor is running successfully:
sudo systemctl status ncache-teams-alert.path

Once the selected NCache event occurs, systemd automatically runs the shell script and sends the alert to the configured Microsoft Teams channel.

Now, if the event you chose occurs you will get a message on MS Teams.

Image showing a teams message notifying of an event.

Note

Excessive event notifications can generate a large number of Teams alerts. In production environments, it is recommended to filter only important or critical events.

See Also

Monitor Caches
Logging
NCache Management Center

Contact Us

PHONE

+1 214-619-2601   (US)

+44 20 7993 8327   (UK)

 
EMAIL

sales@alachisoft.com

support@alachisoft.com

NCache
  • Edition Comparison
  • NCache Architecture
  • Benchmarks
Download
Pricing
Try Playground

Deployments
  • Cloud (SaaS & Software)
  • On-Premises
  • Kubernetes
  • Docker
Technical Use Cases
  • ASP.NET Sessions
  • ASP.NET Core Sessions
  • Pub/Sub Messaging
  • Real-Time ASP.NET SignalR
  • Internet of Things (IoT)
  • NoSQL Database
  • Stream Processing
  • Microservices
Resources
  • Magazine Articles
  • Third-Party Articles
  • Articles
  • Videos
  • Whitepapers
  • Shows
  • Talks
  • Blogs
  • Docs
Customer Case Studies
  • Testimonials
  • Customers
Support
  • Schedule a Demo
  • Forum (Google Groups)
  • Tips
Company
  • Leadership
  • Partners
  • News
  • Events
  • Careers
Contact Us

  • EnglishChinese (Simplified)FrenchGermanItalianJapaneseKoreanPortugueseSpanish

  • Contact Us
  •  
  • Sitemap
  •  
  • Terms of Use
  •  
  • Privacy Policy
© Copyright Alachisoft 2002 - . All rights reserved. NCache is a registered trademark of Diyatech Corp.
Back to top