[Xymon] Creating C# Script for Custom Alarm

Brandon Dale BDale at kitchengroup.com.au
Thu Apr 21 03:24:04 CEST 2016


I don't have any tests written in C# however I do have some written in PowerShell, I can think of a few ways you could do this:


1.       Convert xymonsend.ps1 from http://sourceforge.net/p/xymon/code/HEAD/tree/sandbox/WinPSClient/xymonsend.ps1 into C# and use that in your script to send that data to xymon

2.       I think you can execute C# from within PowerShell so you could wrap it in a PowerShell script using xymonsend and send it that way.

3.       I don't use BBwin anymore but maybe you can get the bbwin externals function to run your code and send the results to your xymon server?

This is an example of how you can use it from the mailing list a while ago: http://lists.xymon.com/pipermail/xymon/2015-April/041507.html here is another example of a script I use  to check for pending restarts on a few servers http://pastebin.com/n6h4M4pq that's in PowerShell running as a scheduled task in windows, you could do the same kind of thing using C# I'm guessing.


Regards,


Brandon



From: Xymon [mailto:xymon-bounces at xymon.com] On Behalf Of Foster Patch
Sent: Thursday, 21 April 2016 3:20 AM
To: xymon at xymon.com
Subject: [Xymon] Creating C# Script for Custom Alarm

Hi,

My company used to use a VB Script to monitor ASP.NET Requests, but updating to .NET 4.5 will mess up your perf counters, which results in all data being displayed as 0. I have a C# script I want to use to use on servers by putting it in the ext directory of a local machine. I was wondering if maybe anyone had any resources I could use to see how to integrate my script into Xymon. Or maybe if someone has an example C# script that has been integrated with xymon. Thank you


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;

namespace PerfCounterQuery
{
    class Program
    {
        static void Main(string[] args)
        {
            IntPtr userHandle = new IntPtr(0);
            string hostName = ".";
            string categoryName = "ASP.NET Applications";
            string instanceName = "__Total__";
            string[] counterNames = { "Requests Executing" , "Request Wait Time" , "Requests In Application Queue" , "Request Execution Time" };
            PerformanceCounterCategory cat = new PerformanceCounterCategory(categoryName, hostName);
            List<PerformanceCounter> counters = new List<PerformanceCounter>();
            foreach (string counterName in counterNames)
            {
                if (!PerformanceCounterCategory.CounterExists(counterName, categoryName, hostName))
                {
                    Console.WriteLine("perf counter \"" + counterName + "\" does not exist");
                    return;
                }
                counters.Add(new PerformanceCounter(categoryName, counterName, instanceName, hostName));
            }
            foreach (PerformanceCounter counter in counters)
                Console.WriteLine(counter.CategoryName + " - " + counter.CounterName + " : " + counter.NextValue());
            Console.ReadLine();
        }
    }
}


Foster Patch
Web Server Technician
AccuWeather



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.xymon.com/pipermail/xymon/attachments/20160421/32dd47ab/attachment.html>


More information about the Xymon mailing list