Add progress notify

This commit is contained in:
kradchen
2023-09-12 09:53:30 +08:00
parent 1e6dfaf212
commit b2721db958
12 changed files with 118 additions and 25 deletions

View File

@@ -2,14 +2,17 @@
#include "spdlog/sinks/stdout_color_sinks.h"
#include "spdlog/sinks/basic_file_sink.h"
#include "spdlog/spdlog.h"
std::shared_ptr<spdlog::logger> getLogger(const char* title)
std::shared_ptr<spdlog::logger> getLogger(const char* title,const char * output)
{
auto console_sink = std::make_shared<spdlog::sinks::stdout_color_sink_mt>();
console_sink->set_level(spdlog::level::info);
console_sink->set_pattern(fmt::format("[%Y-%m-%d %T .%f][{}] [%^%l%$] %v", title));
std::shared_ptr<spdlog::logger> logger(new spdlog::logger(title, {console_sink}));
auto file_sink = std::make_shared<spdlog::sinks::basic_file_sink_mt>(fmt::format("{0}/log.log", output));
file_sink->set_level(spdlog::level::info);
file_sink->set_pattern(fmt::format("[%Y-%m-%d %T .%f][{}] [%^%l%$] %v", title));
std::shared_ptr<spdlog::logger> logger(new spdlog::logger(title, {console_sink,file_sink}));
logger->set_level(spdlog::level::info);
logger->flush_on(spdlog::level::info);
return logger;

View File

@@ -1,6 +1,9 @@
#ifndef __LOG_H__
#define __LOG_H__
#include "spdlog/spdlog.h"
std::shared_ptr<spdlog::logger> getLogger(const char* title);
std::shared_ptr<spdlog::logger> getLogger(const char* title,const char * output);
#define RECON_TRACE(...) SPDLOG_TRACE( __VA_ARGS__)
@@ -9,3 +12,5 @@ std::shared_ptr<spdlog::logger> getLogger(const char* title);
#define RECON_INFO(...) SPDLOG_INFO(__VA_ARGS__)
#define RECON_ERROR(...) SPDLOG_ERROR( __VA_ARGS__)
#endif // __LOG_H__

36
src/log/notify.cpp Normal file
View File

@@ -0,0 +1,36 @@
#include "notify.h"
#include "Request.h"
#include "log/log.h"
namespace Recon {
std::string ReconID;
Req::Request req;
bool notifyStart(const std::string& aReconID ){
ReconID = aReconID;
Req::Request::Init();
req.setClientCertificate("/home/krad/workdir/ReconTester/client.crt","/home/krad/workdir/ReconTester/client.key");
std::string str = "{\"ReconID\": \""+ReconID+"\"}";
std::unordered_map<std::string, std::string> headers;
headers["Content-Type"] = "application/json";
auto resp = req.post("https://127.0.0.1:5002/Task/Start/",str,headers);
return resp->httpCode() == 200;
}
bool notifyFinish(){
std::string str = "{\"ReconID\": \""+ReconID+"\"}";
std::unordered_map<std::string, std::string> headers;
headers["Content-Type"] = "application/json";
auto resp = req.post("https://127.0.0.1:5002/Task/Finish/",str,headers);
Req::Request::Dispose();
return resp->httpCode() == 200;
}
bool notifyProgress( int percent){
char buffer[2048] = {0};
sprintf(buffer, "https://192.168.1.15:5003/Task/Notify/%d/", percent);
std::string str = "{\"ReconID\": \""+ReconID+"\"}";
std::unordered_map<std::string, std::string> headers;
headers["Content-Type"] = "application/json";
auto resp = req.post(buffer,str,headers);
return resp->httpCode() == 200;
}
}

9
src/log/notify.h Normal file
View File

@@ -0,0 +1,9 @@
#ifndef __NOTIFY_H__
#define __NOTIFY_H__
#include <string>
namespace Recon {
bool notifyStart(const std::string& aReconID );
bool notifyFinish();
bool notifyProgress(int percent);
}
#endif // __NOTIFY_H__