First version of ATBUpdateCheck
This commit is contained in:
parent
b270a9f30e
commit
3a259f8a22
@ -112,19 +112,23 @@ void IsmasClient::printErrorMessage(int port,
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::optional<QString>
|
std::optional<QString>
|
||||||
IsmasClient::sendRequestReceiveResponse(int port, QString const &request) {
|
IsmasClient::sendRequestReceiveResponse(int port, QString const &request, bool verbose) {
|
||||||
|
|
||||||
|
if (verbose) {
|
||||||
qInfo() << "REQUEST" << request;
|
qInfo() << "REQUEST" << request;
|
||||||
|
}
|
||||||
|
|
||||||
int sockfd;
|
int sockfd;
|
||||||
int r;
|
int r;
|
||||||
errno = 0;
|
errno = 0;
|
||||||
// socket create and verification
|
// socket create and verification
|
||||||
if ((sockfd = ::socket(AF_INET, SOCK_STREAM, 0)) == -1) {
|
if ((sockfd = ::socket(AF_INET, SOCK_STREAM, 0)) == -1) {
|
||||||
|
if (verbose) {
|
||||||
qCritical().noquote()
|
qCritical().noquote()
|
||||||
<< "\n"
|
<< "\n"
|
||||||
<< "SEND-REQUEST-RECEIVE-RESPONSE ..." << "\n"
|
<< "SEND-REQUEST-RECEIVE-RESPONSE ..." << "\n"
|
||||||
<< "SOCKET CREATION FAILED (" << strerror(errno) << ")";
|
<< "SOCKET CREATION FAILED (" << strerror(errno) << ")";
|
||||||
|
}
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,10 +141,12 @@ IsmasClient::sendRequestReceiveResponse(int port, QString const &request) {
|
|||||||
servAddr.sin_port = htons(port);
|
servAddr.sin_port = htons(port);
|
||||||
// connect the client socket to server socket
|
// connect the client socket to server socket
|
||||||
if ((r = ::connect(sockfd, (struct sockaddr *)(&servAddr), sizeof(servAddr))) != 0) {
|
if ((r = ::connect(sockfd, (struct sockaddr *)(&servAddr), sizeof(servAddr))) != 0) {
|
||||||
|
if (verbose) {
|
||||||
qCritical().noquote()
|
qCritical().noquote()
|
||||||
<< "\n"
|
<< "\n"
|
||||||
<< "SEND-REQUEST-RECEIVE-RESPONSE ..." << "\n"
|
<< "SEND-REQUEST-RECEIVE-RESPONSE ..." << "\n"
|
||||||
<< "CONNECTION WITH SERVER FAILED (" << strerror(r) << ")";
|
<< "CONNECTION WITH SERVER FAILED (" << strerror(r) << ")";
|
||||||
|
}
|
||||||
::close(sockfd);
|
::close(sockfd);
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
@ -155,7 +161,9 @@ IsmasClient::sendRequestReceiveResponse(int port, QString const &request) {
|
|||||||
inet_ntop(AF_INET, &clientAddr.sin_addr, clientIP, sizeof(clientIP));
|
inet_ntop(AF_INET, &clientAddr.sin_addr, clientIP, sizeof(clientIP));
|
||||||
unsigned int clientPort = ntohs(clientAddr.sin_port);
|
unsigned int clientPort = ntohs(clientAddr.sin_port);
|
||||||
|
|
||||||
|
if (verbose) {
|
||||||
printDebugMessage(port, clientIP, clientPort, QString("CONNECTED TO SERVER"));
|
printDebugMessage(port, clientIP, clientPort, QString("CONNECTED TO SERVER"));
|
||||||
|
}
|
||||||
|
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
tv.tv_sec = 10; /* 10 secs timeout for read and write */
|
tv.tv_sec = 10; /* 10 secs timeout for read and write */
|
||||||
@ -244,7 +252,9 @@ IsmasClient::sendRequestReceiveResponse(int port, QString const &request) {
|
|||||||
// QString("CANNOT CLOSE WRITING END (") + strerror(errno) + ")");
|
// QString("CANNOT CLOSE WRITING END (") + strerror(errno) + ")");
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
if (verbose) {
|
||||||
printInfoMessage(port, clientIP, clientPort, QString("MESSAGE SENT <<<") + buf + ">>>");
|
printInfoMessage(port, clientIP, clientPort, QString("MESSAGE SENT <<<") + buf + ">>>");
|
||||||
|
}
|
||||||
|
|
||||||
loop = 0;
|
loop = 0;
|
||||||
bzero(buf, sizeof(buf));
|
bzero(buf, sizeof(buf));
|
||||||
@ -325,7 +335,9 @@ IsmasClient::sendRequestReceiveResponse(int port, QString const &request) {
|
|||||||
response = response.mid(0, idx);
|
response = response.mid(0, idx);
|
||||||
} else
|
} else
|
||||||
if (response.contains("RECORD")) { // RECORD SAVED or RECORD WRITE ABORTED
|
if (response.contains("RECORD")) { // RECORD SAVED or RECORD WRITE ABORTED
|
||||||
|
if (verbose) {
|
||||||
printInfoMessage(port, clientIP, clientPort, QString("IGNORED '") + response + "' RESPONSE");
|
printInfoMessage(port, clientIP, clientPort, QString("IGNORED '") + response + "' RESPONSE");
|
||||||
|
}
|
||||||
::close(sockfd);
|
::close(sockfd);
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
@ -334,8 +346,10 @@ IsmasClient::sendRequestReceiveResponse(int port, QString const &request) {
|
|||||||
QJsonDocument document(QJsonDocument::fromJson(response.toUtf8(), &parseError));
|
QJsonDocument document(QJsonDocument::fromJson(response.toUtf8(), &parseError));
|
||||||
if (parseError.error == QJsonParseError::NoError) {
|
if (parseError.error == QJsonParseError::NoError) {
|
||||||
if (document.isObject()) { // done: received valid APISM response
|
if (document.isObject()) { // done: received valid APISM response
|
||||||
|
if (verbose) {
|
||||||
printInfoMessage(port, clientIP, clientPort,
|
printInfoMessage(port, clientIP, clientPort,
|
||||||
QString("VALID APISM RESPONSE .. \n") + response);
|
QString("VALID APISM RESPONSE .. \n") + response);
|
||||||
|
}
|
||||||
::close(sockfd);
|
::close(sockfd);
|
||||||
return response;
|
return response;
|
||||||
} else {
|
} else {
|
||||||
|
@ -37,7 +37,7 @@ public:
|
|||||||
static char const *reason[REASON::ENTRIES];
|
static char const *reason[REASON::ENTRIES];
|
||||||
|
|
||||||
static std::optional<QString>
|
static std::optional<QString>
|
||||||
sendRequestReceiveResponse(int port, QString const &request);
|
sendRequestReceiveResponse(int port, QString const &request, bool verbose=false);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static void printDebugMessage(int port, QString const &clientIP, int clientPort,
|
static void printDebugMessage(int port, QString const &clientIP, int clientPort,
|
||||||
|
112
Check/main.cpp
112
Check/main.cpp
@ -9,8 +9,18 @@
|
|||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
#include "commandline_parser.h"
|
#include <QJsonDocument>
|
||||||
|
#include <QJsonObject>
|
||||||
|
#include <QJsonValue>
|
||||||
|
#include <QRegularExpression>
|
||||||
|
#include <QFile>
|
||||||
|
#include <QTextStream>
|
||||||
|
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
#include "message_handler.h"
|
#include "message_handler.h"
|
||||||
|
#include "ismas_client.h"
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
QByteArray const value = qgetenv("LC_ALL");
|
QByteArray const value = qgetenv("LC_ALL");
|
||||||
@ -18,9 +28,6 @@ int main(int argc, char **argv) {
|
|||||||
qputenv("LC_ALL", "C");
|
qputenv("LC_ALL", "C");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// qputenv("XDG_RUNTIME_DIR", "/var/run/user/0");
|
|
||||||
|
|
||||||
openlog("ATB-UPDATE_CHECK", LOG_PERROR | LOG_PID | LOG_CONS, LOG_USER);
|
openlog("ATB-UPDATE_CHECK", LOG_PERROR | LOG_PID | LOG_CONS, LOG_USER);
|
||||||
|
|
||||||
QCoreApplication a(argc, argv);
|
QCoreApplication a(argc, argv);
|
||||||
@ -36,15 +43,106 @@ int main(int argc, char **argv) {
|
|||||||
QCommandLineParser parser;
|
QCommandLineParser parser;
|
||||||
QCommandLineOption ismasConnectOption("ismas-connected");
|
QCommandLineOption ismasConnectOption("ismas-connected");
|
||||||
QCommandLineOption updateRequestedOption("update-requested");
|
QCommandLineOption updateRequestedOption("update-requested");
|
||||||
|
QCommandLineOption verboseOption("verbose");
|
||||||
parser.addOption(ismasConnectOption);
|
parser.addOption(ismasConnectOption);
|
||||||
parser.addOption(updateRequestedOption);
|
parser.addOption(updateRequestedOption);
|
||||||
|
parser.addOption(verboseOption);
|
||||||
parser.process(a);
|
parser.process(a);
|
||||||
|
|
||||||
if (parser.isSet(ismasConnectOption)) {
|
QString connectionStatus{"not connected"};
|
||||||
qCritical() << parser.isSet(ismasConnectOption);
|
QString updateRequestStatus{"not requested"};
|
||||||
|
|
||||||
|
if (std::optional<QString> result
|
||||||
|
= IsmasClient::sendRequestReceiveResponse(
|
||||||
|
IsmasClient::APISM::DIRECT_PORT,
|
||||||
|
"#M=APISM#C=REQ_SELF#J={}")) {
|
||||||
|
QJsonDocument d = QJsonDocument::fromJson(result.value().toUtf8());
|
||||||
|
for (QString const &k : d.object().keys()) {
|
||||||
|
if (k.contains("CMD_GET_APISMSTATUS_RESPONSE")) {
|
||||||
|
QJsonObject o = d.object()[k].toObject();
|
||||||
|
QJsonObject::const_iterator it = o.find("Broker");
|
||||||
|
if (it != o.constEnd()) {
|
||||||
|
// value for "Broker"
|
||||||
|
QString const &v = it->toString();
|
||||||
|
if (v.contains("connected", Qt::CaseInsensitive)) {
|
||||||
|
connectionStatus = "connected";
|
||||||
} else
|
} else
|
||||||
|
if (v.contains("not connected", Qt::CaseInsensitive)) {
|
||||||
|
connectionStatus = "not connected";
|
||||||
|
} else
|
||||||
|
if (v.contains("disconnected", Qt::CaseInsensitive)) {
|
||||||
|
connectionStatus = "not connected";
|
||||||
|
} else
|
||||||
|
if (v.contains("connecting", Qt::CaseInsensitive)) {
|
||||||
|
connectionStatus = "not connected";
|
||||||
|
} else
|
||||||
|
if (v.contains("disconnecting", Qt::CaseInsensitive)) {
|
||||||
|
connectionStatus = "not connected";
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (parser.isSet(updateRequestedOption)) {
|
if (parser.isSet(updateRequestedOption)) {
|
||||||
qCritical() << parser.isSet(updateRequestedOption);
|
if (connectionStatus == "connected") {
|
||||||
|
if (std::optional<QString> result
|
||||||
|
= IsmasClient::sendRequestReceiveResponse(
|
||||||
|
IsmasClient::APISM::DIRECT_PORT,
|
||||||
|
"#M=APISM#C=REQ_ISMASPARAMETER#J={}")) {
|
||||||
|
|
||||||
|
QJsonDocument d = QJsonDocument::fromJson(result.value().toUtf8());
|
||||||
|
for (QString const &k : d.object().keys()) {
|
||||||
|
if (k.contains("REQ_ISMASPARAMETER")) {
|
||||||
|
QJsonObject o = d.object()[k].toObject();
|
||||||
|
|
||||||
|
QJsonObject::const_iterator it = o.find("Aknoledge");
|
||||||
|
if (it == o.constEnd()) continue;
|
||||||
|
|
||||||
|
QString const &v = it->toString();
|
||||||
|
if (v != "OK") break;
|
||||||
|
|
||||||
|
for (QString const &k : d.object().keys()) { // request ack
|
||||||
|
if (!k.contains("FileUpload", Qt::CaseInsensitive)) continue;
|
||||||
|
QJsonObject o = d.object()[k].toObject();
|
||||||
|
|
||||||
|
QJsonObject::const_iterator it = o.find("TRG");
|
||||||
|
if (it == o.constEnd()) break;
|
||||||
|
|
||||||
|
QString const &v = it->toString();
|
||||||
|
if (v == "WAIT") {
|
||||||
|
updateRequestStatus = "requested";
|
||||||
|
} else
|
||||||
|
if (v.isEmpty()) {
|
||||||
|
QFile f("/mnt/system_data/cust_nr");
|
||||||
|
if (!f.exists()) break;
|
||||||
|
if (!f.open(QIODevice::ReadOnly | QIODevice::Text)) break;
|
||||||
|
|
||||||
|
QTextStream in(&f);
|
||||||
|
in.setCodec("UTF-8");
|
||||||
|
if(!in.atEnd()) {
|
||||||
|
unsigned custNr = in.readLine().toInt();
|
||||||
|
if (custNr > 0) {
|
||||||
|
QString custRepo = QString("/opt/app/tools/atbupdate/customer_%1").arg(custNr);
|
||||||
|
if (!QDir(custRepo).exists()) {
|
||||||
|
updateRequestStatus = "not necessary";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
qCritical() << updateRequestStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (parser.isSet(ismasConnectOption)) {
|
||||||
|
qCritical() << connectionStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -197,7 +197,8 @@ Worker::Worker(int customerNr,
|
|||||||
// check ISMAS connectivity
|
// check ISMAS connectivity
|
||||||
m_workList.push_back(
|
m_workList.push_back(
|
||||||
std::make_unique<CheckIsmasConnectivityCommand>(
|
std::make_unique<CheckIsmasConnectivityCommand>(
|
||||||
QString("echo CheckIsmasConnectivityCommand")
|
//QString("echo CheckIsmasConnectivityCommand")
|
||||||
|
QString("/opt/app/tools/atbupdate/ATBUpdateCheck --ismas-connected")
|
||||||
, this));
|
, this));
|
||||||
|
|
||||||
// check if update activated in ISMAS
|
// check if update activated in ISMAS
|
||||||
|
Loading…
x
Reference in New Issue
Block a user