Beispiel #1
0
        private static void RunScriptAndEmail(
            decimal currentState,
            decimal limit,
            ThresholdType limitType,
            string scriptPath,
            string watcherName,
            bool isWarning)
        {
            //NOTE: isWarning == false means that notification is about watcher back within limits
            string[] scriptParts = scriptPath.Split(new[] { ' ' }, 2);

            ProcessStartInfo scriptInfo = new ProcessStartInfo(
                scriptParts[0],
                scriptParts[1]
                .Replace("%value%", currentState.ToString("####.#").Replace(",", "."))
                .Replace("%limit%", limit.ToString("####.#").Replace(",", "."))
                .Replace("%type%", limitType.ToString().ToLower())
                );

            try
            {
                Process.Start(scriptInfo);
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Script start failed. Message: {ex.Message}");
            }

            if (_emailNotifier.IsConfigured)
            {
                try
                {
                    _emailNotifier.SendMail(
                        watcherName,
                        currentState,
                        limit,
                        isWarning
                                                        ? EventType.Warning
                                                        : EventType.Ok);
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"Email send failed. Message: {ex.Message}");
                }
            }
        }