mon_page.h 4.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #pragma once
  2. #include <library/cpp/monlib/service/service.h>
  3. #include <library/cpp/monlib/service/mon_service_http_request.h>
  4. #include <util/generic/string.h>
  5. #include <util/generic/ptr.h>
  6. namespace NMonitoring {
  7. static const char HTTPOKTEXT[] = "HTTP/1.1 200 Ok\r\nContent-Type: text/plain\r\nConnection: Close\r\n\r\n";
  8. static const char HTTPOKBIN[] = "HTTP/1.1 200 Ok\r\nContent-Type: application/octet-stream\r\nConnection: Close\r\n\r\n";
  9. static const char HTTPOKHTML[] = "HTTP/1.1 200 Ok\r\nContent-Type: text/html\r\nConnection: Close\r\n\r\n";
  10. static const char HTTPOKJSON[] = "HTTP/1.1 200 Ok\r\nContent-Type: application/json\r\nConnection: Close\r\n\r\n";
  11. static const char HTTPOKSPACK[] = "HTTP/1.1 200 Ok\r\nContent-Type: application/x-solomon-spack\r\nConnection: Close\r\n\r\n";
  12. static const char HTTPOKPROMETHEUS[] = "HTTP/1.1 200 Ok\r\nContent-Type: text/plain\r\nConnection: Close\r\n\r\n";
  13. static const char HTTPOKUNISTAT[] = "HTTP/1.1 200 Ok\r\nContent-Type: text/json\r\nConnection: Close\r\n\r\n";
  14. static const char HTTPOKJAVASCRIPT[] = "HTTP/1.1 200 Ok\r\nContent-Type: text/javascript\r\nConnection: Close\r\n\r\n";
  15. static const char HTTPOKCSS[] = "HTTP/1.1 200 Ok\r\nContent-Type: text/css\r\nConnection: Close\r\n\r\n";
  16. static const char HTTPNOCONTENT[] = "HTTP/1.1 204 No content\r\nConnection: Close\r\n\r\n";
  17. static const char HTTPNOTFOUND[] = "HTTP/1.1 404 Invalid URI\r\nConnection: Close\r\n\r\nInvalid URL\r\n";
  18. static const char HTTPUNAUTHORIZED[] = "HTTP/1.1 401 Unauthorized\r\nConnection: Close\r\n\r\nUnauthorized\r\n";
  19. static const char HTTPFORBIDDEN[] = "HTTP/1.1 403 Forbidden\r\nConnection: Close\r\n\r\nForbidden\r\n";
  20. static const char HTTPOKJAVASCRIPT_CACHED[] = "HTTP/1.1 200 Ok\r\nContent-Type: text/javascript\r\nCache-Control: public, max-age=31536000\r\nConnection: Close\r\n\r\n";
  21. static const char HTTPOKCSS_CACHED[] = "HTTP/1.1 200 Ok\r\nContent-Type: text/css\r\nCache-Control: public, max-age=31536000\r\nConnection: Close\r\n\r\n";
  22. // Fonts
  23. static const char HTTPOKFONTEOT[] = "HTTP/1.1 200 Ok\r\nContent-Type: application/vnd.ms-fontobject\r\nConnection: Close\r\n\r\n";
  24. static const char HTTPOKFONTTTF[] = "HTTP/1.1 200 Ok\r\nContent-Type: application/x-font-ttf\r\nConnection: Close\r\n\r\n";
  25. static const char HTTPOKFONTWOFF[] = "HTTP/1.1 200 Ok\r\nContent-Type: application/font-woff\r\nConnection: Close\r\n\r\n";
  26. static const char HTTPOKFONTWOFF2[] = "HTTP/1.1 200 Ok\r\nContent-Type: application/font-woff2\r\nConnection: Close\r\n\r\n";
  27. static const char HTTPOKFONTEOT_CACHED[] = "HTTP/1.1 200 Ok\r\nContent-Type: application/vnd.ms-fontobject\r\nCache-Control: public, max-age=31536000\r\nConnection: Close\r\n\r\n";
  28. static const char HTTPOKFONTTTF_CACHED[] = "HTTP/1.1 200 Ok\r\nContent-Type: application/x-font-ttf\r\nCache-Control: public, max-age=31536000\r\nConnection: Close\r\n\r\n";
  29. static const char HTTPOKFONTWOFF_CACHED[] = "HTTP/1.1 200 Ok\r\nContent-Type: application/font-woff\r\nCache-Control: public, max-age=31536000\r\nConnection: Close\r\n\r\n";
  30. static const char HTTPOKFONTWOFF2_CACHED[] = "HTTP/1.1 200 Ok\r\nContent-Type: application/font-woff2\r\nCache-Control: public, max-age=31536000\r\nConnection: Close\r\n\r\n";
  31. // Images
  32. static const char HTTPOKPNG[] = "HTTP/1.1 200 Ok\r\nContent-Type: image/png\r\nConnection: Close\r\n\r\n";
  33. static const char HTTPOKSVG[] = "HTTP/1.1 200 Ok\r\nContent-Type: image/svg+xml\r\nConnection: Close\r\n\r\n";
  34. class IMonPage;
  35. using TMonPagePtr = TIntrusivePtr<IMonPage>;
  36. class IMonPage: public TAtomicRefCount<IMonPage> {
  37. public:
  38. const TString Path;
  39. const TString Title;
  40. const IMonPage* Parent = nullptr;
  41. public:
  42. IMonPage(const TString& path, const TString& title = TString());
  43. virtual ~IMonPage() {
  44. }
  45. void OutputNavBar(IOutputStream& out);
  46. virtual const TString& GetPath() const {
  47. return Path;
  48. }
  49. virtual const TString& GetTitle() const {
  50. return Title;
  51. }
  52. bool IsInIndex() const {
  53. return !Title.empty();
  54. }
  55. virtual bool IsIndex() const {
  56. return false;
  57. }
  58. virtual void Output(IMonHttpRequest& request) = 0;
  59. };
  60. }