-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRegexStartUp.cpp
More file actions
132 lines (125 loc) · 4.09 KB
/
RegexStartUp.cpp
File metadata and controls
132 lines (125 loc) · 4.09 KB
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
// Copyright 2017 Patrick Muldoon
#include <vector>
#include <iostream>
#include <fstream>
#include <string>
#include "intouch.hpp"
int main(int argc, char* argv[]) {
if(argc != 2) {
throw std::runtime_error("Wrong number of arguments.");
std::cout << "Usage " << argv[0] << "logfile" << std::endl;
exit(1);
}
std::string logfile = argv[1];
std::ifstream fin;
fin.open(logfile);
if(fin.fail()) {
std::cerr << "Error opening file " << logfile << std::endl;
exit(1);
}
std::string outfile(argv[1]);
outfile += ".rpt";
std::ofstream fout;
fout.open(outfile.c_str());
if(fout.fail()) {
std::cerr << "Error opening output file" << outfile << std::endl;
exit(1);
}
unsigned int lines_scanned = 0, boots_started = 0, boots_finished = 0;
unsigned int services_started = 0, services_completed = 0;
int count = 0, counter = 0;
std::string line;
std::vector<Intouch> bootups;
std::vector<Softload> softloads;
int size = 0;
while(std::getline(fin, line)) {
++lines_scanned;
if(regex_match(line, StartRegex)) {
++boots_started;
Intouch it(line, logfile, lines_scanned);
bootups.push_back(it);
while(std::getline(fin, line) && count == 0){
++lines_scanned;
if(regex_match(line, ServiceStart)){
++services_started;
Services s(line, logfile, lines_scanned);
bootups.back().a.push_back(s);
}else if(regex_match(line, ServiceSuccess)){
++services_completed;
std::string compare;
boost::smatch sm;
boost::regex_match(line, sm, ServiceSuccess);
compare = sm[1];
for(int i = 0; i < bootups.back().a.size(); ++i){
if(bootups.back().a[i].getServiceName() == compare){
bootups.back().a.at(i).ServiceBoot(line, lines_scanned);
}
}
}else if(regex_match(line, SucceededRegex)) {
++boots_finished;
bootups.back().BootSuccess(line, lines_scanned);
++lines_scanned;
count++;
}
}
} else if(regex_match(line, SoftLoadBegin)){
std::cout << "softload start\n";
Softload soft(line, logfile, lines_scanned);
softloads.push_back(soft);
while(softloads.back().getSuccess() == false){
std::getline(fin, line);
++lines_scanned;
if(regex_match(line, Original)){
softloads.back().Originalver(line);
} else if(regex_match(line, New)){
softloads.back().Newver(line);
} else if(regex_match(line, SoftLoadEnd)){
softloads.back().SoftloadSuccess(line, lines_scanned);
counter++;
}
}
}
count = 0;
}
for(unsigned int j = 0; j < bootups.size()-1; ++j) {
fout << bootups[j] << std::endl;
fout << "Services" << std::endl;
for(unsigned int i = 0; i < bootups[j].a.size(); ++i){
fout << bootups[j].a[i];
}
fout << "\t*** Services not successfully started: ";
for(unsigned int i = 0; i < bootups[j].a.size()-1; ++i){
if(bootups[j].a[i].getSuccess() == false){
fout << bootups[j].a[i].getServiceName();
}
}
if(size < counter){
if(bootups[j].getEndLine() < softloads.at(size).getStartLine()){
fout << std::endl;
fout << "=== Softload ===" << std::endl;
fout << softloads.at(size).getStartLine() << "(" << softloads.at(size).getFileName() << ")"
<< " : " << softloads.at(size).getStartTime() << " Softload Start" << std::endl;
fout << "\tOriginal Version ==> " << softloads.at(size).getOriginal() << std::endl;
fout << "\tNew Version ==> " << softloads.at(size).getNew() << std::endl;
fout << "\tElapsed Time ==> " << std::endl;
fout << softloads.at(size).getEndLine() << "(" << softloads.at(size).getFileName() << ")"
<< " : " << softloads.at(size).getEndTime() << " Softload Completed" << std::endl;
size++;
}
}
fout << std::endl;
}
fout << bootups[bootups.size() - 1] << std::endl;
fout << "Services" << std::endl;
for(unsigned int i = 0; i < bootups[bootups.size() -1].a.size(); ++i){
fout << bootups[bootups.size()-1].a[i];
}
fout << "\t*** Services not successfully started: ";
for(unsigned int i = 0; i < bootups[bootups.size()-1].a.size(); ++i){
if(bootups[bootups.size()-1].a[i].getSuccess() == false){
fout << bootups[bootups.size()-1].a[i].getServiceName();
}
}
fin.close();
fout.close();
}