1 #ifndef NETSCHEDULE_ALERT__HPP 2 #define NETSCHEDULE_ALERT__HPP 3 4 /* $Id: ns_alert.hpp 573688 2018-10-31 14:21:21Z satskyse $ 5 * =========================================================================== 6 * 7 * PUBLIC DOMAIN NOTICE 8 * National Center for Biotechnology Information 9 * 10 * This software/database is a "United States Government Work" under the 11 * terms of the United States Copyright Act. It was written as part of 12 * the author's official duties as a United States Government employee and 13 * thus cannot be copyrighted. This software/database is freely available 14 * to the public for use. The National Library of Medicine and the U.S. 15 * Government have not placed any restriction on its use or reproduction. 16 * 17 * Although all reasonable efforts have been taken to ensure the accuracy 18 * and reliability of the software and data, the NLM and the U.S. 19 * Government do not and cannot warrant the performance or results that 20 * may be obtained by using this software or data. The NLM and the U.S. 21 * Government disclaim all warranties, express or implied, including 22 * warranties of performance, merchantability or fitness for any particular 23 * purpose. 24 * 25 * Please cite the author in any work or product based on this material. 26 * 27 * =========================================================================== 28 * 29 * Authors: Sergey Satskiy 30 * 31 * File Description: 32 * Net schedule server alerts 33 * 34 */ 35 36 37 #include "ns_precise_time.hpp" 38 #include <corelib/ncbimtx.hpp> 39 40 #include <map> 41 42 43 BEGIN_NCBI_SCOPE 44 45 46 enum EAlertType { 47 eUnknown = -1, 48 eStartupConfig = 0, 49 eReconfigure = 1, 50 ePidFile = 2, 51 eStartAfterCrash = 3, 52 eAccess = 4, 53 eConfigOutOfSync = 5, 54 eReinit = 6, 55 eNoDump = 7, 56 eDumpError = 8, 57 eMaxQueues = 9, 58 eDumpLoadError = 10, 59 eDumpSpaceError = 11, 60 eDataDirRemoveError = 12 61 }; 62 63 enum EAlertAckResult { 64 eNotFound = 0, 65 eAlreadyAcknowledged = 1, 66 eAcknowledged = 2 67 }; 68 69 70 struct SNSAlertAttributes 71 { 72 CNSPreciseTime m_LastDetectedTimestamp; 73 CNSPreciseTime m_AcknowledgedTimestamp; 74 bool m_On; 75 size_t m_Count; // total, i.e. since startup 76 size_t m_CountSinceAck; // since acknowledge 77 string m_User; 78 string m_Message; 79 SNSAlertAttributesSNSAlertAttributes80 SNSAlertAttributes() : 81 m_LastDetectedTimestamp(CNSPreciseTime::Current()), 82 m_AcknowledgedTimestamp(), m_On(true), m_Count(1), 83 m_CountSinceAck(1) 84 {} 85 86 string Serialize(void) const; 87 }; 88 89 90 91 92 class CNSAlerts 93 { 94 public: 95 void Register(enum EAlertType alert_type, const string & message); 96 enum EAlertAckResult Acknowledge(const string & alert_id, 97 const string & user); 98 enum EAlertAckResult Acknowledge(enum EAlertType alert_type, 99 const string & user); 100 string GetURLEncoded(void) const; 101 string Serialize(void) const; 102 103 private: 104 mutable CFastMutex m_Lock; 105 map< enum EAlertType, 106 SNSAlertAttributes > m_Alerts; 107 108 enum EAlertType x_IdToType(const string & alert_id) const; 109 string x_TypeToId(enum EAlertType type) const; 110 }; 111 112 113 114 END_NCBI_SCOPE 115 116 #endif /* NETSCHEDULE_ALERT__HPP */ 117 118