/* * Possible requests from M/Monit: * #define HOME "/" #define TEST "/_monit" #define ABOUT "/_about" #define PING "/_ping" #define GETID "/_getid" #define STATUS "/_status" #define STATUS2 "/_status2" #define RUN "/_runtime" #define VIEWLOG "/_viewlog" #define DOACTION "/_doaction" #define FAVICON "/favicon.ico" * */ internal void Start() { var server = new HttpServer(); server.EndPoint = new IPEndPoint(IPAddress.Parse(ConfigMgr.Config.HttpdBindIp), ConfigMgr.Config.HttpdPort); server.RequestReceived += (sender, eventArgs) => { string responseString = String.Empty; string reqUrl = eventArgs.Request.RawUrl; Logger.Log.Debug("Nhttpd.HttpServer: Received URL request to " + reqUrl); if (reqUrl.Equals("/_ping")) { // pong is the expected answer // see do_ping in cervlet.c responseString = "pong"; } else if (reqUrl.Equals("/_getid")) { responseString = UniqueWindowsId.GetOrCreateUniqueId(); } else if (reqUrl.Equals("/_status?format=xml")) { if (!CheckCredentials(eventArgs.Request.Headers)) { eventArgs.Response.StatusCode = 403; eventArgs.Response.Status = "Forbidden"; return; } eventArgs.Response.ContentType = "text/xml"; responseString = MonitWindowsAgent.Instance.GetStatusXmlData().SerializedString; } else { eventArgs.Response.StatusCode = 404; eventArgs.Response.Status = "Not Found"; } using (var writer = new StreamWriter(eventArgs.Response.OutputStream)) { writer.Write(responseString); } Logger.Log.Debug("Nhttpd.HttpServer: Responding with status " + eventArgs.Response.Status + ": " + responseString); }; server.Start(); }
public SerializedInfo GetStatusXmlData() { var data = new monit(); data.id = UniqueWindowsId.GetOrCreateUniqueId(); data.incarnation = SystemStats.ProcessRunningInSec(); data.server = MonitStatusGenericData.GetMonitServerData(); data.platform = MonitStatusGenericData.GetMonitPlatformData(); data.version = "5.6"; // TODO, decide how to use the correct version number here in the future var services = new List <monitService>(); services.AddRange(GetFilesystemServices()); // TODO, should depend on config / controlfile services.Add(GetSystemService()); // TODO, should depend on config / controlfile // data.service.Add(GetHostService()); // TODO, depends on config / controlfile.. data.services = services.ToArray(); var status = SerializeMgr.Serialize(data); return(status); }
public MonitWindowsAgent() { Run = new Run_T(); Run.id = UniqueWindowsId.GetOrCreateUniqueId(); Run.incarnation = SystemStats.ProcessRunningInSec(); Run.controlfile = "none"; //TODO Run.startdelay = 0; //TODO Run.polltime = 120; //TODO Run.Env = new myenvironment(); Run.Env.user = SystemStats.GetHostname(); Run.httpd = new Httpd_T(); Run.httpd.port = ConfigMgr.Config.Httpd.Port; Run.httpd.ssl = ConfigMgr.Config.Httpd.SSL; Run.httpd.address = ConfigMgr.Config.Httpd.BindIp; Run.httpd.credentials = new List <Auth_T>(); Run.httpd.credentials.Add(new Auth_T { uname = ConfigMgr.Config.Httpd.Username, passwd = ConfigMgr.Config.Httpd.Password }); Run.mmonits = new List <Mmonit_T>(); Run.mmonits.Add(new Mmonit_T { url = new URL_T { url = ConfigMgr.Config.MMonits[0].Url, //port = ConfigMgr.Config.MMonits[0].Port, password = ConfigMgr.Config.MMonits[0].Password, user = ConfigMgr.Config.MMonits[0].Username } }); servicelist = new List <Service_T>(); servicelist_conf = new List <Service_T>(); ConfigMgr.Config.Services.ForEach(sc => { var newS = ServiceHelper.CreateService(sc, sc.Name.ToLower()); if (newS == null) { Logger.Log.Error("Service could not be created!"); } else { if (sc is ProcessConfig) { ProcessHelper.AddProcess(newS); } else if (sc is FilesystemConfig) { FilesystemHelper.AddFilesystem(newS); } } }); servicegrouplist = new List <ServiceGroup_T>(); systeminfo = SystemInfoHelper.GetSystemInfo(); m_timer = new Timer(ConfigMgr.Config.Period); m_timer.Elapsed += DoPeriodicCheck; m_timer.AutoReset = true; m_mMonitClient = new Collector(); var service = ServiceHelper.GetSystemService(); Run.system = new List <Service_T>(); Run.system.Add(service); }