Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#include "MantidKernel/ErrorReporter.h"
#include "MantidKernel/ChecksumHelper.h"
#include "MantidKernel/ConfigService.h"
#include "MantidKernel/DateAndTime.h"
#include "MantidKernel/Exception.h"
#include "MantidKernel/InternetHelper.h"
#include "MantidKernel/MantidVersion.h"
#include "MantidKernel/Logger.h"
#include "MantidKernel/ParaViewVersion.h"
#include "MantidKernel/FacilityInfo.h"
#include <Poco/ActiveResult.h>
#include <json/json.h>
namespace Mantid {
namespace Kernel {
namespace {
/// static logger
Logger g_log("ErrorReporter");
}
//----------------------------------------------------------------------------------------------
// Constructor for ErrorReporter
/** Constructor
*/
ErrorReporter::ErrorReporter(std::string application,
Types::Core::time_duration upTime,
std::string exitCode, bool share)
: ErrorReporter(application, upTime, exitCode, share, "", "") {}
/** Constructor
*/
ErrorReporter::ErrorReporter(std::string application,
Types::Core::time_duration upTime,
std::string exitCode, bool share, std::string name,
std::string email)
: m_application(application), m_exitCode(exitCode), m_upTime(upTime),
m_share(share), m_name(name), m_email(email) {
int retval = Mantid::Kernel::ConfigService::Instance().getValue(
"errorreports.rooturl", m_url);
if (retval == 0) {
g_log.debug() << "Failed to load error report url\n";
}
}
/** Generates an error message and then calls an internet helper to send it
*/
void ErrorReporter::sendErrorReport() {
try {
std::string message = this->generateErrorMessage();
// send the report
// Poco::ActiveResult<int> result = m_errorActiveMethod(message);
this->sendReport(message, m_url + "/api/error");
} catch (std::exception &ex) {
g_log.debug() << "Send error report failure. " << ex.what() << '\n';
}
}
/** Generates an error message in json format
*/
std::string ErrorReporter::generateErrorMessage() {
::Json::Value message;
// username
message["uid"] = Kernel::ChecksumHelper::md5FromString(
ConfigService::Instance().getUsername());
// hostname
message["host"] = Kernel::ChecksumHelper::md5FromString(
ConfigService::Instance().getComputerName());
// os name, version, and architecture
message["osName"] = ConfigService::Instance().getOSName();
message["osArch"] = ConfigService::Instance().getOSArchitecture();
message["osVersion"] = ConfigService::Instance().getOSVersion();
message["osReadable"] = ConfigService::Instance().getOSVersionReadable();
#if defined(MAKE_VATES)
// paraview
message["ParaView"] = Kernel::ParaViewVersion::targetVersion();
#else
message["ParaView"] = 0;
#endif
// mantid version and sha1
message["mantidVersion"] = MantidVersion::version();
message["mantidSha1"] = MantidVersion::revisionFull();
message["dateTime"] =
Types::Core::DateAndTime::getCurrentTime().toISO8601String();
message["upTime"] = to_simple_string(m_upTime);
message["application"] = m_application;
message["facility"] = ConfigService::Instance().getFacility().name();
message["exitCode"] = m_exitCode;
if (m_share) {
message["email"] = m_email;
message["name"] = m_name;
}
::Json::FastWriter writer;
return writer.write(message);
}
/** Submits a post request to the specified url with the message as the body
@param message : String containg json formatted error message
@param url : The url to send the post request to
*/
int ErrorReporter::sendReport(const std::string &message,
const std::string &url) {
int status = -1;
try {
Kernel::InternetHelper helper;
std::stringstream responseStream;
helper.setTimeout(20);
helper.setBody(message);
status = helper.sendRequest(url, responseStream);
} catch (Mantid::Kernel::Exception::InternetError &e) {
status = e.errorCode();
g_log.information() << "Call to \"" << url << "\" responded with " << status
<< "\n" << e.what() << "\n";
}
return status;
}
} // namespace Kernel
} // namespace Mantid