示例#1
0
        static void Main(string[] args)
        {
            try
            {
                string zabbixIp   = "10.120.50.10";
                int    zabbixPort = 10051;

                string key  = "MyTestKey";
                string host = "MyTestHost";


                ZabbixSender sender = new ZabbixSender(zabbixIp, zabbixPort);

                //This is when we send ourvalue "0" to zabbix
                var result = sender.Send(host, key, "0");

                Console.WriteLine("success : {0}, processed : {1}, failed : {2}, total : {3}, seconds: {4}",
                                  result.IsSuccess,
                                  result.ZabbixResultInfo.Processed,
                                  result.ZabbixResultInfo.Failed,
                                  result.ZabbixResultInfo.Total,
                                  result.ZabbixResultInfo.SpentSeconds);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                Console.ReadKey();
            }
        }
        public void Initialize()
        {
            try
            {
                try
                {
                    IniFile config = new IniFile(Zabbix_Config_Filename);

                    ServerIP = config.IniReadValue(string.Empty, "Server");
                    Host     = config.IniReadValue(string.Empty, "Hostname");
                    try
                    {
                        ServerPort = int.Parse(config.IniReadValue(string.Empty, "ServerPort"));
                    }
                    catch (Exception)
                    {
                        // ServerPort can be absent from the config file - Setting the default port
                        ServerPort = 10051;
                    }
                }
                catch (FileNotFoundException fe)
                {
                    Logger.Current.Error("ZabbixInitialize", "Couldn't find Zabbix Config File - Using default value instead", fe);
                    ServerIP   = "monitoring.com";
                    Host       = Environment.MachineName;
                    ServerPort = 10051;
                }
                catch (Exception e)
                {
                    Logger.Current.Error("ZabbixInitialize", "Couldn't initialize Zabbix configuration - Zabbix sending is disabled", e);
                }

                ComponentName = _config.ComponentName;

                ZabbixSender.StartProcess();

                Logger.Current.Info("Zabbix.Initialize", "Started Zabbix Monitoring", ComponentName, ServerIP, ServerPort, Host);
            }
            catch (Exception e)
            {
                Logger.Current.Error("Zabbix.Initialize", "Zabbix initialization failed", e);
            }
        }