Feature__33.patch
nel/include/nel/misc/common.h (working copy) | ||
---|---|---|
322 | 322 |
uint32 humanReadableToBytes (const std::string &str); |
323 | 323 |
|
324 | 324 |
/// Convert a time into a string that is easily readable by an human, for example 3600 -> "1h" |
325 |
std::string secondsToHumanReadable (uint32 time);
|
|
325 |
std::string secondsToHumanReadable (time_t time);
|
|
326 | 326 |
|
327 | 327 |
|
328 | 328 |
/// Get a bytes or time in string format and convert it in seconds or bytes |
329 |
uint32 fromHumanReadable (const std::string &str);
|
|
329 |
time_t fromHumanReadable (const std::string &str);
|
|
330 | 330 |
|
331 | 331 |
|
332 | 332 |
/// This function executes a program in the background and returns instantly (used for example to launch services in AES). |
nel/include/nel/misc/time_nl.h (working copy) | ||
---|---|---|
62 | 62 |
* daylight saving if applicable. |
63 | 63 |
* This values is the same on all computer if computers are synchronized (with NTP for example). |
64 | 64 |
*/ |
65 |
static uint32 getSecondsSince1970 ();
|
|
65 |
static time_t getSecondsSince1970 ();
|
|
66 | 66 |
|
67 | 67 |
/** Return the number of second since midnight (00:00:00), January 1, 1970, |
68 | 68 |
* coordinated universal time, according to the system clock. |
nel/include/nel/net/admin.h (working copy) | ||
---|---|---|
58 | 58 |
std::string Name; // variable name |
59 | 59 |
int Update; // delta time in second when we have to check variable |
60 | 60 |
|
61 |
uint32 LastUpdate; // in second
|
|
61 |
time_t LastUpdate; // in second
|
|
62 | 62 |
}; |
63 | 63 |
|
64 | 64 |
typedef void (*TRemoteClientCallback) (uint32 rid, const std::string &cmd, const std::string &entityNames); |
nel/include/nel/net/service.h (working copy) | ||
---|---|---|
237 | 237 |
sint getExitStatus () const { return _ExitStatus; } |
238 | 238 |
|
239 | 239 |
/// Returns the date of launch of the service. Unit: see CTime::getSecondsSince1970() |
240 |
uint32 getLaunchingDate () const;
|
|
240 |
time_t getLaunchingDate () const;
|
|
241 | 241 |
|
242 | 242 |
/// Return true if this service don't use the NS (naming service) |
243 | 243 |
bool getDontUseNS() const { return _DontUseNS; }; |
nel/src/misc/common.cpp (working copy) | ||
---|---|---|
395 | 395 |
} |
396 | 396 |
|
397 | 397 |
|
398 |
string secondsToHumanReadable (uint32 time)
|
|
398 |
string secondsToHumanReadable (time_t time)
|
|
399 | 399 |
{ |
400 | 400 |
static const char *divTable[] = { "s", "mn", "h", "d" }; |
401 | 401 |
static uint divCoef[] = { 60, 60, 24 }; |
402 | 402 |
uint div = 0; |
403 |
uint32 res = time;
|
|
404 |
uint32 newres = res;
|
|
403 |
time_t res = time;
|
|
404 |
time_t newres = res;
|
|
405 | 405 |
for(;;) |
406 | 406 |
{ |
407 | 407 |
if(div > 2) |
... | ... | |
418 | 418 |
return toString ("%u%s", res, divTable[div]); |
419 | 419 |
} |
420 | 420 |
|
421 |
uint32 fromHumanReadable (const std::string &str)
|
|
421 |
time_t fromHumanReadable (const std::string &str)
|
|
422 | 422 |
{ |
423 | 423 |
if (str.size() == 0) |
424 | 424 |
return 0; |
425 | 425 |
|
426 |
uint32 val;
|
|
426 |
time_t val;
|
|
427 | 427 |
fromString(str, val); |
428 | 428 |
|
429 | 429 |
switch (str[str.size()-1]) |
... | ... | |
451 | 451 |
if (args.size() != 1) |
452 | 452 |
return false; |
453 | 453 |
|
454 |
uint32 seconds;
|
|
454 |
time_t seconds;
|
|
455 | 455 |
fromString(args[0], seconds); |
456 | 456 |
log.displayNL("%s -> %s", args[0].c_str(), secondsToHumanReadable(seconds).c_str()); |
457 | 457 |
|
nel/src/misc/time_nl.cpp (working copy) | ||
---|---|---|
48 | 48 |
* coordinated universal time, according to the system clock. |
49 | 49 |
* This values is the same on all computer if computers are synchronized (with NTP for example). |
50 | 50 |
*/ |
51 |
uint32 CTime::getSecondsSince1970 ()
|
|
51 |
time_t CTime::getSecondsSince1970 ()
|
|
52 | 52 |
{ |
53 |
return uint32(time(NULL));
|
|
53 |
return time_t(time(NULL));
|
|
54 | 54 |
} |
55 | 55 |
|
56 | 56 |
/** Return the number of second since midnight (00:00:00), January 1, 1970, |
nel/src/net/admin.cpp (working copy) | ||
---|---|---|
68 | 68 |
uint NbWaiting; |
69 | 69 |
uint32 NbReceived; |
70 | 70 |
TServiceId SId; |
71 |
uint32 Time; // when the request was ask
|
|
71 |
time_t Time; // when the request was ask
|
|
72 | 72 |
|
73 | 73 |
TAdminViewResult Answers; |
74 | 74 |
}; |
... | ... | |
304 | 304 |
|
305 | 305 |
static void cleanRequest () |
306 | 306 |
{ |
307 |
uint32 currentTime = CTime::getSecondsSince1970 ();
|
|
307 |
time_t currentTime = CTime::getSecondsSince1970 ();
|
|
308 | 308 |
|
309 | 309 |
for (uint i = 0 ; i < Requests.size ();) |
310 | 310 |
{ |
... | ... | |
634 | 634 |
|
635 | 635 |
void updateAdmin() |
636 | 636 |
{ |
637 |
uint32 CurrentTime = CTime::getSecondsSince1970();
|
|
637 |
time_t CurrentTime = CTime::getSecondsSince1970();
|
|
638 | 638 |
|
639 | 639 |
|
640 | 640 |
// |
... | ... | |
648 | 648 |
// Check graph updates |
649 | 649 |
// |
650 | 650 |
|
651 |
static uint32 lastGraphUpdateCheck = 0;
|
|
651 |
static time_t lastGraphUpdateCheck = 0;
|
|
652 | 652 |
|
653 | 653 |
if (CurrentTime >= lastGraphUpdateCheck+1) |
654 | 654 |
{ |
... | ... | |
714 | 714 |
// Check alarms |
715 | 715 |
// |
716 | 716 |
|
717 |
static uint32 lastAlarmsCheck = 0;
|
|
717 |
static time_t lastAlarmsCheck = 0;
|
|
718 | 718 |
|
719 | 719 |
if (CurrentTime >= lastAlarmsCheck+AlarmCheckDelay) |
720 | 720 |
{ |
nel/src/net/login_server.cpp (working copy) | ||
---|---|---|
51 | 51 |
string UserExtended; // extended data (for free use) |
52 | 52 |
uint32 InstanceId; // the world instance in witch the user is awaited |
53 | 53 |
uint32 CharSlot; // the expected character slot, any other will be denied |
54 |
uint32 Time; // when the cookie is inserted in pending list
|
|
54 |
time_t Time; // when the cookie is inserted in pending list
|
|
55 | 55 |
}; |
56 | 56 |
|
57 | 57 |
static list<CPendingUser> PendingUsers; |
... | ... | |
96 | 96 |
// delete too old cookie |
97 | 97 |
|
98 | 98 |
list<CPendingUser>::iterator it = PendingUsers.begin(); |
99 |
uint32 Time = CTime::getSecondsSince1970();
|
|
99 |
time_t Time = CTime::getSecondsSince1970();
|
|
100 | 100 |
while (it != PendingUsers.end ()) |
101 | 101 |
{ |
102 | 102 |
if ((*it).Time < Time - TimeBeforeEraseCookie) |
nel/src/net/module_gateway_transport.cpp (working copy) | ||
---|---|---|
56 | 56 |
TSockId SockId; |
57 | 57 |
|
58 | 58 |
/// Time stamp of last message received/emitted |
59 |
mutable uint32 LastCommTime;
|
|
59 |
mutable time_t LastCommTime;
|
|
60 | 60 |
|
61 | 61 |
|
62 | 62 |
CL3ServerRoute(IGatewayTransport *transport) |
... | ... | |
115 | 115 |
if (_CallbackServer.get() != NULL) |
116 | 116 |
_CallbackServer->update2(100, 0); |
117 | 117 |
|
118 |
uint32 now = CTime::getSecondsSince1970();
|
|
118 |
time_t now = CTime::getSecondsSince1970();
|
|
119 | 119 |
// check each connected client for keep alive |
120 | 120 |
TRouteMap::iterator first(_Routes.begin()), last(_Routes.end()); |
121 | 121 |
for (; first != last; ++first) |
... | ... | |
402 | 402 |
/// The Client callback |
403 | 403 |
mutable CCallbackClient CallbackClient; |
404 | 404 |
/// Time stamp of last message received/emitted |
405 |
mutable uint32 LastCommTime;
|
|
405 |
mutable time_t LastCommTime;
|
|
406 | 406 |
|
407 | 407 |
/// The last time we try to reconnect (in case of disconnection) |
408 |
uint32 LastConnectionRetry;
|
|
408 |
time_t LastConnectionRetry;
|
|
409 | 409 |
|
410 | 410 |
// conn id |
411 | 411 |
uint32 ConnId; |
... | ... | |
521 | 521 |
// delete any route pending |
522 | 522 |
deletePendingRoute(); |
523 | 523 |
|
524 |
uint32 now = CTime::getSecondsSince1970();
|
|
524 |
time_t now = CTime::getSecondsSince1970();
|
|
525 | 525 |
// update the client connection |
526 | 526 |
TClientRoutes::iterator first(_Routes.begin()), last(_Routes.end()); |
527 | 527 |
for (; first != last; ++first) |
nel/src/net/service.cpp (working copy) | ||
---|---|---|
140 | 140 |
//static CLog commandLog; |
141 | 141 |
|
142 | 142 |
static string CompilationDate; |
143 |
static uint32 LaunchingDate;
|
|
143 |
static time_t LaunchingDate;
|
|
144 | 144 |
|
145 | 145 |
static uint32 NbUserUpdate = 0; |
146 | 146 |
|
... | ... | |
1705 | 1705 |
/* |
1706 | 1706 |
* Returns the date of launch of the service. Unit: see CTime::getSecondsSince1970() |
1707 | 1707 |
*/ |
1708 |
uint32 IService::getLaunchingDate () const
|
|
1708 |
time_t IService::getLaunchingDate () const
|
|
1709 | 1709 |
{ |
1710 | 1710 |
return LaunchingDate; |
1711 | 1711 |
} |
nelns/admin_executor_service/admin_executor_service.cpp (working copy) | ||
---|---|---|
78 | 78 |
// |
79 | 79 |
// Namespaces |
80 | 80 |
// |
81 |
|
|
81 |
|
|
82 | 82 |
using namespace std; |
83 | 83 |
using namespace NLMISC; |
84 | 84 |
using namespace NLNET; |
... | ... | |
100 | 100 |
uint NbWaiting; |
101 | 101 |
uint32 NbReceived; |
102 | 102 |
TServiceId SId; |
103 |
uint32 Time; // when the request was ask
|
|
103 |
time_t Time; // when the request was ask
|
|
104 | 104 |
|
105 | 105 |
TAdminViewResult Answers; |
106 | 106 |
}; |
... | ... | |
122 | 122 |
uint32 PId; /// process Id used to kill the application |
123 | 123 |
bool Relaunch; /// if true, it means that the admin want to close and relaunch the service |
124 | 124 |
|
125 |
uint32 LastPing; /// time in seconds of the last ping sent. If 0, means that the service already pong
|
|
125 |
time_t LastPing; /// time in seconds of the last ping sent. If 0, means that the service already pong
|
|
126 | 126 |
|
127 | 127 |
vector<uint32> WaitingRequestId; /// contains all request that the server hasn't reply yet |
128 | 128 |
|
... | ... | |
197 | 197 |
|
198 | 198 |
vector<string> RegisteredServices; |
199 | 199 |
|
200 |
vector<pair<uint32, string> > WaitingToLaunchServices; // date and alias name
|
|
200 |
vector<pair<time_t, string> > WaitingToLaunchServices; // date and alias name
|
|
201 | 201 |
|
202 | 202 |
vector<string> AllAdminAlarms; // contains *all* alarms |
203 | 203 |
|
... | ... | |
208 | 208 |
// Global Variables (scalars) |
209 | 209 |
// |
210 | 210 |
|
211 |
uint32 LastPing = 0; // contains the date of the last ping sent to the services
|
|
211 |
time_t LastPing = 0; // contains the date of the last ping sent to the services
|
|
212 | 212 |
|
213 | 213 |
|
214 | 214 |
// |
... | ... | |
238 | 238 |
{ |
239 | 239 |
char *text; |
240 | 240 |
NLMISC_CONVERT_VARGS(text, format, 4096); |
241 |
|
|
241 |
|
|
242 | 242 |
CMessage msgout("ADMIN_EMAIL"); |
243 | 243 |
string str = text; |
244 | 244 |
msgout.serial(str); |
... | ... | |
420 | 420 |
// make sure the alias, command, etc were setup ok |
421 | 421 |
if (!ok) return false; |
422 | 422 |
nlinfo("Starting the service alias '%s'", alias.c_str()); |
423 |
|
|
423 |
|
|
424 | 424 |
bool dontLaunchServicesDirectly= IService::getInstance()->ConfigFile.exists("DontLaunchServicesDirectly")? IService::getInstance()->ConfigFile.getVar("DontLaunchServicesDirectly").asBool(): false; |
425 | 425 |
if (!dontLaunchServicesDirectly) |
426 |
{
|
|
426 |
{ |
|
427 | 427 |
// give the service alias to the service to forward it back when it will connected to the aes. |
428 | 428 |
arg += " -N"; |
429 | 429 |
arg += alias; |
... | ... | |
431 | 431 |
// set the path for running |
432 | 432 |
arg += " -A"; |
433 | 433 |
arg += path; |
434 |
|
|
434 |
|
|
435 | 435 |
// suppress output to stdout |
436 | 436 |
#ifdef NL_OS_WINDOWS |
437 | 437 |
arg += " >NUL:"; |
... | ... | |
441 | 441 |
|
442 | 442 |
// launch the service |
443 | 443 |
bool res = launchProgram(command, arg); |
444 |
|
|
444 |
|
|
445 | 445 |
// if launching ok, leave 1 second to the new launching service before lauching next one |
446 | 446 |
if (res) |
447 | 447 |
nlSleep(1000); |
448 |
|
|
448 |
|
|
449 | 449 |
return res; |
450 | 450 |
} |
451 | 451 |
else |
... | ... | |
502 | 502 |
|
503 | 503 |
void checkWaitingServices() |
504 | 504 |
{ |
505 |
uint32 d = CTime::getSecondsSince1970();
|
|
505 |
time_t d = CTime::getSecondsSince1970();
|
|
506 | 506 |
|
507 | 507 |
for(uint i = 0; i < WaitingToLaunchServices.size(); ) |
508 | 508 |
{ |
... | ... | |
520 | 520 |
|
521 | 521 |
static void checkPingPong() |
522 | 522 |
{ |
523 |
uint32 d = CTime::getSecondsSince1970();
|
|
523 |
time_t d = CTime::getSecondsSince1970();
|
|
524 | 524 |
|
525 | 525 |
bool allPonged = true; |
526 | 526 |
bool haveService = false; |
527 |
|
|
527 |
|
|
528 | 528 |
for(uint i = 0; i < Services.size(); i++) |
529 | 529 |
{ |
530 | 530 |
if(Services[i].Ready) |
... | ... | |
682 | 682 |
|
683 | 683 |
Requests[i].NbReceived++; |
684 | 684 |
nldebug("REQUEST: ++ i %d rid %d NbWaiting %d NbReceived+ %d", i, Requests[i].Id, Requests[i].NbWaiting, Requests[i].NbReceived); |
685 |
|
|
685 |
|
|
686 | 686 |
return; |
687 | 687 |
} |
688 | 688 |
} |
... | ... | |
692 | 692 |
|
693 | 693 |
void cleanRequests() |
694 | 694 |
{ |
695 |
uint32 currentTime = CTime::getSecondsSince1970();
|
|
695 |
time_t currentTime = CTime::getSecondsSince1970();
|
|
696 | 696 |
|
697 | 697 |
// just a debug check |
698 | 698 |
for (uint t = 0 ; t < Requests.size(); t++) |
... | ... | |
715 | 715 |
} |
716 | 716 |
} |
717 | 717 |
nlinfo("REQUEST: Waiting request %d: NbRef %d NbWaiting %d NbReceived %d", Requests[t].Id, NbRef, NbWaiting, NbReceived); |
718 |
|
|
718 |
|
|
719 | 719 |
if (NbRef != NbWaiting - NbReceived) |
720 | 720 |
{ |
721 | 721 |
nlwarning("REQUEST: **** i %d rid %d -> NbRef(%d) != NbWaiting(%d) - NbReceived(%d) ", t, Requests[t].Id, NbRef, NbWaiting, NbReceived); |
... | ... | |
731 | 731 |
|
732 | 732 |
TAdminViewVarNames varNames; |
733 | 733 |
TAdminViewValues values; |
734 |
|
|
734 |
|
|
735 | 735 |
varNames.push_back("service"); |
736 | 736 |
for (uint j = 0; j < Services.size(); j++) |
737 | 737 |
{ |
... | ... | |
748 | 748 |
else |
749 | 749 |
s = Services[j].AliasName; |
750 | 750 |
s += "-"+toString(Services[j].ServiceId); |
751 |
s += "((TIMEOUT))";
|
|
751 |
s += "((TIMEOUT))"; |
|
752 | 752 |
values.clear(); |
753 | 753 |
values.push_back(s); |
754 | 754 |
aesAddRequestAnswer(Requests[i].Id, varNames, values); |
... | ... | |
798 | 798 |
} |
799 | 799 |
InfoLog->displayRawNL(""); |
800 | 800 |
InfoLog->displayRawNL("----------------------------------------------"); |
801 |
}
|
|
801 |
} |
|
802 | 802 |
} |
803 | 803 |
else |
804 | 804 |
CUnifiedNetwork::getInstance()->send(Requests[i].SId, msgout); |
... | ... | |
847 | 847 |
// not found in alias, try with short name |
848 | 848 |
for (sit = Services.begin(); sit != Services.end(); sit++) |
849 | 849 |
{ |
850 |
if ((*sit).ShortName == shortName)
|
|
850 |
if ((*sit).ShortName == shortName) |
|
851 | 851 |
{ |
852 | 852 |
services.push_back(sit); |
853 | 853 |
} |
... | ... | |
944 | 944 |
serviceGetView(rid, viewStr, answer); |
945 | 945 |
aesAddRequestAnswer(rid, answer); |
946 | 946 |
nlinfo("REQUEST: Treated view myself directly: '%s'", viewStr.c_str()); |
947 |
}
|
|
947 |
} |
|
948 | 948 |
|
949 | 949 |
void treatRequestForOfflineService(uint32 rid, const string& serviceName, const string& viewStr) |
950 | 950 |
{ |
... | ... | |
954 | 954 |
|
955 | 955 |
TAdminViewVarNames varNames; |
956 | 956 |
TAdminViewValues values; |
957 |
|
|
957 |
|
|
958 | 958 |
// add default row |
959 | 959 |
varNames.push_back("service"); |
960 | 960 |
values.push_back(serviceName); |
961 |
|
|
961 |
|
|
962 | 962 |
for (uint k = 0; k < subvarpath.Destination.size(); k++) |
963 | 963 |
{ |
964 | 964 |
size_t pos = subvarpath.Destination[k].first.find("="); |
... | ... | |
1004 | 1004 |
aesAddRequestAnswer(rid, varNames, values); |
1005 | 1005 |
nlinfo("REQUEST: Sent and received view '%s' to offline service '%s'", viewStr.c_str(), serviceName.c_str()); |
1006 | 1006 |
} |
1007 |
|
|
1007 |
|
|
1008 | 1008 |
void addRequestForOnlineServices(uint32 rid, const string& viewStr) |
1009 | 1009 |
{ |
1010 | 1010 |
// add services that I manage |
... | ... | |
1018 | 1018 |
|
1019 | 1019 |
// add myself |
1020 | 1020 |
treatRequestOneself(rid,viewStr); |
1021 |
}
|
|
1021 |
} |
|
1022 | 1022 |
|
1023 | 1023 |
void addRequestForAllServices(uint32 rid, const string& viewStr) |
1024 | 1024 |
{ |
... | ... | |
1039 | 1039 |
|
1040 | 1040 |
// add all running services (and for oneself) |
1041 | 1041 |
addRequestForOnlineServices(rid,viewStr); |
1042 |
}
|
|
1042 |
} |
|
1043 | 1043 |
|
1044 | 1044 |
void addRequestForNamedService(uint32 rid, const string& service, const string& viewStr) |
1045 | 1045 |
{ |
... | ... | |
1074 | 1074 |
} |
1075 | 1075 |
} |
1076 | 1076 |
} |
1077 |
}
|
|
1077 |
} |
|
1078 | 1078 |
|
1079 | 1079 |
void addRequest(uint32 rid, const string &rawvarpath, TServiceId sid) |
1080 | 1080 |
{ |
... | ... | |
1097 | 1097 |
for (uint t = 0; t < vp.Destination.size(); t++) |
1098 | 1098 |
{ |
1099 | 1099 |
string service = vp.Destination[t].first; |
1100 |
|
|
1100 |
|
|
1101 | 1101 |
if (service == "*") |
1102 | 1102 |
{ |
1103 | 1103 |
addRequestForOnlineServices(rid,varpath.Destination[i].second); |
... | ... | |
1196 | 1196 |
// |
1197 | 1197 |
msgin.serialCont(AllAdminAlarms); |
1198 | 1198 |
msgin.serialCont(AllGraphUpdates); |
1199 |
|
|
1199 |
|
|
1200 | 1200 |
// set our own alarms for this service |
1201 | 1201 |
setInformations(AllAdminAlarms, AllGraphUpdates); |
1202 | 1202 |
|
... | ... | |
1245 | 1245 |
{ |
1246 | 1246 |
// receive an view answer from the service |
1247 | 1247 |
TServices::iterator sit = findService(sid); |
1248 |
|
|
1248 |
|
|
1249 | 1249 |
uint32 rid; |
1250 | 1250 |
msgin.serial(rid); |
1251 | 1251 |
|
... | ... | |
1257 | 1257 |
{ |
1258 | 1258 |
varNames.clear(); |
1259 | 1259 |
values.clear(); |
1260 |
|
|
1260 |
|
|
1261 | 1261 |
// adding default row |
1262 |
|
|
1262 |
|
|
1263 | 1263 |
uint32 i, nb; |
1264 | 1264 |
string var, val; |
1265 |
|
|
1265 |
|
|
1266 | 1266 |
msgin.serial(nb); |
1267 | 1267 |
for (i = 0; i < nb; i++) |
1268 | 1268 |
{ |
1269 | 1269 |
msgin.serial(var); |
1270 | 1270 |
varNames.push_back(var); |
1271 | 1271 |
} |
1272 |
|
|
1272 |
|
|
1273 | 1273 |
msgin.serial(nb); |
1274 | 1274 |
for (i = 0; i < nb; i++) |
1275 | 1275 |
{ |
... | ... | |
1279 | 1279 |
answer.push_back(SAdminViewRow(varNames,values)); |
1280 | 1280 |
} |
1281 | 1281 |
aesAddRequestAnswer(rid, answer); |
1282 |
|
|
1282 |
|
|
1283 | 1283 |
// remove the waiting request |
1284 | 1284 |
for (uint i = 0; i < (*sit).WaitingRequestId.size();) |
1285 | 1285 |
{ |
... | ... | |
1497 | 1497 |
if (i != 0) cmd += " "; |
1498 | 1498 |
cmd += args[i]; |
1499 | 1499 |
} |
1500 |
|
|
1500 |
|
|
1501 | 1501 |
static uint32 requestId=0; |
1502 | 1502 |
addRequest(requestId++, cmd, TServiceId(0)); |
1503 | 1503 |
|
... | ... | |
1539 | 1539 |
{ |
1540 | 1540 |
if(args.size() <= 0) |
1541 | 1541 |
return false; |
1542 |
|
|
1542 |
|
|
1543 | 1543 |
string text; |
1544 | 1544 |
for (uint i =0; i < args.size(); i++) |
1545 | 1545 |
{ |
1546 | 1546 |
text += args[i]+" "; |
1547 | 1547 |
} |
1548 | 1548 |
sendAdminEmail(text.c_str()); |
1549 |
|
|
1549 |
|
|
1550 | 1550 |
return true; |
1551 | 1551 |
} |
1552 | 1552 |
|
... | ... | |
1623 | 1623 |
{ |
1624 | 1624 |
if(args.size() <= 0) |
1625 | 1625 |
return false; |
1626 |
|
|
1626 |
|
|
1627 | 1627 |
string cmd; |
1628 | 1628 |
for (uint i =0; i < args.size(); i++) |
1629 | 1629 |
{ |
1630 | 1630 |
cmd += args[i]+" "; |
1631 | 1631 |
} |
1632 |
|
|
1632 |
|
|
1633 | 1633 |
string path; |
1634 | 1634 |
#ifdef NL_OS_UNIX |
1635 | 1635 |
path = "/tmp/"; |
... | ... | |
1637 | 1637 |
|
1638 | 1638 |
string fn = path+CFile::findNewFile("aessys.tmp"); |
1639 | 1639 |
string fne = path+CFile::findNewFile("aessyse.tmp"); |
1640 |
|
|
1640 |
|
|
1641 | 1641 |
cmd += " >" + fn + " 2>" + fne; |
1642 |
|
|
1642 |
|
|
1643 | 1643 |
log.displayNL("Executing: '%s' in directory '%s'", cmd.c_str(), CPath::getCurrentPath().c_str()); |
1644 | 1644 |
|
1645 | 1645 |
system(cmd.c_str()); |
1646 |
|
|
1646 |
|
|
1647 | 1647 |
char str[1024]; |
1648 | 1648 |
|
1649 | 1649 |
FILE *fp = fopen(fn.c_str(), "rt"); |
... | ... | |
1656 | 1656 |
break; |
1657 | 1657 |
log.displayRaw(res); |
1658 | 1658 |
} |
1659 |
|
|
1659 |
|
|
1660 | 1660 |
fclose(fp); |
1661 | 1661 |
} |
1662 | 1662 |
else |
1663 | 1663 |
{ |
1664 | 1664 |
log.displayNL("No stdout"); |
1665 | 1665 |
} |
1666 |
|
|
1666 |
|
|
1667 | 1667 |
fp = fopen(fne.c_str(), "rt"); |
1668 | 1668 |
if (fp != NULL) |
1669 | 1669 |
{ |
... | ... | |
1674 | 1674 |
break; |
1675 | 1675 |
log.displayRaw(res); |
1676 | 1676 |
} |
1677 |
|
|
1677 |
|
|
1678 | 1678 |
fclose(fp); |
1679 | 1679 |
} |
1680 | 1680 |
else |
... | ... | |
1731 | 1731 |
} |
1732 | 1732 |
else |
1733 | 1733 |
log.displayNL( "Task is not running" ); |
1734 |
}
|
|
1734 |
} |
|
1735 | 1735 |
|
1736 | 1736 |
return true; |
1737 | 1737 |
} |
nelns/admin_service/admin_service.cpp (working copy) | ||
---|---|---|
103 | 103 |
uint NbWaiting; |
104 | 104 |
uint32 NbReceived; |
105 | 105 |
TSockId From; |
106 |
uint32 Time; // when the request was ask
|
|
107 |
|
|
106 |
time_t Time; // when the request was ask
|
|
107 |
|
|
108 | 108 |
uint32 NbRow; |
109 | 109 |
uint32 NbLines; |
110 | 110 |
|
... | ... | |
203 | 203 |
for (aesit = AdminExecutorServices.begin(); aesit != AdminExecutorServices.end(); aesit++) |
204 | 204 |
if ((*aesit).SId == sid) |
205 | 205 |
break; |
206 |
|
|
206 |
|
|
207 | 207 |
if (asrt) |
208 | 208 |
nlassert (aesit != AdminExecutorServices.end()); |
209 | 209 |
return aesit; |
... | ... | |
215 | 215 |
for (aesit = AdminExecutorServices.begin(); aesit != AdminExecutorServices.end(); aesit++) |
216 | 216 |
if ((*aesit).Name == name) |
217 | 217 |
break; |
218 |
|
|
218 |
|
|
219 | 219 |
if (asrt) |
220 | 220 |
nlassert (aesit != AdminExecutorServices.end()); |
221 |
|
|
221 |
|
|
222 | 222 |
return aesit; |
223 | 223 |
} |
224 | 224 |
|
... | ... | |
236 | 236 |
|
237 | 237 |
char *query; |
238 | 238 |
NLMISC_CONVERT_VARGS (query, format, 1024); |
239 |
|
|
239 |
|
|
240 | 240 |
if (DatabaseConnection == 0) |
241 | 241 |
{ |
242 | 242 |
nlwarning ("MYSQL: mysql_query (%s) failed: DatabaseConnection is 0", query); |
243 | 243 |
return NULL; |
244 | 244 |
} |
245 |
|
|
245 |
|
|
246 | 246 |
int ret = mysql_query (DatabaseConnection, query); |
247 | 247 |
if (ret != 0) |
248 | 248 |
{ |
249 | 249 |
nlwarning ("MYSQL: mysql_query () failed for query '%s': %s", query, mysql_error(DatabaseConnection)); |
250 | 250 |
return 0; |
251 | 251 |
} |
252 |
|
|
252 |
|
|
253 | 253 |
sqlCurrentQueryResult = mysql_store_result(DatabaseConnection); |
254 | 254 |
if (sqlCurrentQueryResult == 0) |
255 | 255 |
{ |
256 | 256 |
nlwarning ("MYSQL: mysql_store_result () failed for query '%s': %s", query, mysql_error(DatabaseConnection)); |
257 | 257 |
return 0; |
258 | 258 |
} |
259 |
|
|
259 |
|
|
260 | 260 |
MYSQL_ROW row = mysql_fetch_row(sqlCurrentQueryResult); |
261 | 261 |
if (row == 0) |
262 | 262 |
{ |
263 | 263 |
nlwarning ("MYSQL: mysql_fetch_row () failed for query '%s': %s", query, mysql_error(DatabaseConnection)); |
264 | 264 |
} |
265 |
|
|
265 |
|
|
266 | 266 |
nldebug ("MYSQL: sqlQuery(%s) returns %d rows", query, mysql_num_rows(sqlCurrentQueryResult)); |
267 |
|
|
268 |
return row;
|
|
267 |
|
|
268 |
return row; |
|
269 | 269 |
} |
270 | 270 |
|
271 | 271 |
MYSQL_ROW sqlNextRow () |
... | ... | |
275 | 275 |
|
276 | 276 |
if (sqlCurrentQueryResult == 0) |
277 | 277 |
return 0; |
278 |
|
|
278 |
|
|
279 | 279 |
return mysql_fetch_row(sqlCurrentQueryResult); |
280 | 280 |
} |
281 | 281 |
|
... | ... | |
297 | 297 |
// |
298 | 298 |
|
299 | 299 |
string Email; |
300 |
uint32 FirstEmailTime = 0;
|
|
300 |
time_t FirstEmailTime = 0;
|
|
301 | 301 |
|
302 | 302 |
void sendAdminAlert (const char *format, ...) |
303 | 303 |
{ |
... | ... | |
360 | 360 |
{ |
361 | 361 |
subject = "Multiple problems"; |
362 | 362 |
} |
363 |
|
|
363 |
|
|
364 | 364 |
std::string from; |
365 | 365 |
if(IService::getInstance()->ConfigFile.exists("AdminEmailFrom")) |
366 | 366 |
from = IService::getInstance()->ConfigFile.getVar("AdminEmailFrom").asString(); |
... | ... | |
404 | 404 |
msgin.serial (service, var, val); |
405 | 405 |
|
406 | 406 |
AESIT aesit = findAES (sid); |
407 |
|
|
407 |
|
|
408 | 408 |
string shard, server; |
409 | 409 |
shard = (*aesit).Shard; |
410 | 410 |
server = (*aesit).Name; |
411 |
|
|
411 |
|
|
412 | 412 |
if (!shard.empty() && !server.empty() && !service.empty() && !var.empty()) |
413 | 413 |
{ |
414 | 414 |
string path = CPath::standardizePath (IService::getInstance()->ConfigFile.getVar("RRDVarPath").asString()); |
415 | 415 |
string rrdfilename = path + shard+"."+server+"."+service+"."+var+".rrd"; |
416 | 416 |
|
417 | 417 |
string arg; |
418 |
|
|
418 |
|
|
419 | 419 |
if (!NLMISC::CFile::fileExists(rrdfilename)) |
420 | 420 |
{ |
421 | 421 |
MYSQL_ROW row = sqlQuery ("select graph_update from variable where path like '%%%s' and graph_update!=0", var.c_str()); |
... | ... | |
541 | 541 |
|
542 | 542 |
void cleanRequest () |
543 | 543 |
{ |
544 |
uint32 currentTime = CTime::getSecondsSince1970 ();
|
|
544 |
time_t currentTime = CTime::getSecondsSince1970 ();
|
|
545 | 545 |
|
546 | 546 |
bool timeout; |
547 | 547 |
|
... | ... | |
560 | 560 |
{ |
561 | 561 |
nlwarning ("REQUEST: Request %d timeouted, only %d on %d services have replied", Requests[i].Id, Requests[i].NbReceived, Requests[i].NbWaiting); |
562 | 562 |
} |
563 |
|
|
563 |
|
|
564 | 564 |
if (Requests[i].Log.empty()) |
565 | 565 |
{ |
566 | 566 |
if (Requests[i].NbRow == 0 && timeout) |
... | ... | |
682 | 682 |
vector<string> informations; |
683 | 683 |
|
684 | 684 |
CMessage msgout("AES_INFO"); |
685 |
|
|
685 |
|
|
686 | 686 |
// |
687 | 687 |
// send services that should be running on this AES |
688 | 688 |
// |
... | ... | |
713 | 713 |
} |
714 | 714 |
sqlFlushResult(); |
715 | 715 |
msgout.serialCont (informations); |
716 |
|
|
716 |
|
|
717 | 717 |
// |
718 | 718 |
// send graph update for services that should running on this AES |
719 | 719 |
// |
... | ... | |
746 | 746 |
} |
747 | 747 |
sqlFlushResult(); |
748 | 748 |
msgout.serialCont (informations); |
749 |
|
|
749 |
|
|
750 | 750 |
nlinfo ("Sending all informations about %s AES-%hu (hostedservices, alarms,grapupdate)", (*aesit).Name.c_str(), (*aesit).SId.get()); |
751 | 751 |
CUnifiedNetwork::getInstance ()->send (sid, msgout); |
752 | 752 |
} |
... | ... | |
802 | 802 |
} |
803 | 803 |
string shard = row[0]; |
804 | 804 |
sqlFlushResult(); |
805 |
|
|
805 |
|
|
806 | 806 |
AdminExecutorServices.push_back (CAdminExecutorService(shard, server, sid)); |
807 | 807 |
|
808 | 808 |
nlinfo ("%s-%hu, server name %s, for shard %s connected and added in the list", serviceName.c_str(), sid.get(), server.c_str(), shard.c_str()); |
809 |
|
|
809 |
|
|
810 | 810 |
// send him services that should run on this server |
811 | 811 |
sendAESInformations (sid); |
812 | 812 |
} |
... | ... | |
863 | 863 |
AdminExecutorServices.push_back (CAdminExecutorService(shard, server, sid)); |
864 | 864 |
|
865 | 865 |
nlinfo ("%s-%hu, server name %s, for shard %s connected and added in the list", serviceName.c_str(), sid.get(), server.c_str(), shard.c_str()); |
866 |
|
|
866 |
|
|
867 | 867 |
// send him services that should run on this server |
868 | 868 |
sendAESInformations (sid); |
869 | 869 |
} |
... | ... | |
1022 | 1022 |
else if (shard == "*" && server == "#") |
1023 | 1023 |
{ |
1024 | 1024 |
// Select all shard all server including offline one |
1025 |
|
|
1025 |
|
|
1026 | 1026 |
MYSQL_ROW row = sqlQuery ("select distinct server, shard from service"); |
1027 |
|
|
1027 |
|
|
1028 | 1028 |
while (row != NULL) |
1029 | 1029 |
{ |
1030 | 1030 |
AESIT aesit = findAES (row[0], false); |
1031 |
|
|
1031 |
|
|
1032 | 1032 |
if (aesit != AdminExecutorServices.end()) |
1033 | 1033 |
{ |
1034 | 1034 |
addRequestWaitingNb (rid); |
1035 | 1035 |
(*aesit).WaitingRequestId.push_back (rid); |
1036 |
|
|
1036 |
|
|
1037 | 1037 |
CMessage msgout("AES_GET_VIEW"); |
1038 | 1038 |
msgout.serial (rid); |
1039 | 1039 |
msgout.serial (subvarpath.Destination[j].second); |
1040 | 1040 |
CUnifiedNetwork::getInstance ()->send ((*aesit).SId, msgout); |
1041 | 1041 |
nlinfo ("REQUEST: Sent view '%s' to shard name %s 'AES-%hu'", subvarpath.Destination[j].second.c_str(), (*aesit).Name.c_str(), (*aesit).SId.get()); |
1042 |
|
|
1042 |
|
|
1043 | 1043 |
} |
1044 | 1044 |
else if (server == "#") |
1045 | 1045 |
{ |
1046 | 1046 |
vector<string> vara, vala; |
1047 |
|
|
1047 |
|
|
1048 | 1048 |
// adding default row |
1049 | 1049 |
vara.push_back ("shard"); |
1050 | 1050 |
vala.push_back (row[1]); |
... | ... | |
1054 | 1054 |
|
1055 | 1055 |
vara.push_back ("service"); |
1056 | 1056 |
vala.push_back ("AES"); |
1057 |
|
|
1057 |
|
|
1058 | 1058 |
vara.push_back ("State"); |
1059 | 1059 |
vala.push_back ("Offline"); |
1060 |
|
|
1060 |
|
|
1061 | 1061 |
addRequestAnswer (rid, vara, vala); |
1062 | 1062 |
} |
1063 | 1063 |
row = sqlNextRow (); |
... | ... | |
1089 | 1089 |
else if (server == "#") |
1090 | 1090 |
{ |
1091 | 1091 |
vector<string> vara, vala; |
1092 |
|
|
1092 |
|
|
1093 | 1093 |
// adding default row |
1094 | 1094 |
vara.push_back ("shard"); |
1095 | 1095 |
vala.push_back (shard); |
1096 | 1096 |
|
1097 | 1097 |
vara.push_back ("server"); |
1098 | 1098 |
vala.push_back (row[0]); |
1099 |
|
|
1099 |
|
|
1100 | 1100 |
vara.push_back ("service"); |
1101 | 1101 |
vala.push_back ("AES"); |
1102 |
|
|
1102 |
|
|
1103 | 1103 |
vara.push_back ("State"); |
1104 | 1104 |
vala.push_back ("Offline"); |
1105 | 1105 |
|
... | ... | |
1178 | 1178 |
|
1179 | 1179 |
varRequestTimeout (ConfigFile.getVar ("RequestTimeout")); |
1180 | 1180 |
ConfigFile.setCallback("RequestTimeout", &varRequestTimeout); |
1181 |
|
|
1181 |
|
|
1182 | 1182 |
varAdminAlertAccumlationTime (ConfigFile.getVar ("AdminAlertAccumlationTime")); |
1183 | 1183 |
ConfigFile.setCallback("AdmimAlertAccumlationTime", &varAdminAlertAccumlationTime); |
1184 |
|
|
1184 |
|
|
1185 | 1185 |
} |
1186 | 1186 |
|
1187 | 1187 |
bool update () |
1188 | 1188 |
{ |
1189 | 1189 |
cleanRequest (); |
1190 | 1190 |
connectionWebUpdate (); |
1191 |
|
|
1191 |
|
|
1192 | 1192 |
updateSendAdminAlert (); |
1193 | 1193 |
return true; |
1194 | 1194 |
} |
... | ... | |
1251 | 1251 |
NLMISC_COMMAND (generateAlert, "generate an alert", "<text>") |
1252 | 1252 |
{ |
1253 | 1253 |
if(args.size() != 1) return false; |
1254 |
|
|
1254 |
|
|
1255 | 1255 |
sendAdminAlert (args[0].c_str()); |
1256 | 1256 |
|
1257 | 1257 |
return true; |