Добавлен парсер квот

pull/3/head
Igor Belitskiy 2 years ago
parent 61a401c9e9
commit 68426f9c7e

@ -2,6 +2,7 @@
#define MY_TYPE_H #define MY_TYPE_H
#include "project_lib.h" #include "project_lib.h"
#include <string>
using namespace std; using namespace std;
@ -45,7 +46,18 @@ struct status_quotas {
bool project; bool project;
bool status; bool status;
}; };
struct data_all_quotas {
string username;
string status;
string block_used;
string block_soft;
string block_hard;
string block_grace;
string file_used;
string file_soft;
string file_hard;
string file_grace;
};
typedef struct users_grups USER_GRUPS; typedef struct users_grups USER_GRUPS;
typedef map <string, string> map_str_str; typedef map <string, string> map_str_str;

@ -1,4 +1,5 @@
#include "system_cmd_quotas.h" #include "system_cmd_quotas.h"
#include "my_type.h"
namespace Quotas_sys { namespace Quotas_sys {
Quotas_sys::Quotas_sys() { Quotas_sys::Quotas_sys() {
@ -158,31 +159,75 @@ bool Quotas_sys::off_quota_system(string partition, string quota_hw, string quot
} }
void Quotas_sys::pars_data(string cmd) { vector<data_all_quotas> Quotas_sys::pars_data(string cmd) {
string start_pars = "------\n"; string start_pars = "------\n";
string response = obj_process_call.call_all_sections(cmd); string response = obj_process_call.call_all_sections(cmd);
size_t index_start = response.find(start_pars); size_t index_start = response.find(start_pars);
string line_pars = ""; string line_pars = "";
struct data_all_quotas struct_data;
vector<data_all_quotas> vec_struct_data;
int index = 0; int index = 0;
int old_index = index; int old_index = index;
if (index_start != string::npos) { if (index_start != string::npos) {
response = response.substr(index_start+start_pars.length(), response.length()); response = response.substr(index_start+start_pars.length(), response.length());
vector<int> vec_index_sep = Utils::find_all(response, "\n"); vector<int> vec_index_sep = Utils::find_all(response, "\n");
cout << response.substr(0, vec_index_sep[0]) << endl;
for (size_t i = 0; i < vec_index_sep.size(); i++) { for (size_t i = 0; i < vec_index_sep.size(); i++) {
old_index = index; old_index = index;
index = vec_index_sep[i]; index = vec_index_sep[i];
if (index-1 == old_index) { if (index-1 == old_index) {
break; break;
} }
line_pars = line_pars.substr(old_index, index); line_pars = response.substr(old_index, index);
part_quotas_line(line_pars); struct_data = part_quotas_line(line_pars);
vec_struct_data.push_back(struct_data);
} }
} }
} }
struct status_quotas part_quotas_line(string line) {
vector<int> vec_index_sep = Utils::find_all(response, "\t"); struct data_all_quotas Quotas_sys::part_quotas_line(string line) {
cout << vec_index_sep.size() << endl; struct data_all_quotas struct_data;
vector<int> vec_index_sep = Utils::find_all(line, " ");
int old_index = 0;
string buff = "";
int index_data = 0;
for (int& index: vec_index_sep) {
if ((index - old_index) >= 2) {
buff = line.substr(old_index, index - old_index);
if (index_data == 0) {
struct_data.username = buff;
}
else if (index_data == 1) {
struct_data.status = buff;
}
else if (index_data == 2) {
struct_data.block_used = buff;
}
else if (index_data == 3) {
struct_data.block_soft = buff;
}
else if (index_data == 4) {
struct_data.block_hard = buff;
}
else if (index_data == 5) {
struct_data.block_grace = buff;
}
else if (index_data == 6) {
struct_data.file_used = buff;
}
else if (index_data == 7) {
struct_data.file_soft = buff;
}
else if (index_data == 8) {
struct_data.file_hard = buff;
}
else if (index == 9) {
struct_data.file_grace = buff;
}
index_data += 1;
}
old_index = index;
}
return struct_data;
} }
} }

@ -24,9 +24,9 @@ class Quotas_sys {
struct status_quotas check_on_quotas_system_2_hw(string params); struct status_quotas check_on_quotas_system_2_hw(string params);
bool on_quota_hw(string partition, string cmd_hw, string cmd_sw); bool on_quota_hw(string partition, string cmd_hw, string cmd_sw);
bool on_quota_sw(string partition, int mode); bool on_quota_sw(string partition, int mode);
void pars_data(string cmd); vector<data_all_quotas> pars_data(string cmd);
protected: protected:
struct status_quotas part_quotas_line(string line); struct data_all_quotas part_quotas_line(string line);
}; };
} }
#endif #endif
Loading…
Cancel
Save