I wrote a simple C# console application that goes into SQL and returns an integer value and message followed by a return-code. The integer value is a percentage ranging from 0 to 100%. 100% is green, if it drops below 80% I have a warning.
When I run the exe the code in command line it generates the right values. However when I add the custom EXE sensor in PRTG I have a constant value of 0 and the message is 78620d7b-087c-443f-bea3-3191c7adb254
Should be... 100:ok or 67:WARNING
My main method calls the a method that prints an integer and text to the console window. Then comes back with an exit code.
class Program { static int Main(string[] args) { int ret = HitRatio.buffHitPer(); return ret; } }
Method which grabs data from the SQL server and prints to the console window.
private static int CreateCommand(string queryString, string connectionString) { int ret=1; SqlConnection connection = new SqlConnection(connectionString); try { connection.Open(); SqlCommand command = new SqlCommand(queryString, connection); SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) //PRTG is expecting a return in the format of int64:string { if (Convert.ToInt32(reader[0]) >= 79) { Console.WriteLine(Convert.ToInt16(reader[0]) + ":WARNING"); ret = 1; } else if (Convert.ToInt32(reader[0]) < 79) { Console.WriteLine(Convert.ToInt16(reader[0]) + ":ok"); ret = 0; } } } catch(Exception e) { Console.WriteLine(String.Format("0:{0}", Convert.ToString(e))); ret = 2; } finally { connection.Close(); } return ret; }
Add comment