ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/host/c++/Host.cpp
(Generate patch)

Comparing projects/cms/source/host/c++/Host.cpp (file contents):
Revision 1.1 by ab11, Mon Feb 26 14:59:04 2001 UTC vs.
Revision 1.3 by ab11, Tue Mar 6 00:40:28 2001 UTC

# Line 1 | Line 1
1   #include <iostream.h>
2   #include <unistd.h> // linux header for the sleep function
3 + #include <stdlib.h> // itoa()
4   #include <time.h>
5   #include "SysMon.h"
6   // #include "Config.h" - redefinition error - turns out i don't need it
# Line 14 | Line 15 | int main(){
15          
16          // list of local variables
17          int noErrors = 1;
18 +        int reloadConfig = 0;
19          
20          // print some extra info..
21          int debug = 0;
# Line 23 | Line 25 | int main(){
25          std::cout << "C Host starting..\n";
26          
27          std::cout << "Attemping to load config\n";
28 <        Config config("killigrew.ukc.ac.uk",4567,debug);                // host, port, debug (0/1)
28 >        Config config("raptor.ukc.ac.uk",4567,debug);           // host, port, debug (0/1)
29          
30          std::cout << "Creating data collector\n";
31          SysMon sysMon(config, debug);
# Line 37 | Line 39 | int main(){
39                  } // if
40          } // if
41                          
42 +                        
43          std::cout << "Configuring TCPUpdateTime\n";
44          int TCPUpdateTime = config.getIntProperty("TCPUpdateTime");
45          if ( TCPUpdateTime  == -1){
# Line 55 | Line 58 | int main(){
58                  AveragerUpdateTime = 2;
59          } // if
60          
61 +        std::cout << "Configuring Filter Retry Tolerances\n";
62 +        int MaxFilterRetrys = config.getIntProperty("MAXTCPFilterRetries");
63 +        if ( MaxFilterRetrys == -1){
64 +                if ( debug == 1 ){
65 +                        std::cout << "Using Default Tolerance\n";
66 +                } // if
67 +                MaxFilterRetrys = 5;
68 +        } // if
69 +        
70 +        
71          std::cout << "Configuring Alerter\n";
72          // Set the values at which the Alerter should kick in. and how many packets it should
73          // send
74          
75          // now do the data collection
76          
77 +        std::cout << "Starting Data Collection\n";
78          // work out which is closer, the next heartbeat or the next data collection
79          int localTime = time(NULL);
80 <        std::cout << "#";
80 >        // std::cout << "#";
81          int nextUDPTime = localTime + UDPUpdateTime;
82          int nextAveragerTime = localTime + AveragerUpdateTime;
83          int nextTCPTime = localTime + TCPUpdateTime;
84          int sequence = 0;
85 <        
85 >                
86          int nextAction = 0;
87          while ( noErrors == 1){
88 <                std::cout << ".";
88 >                // firstly check we haven't got to reload our config
89 >                if ( reloadConfig == 1 ){
90 >                        // reload the config by starting a new
91 >                        std::cout << "Forcing reload of Configuration\n";
92 >                        config = Config("raptor.ukc.ac.uk",4567,debug);
93 >                        
94 >                        std::cout << "Configuring UDPUpdateTime\n";
95 >                        int UDPUpdateTime = config.getIntProperty("UDPUpdateTime");
96 >                        if (  UDPUpdateTime == -1 ){
97 >                                if ( debug == 1 ){
98 >                                        std::cout << "Using Default time!\n";
99 >                                        UDPUpdateTime = 5;
100 >                                } // if
101 >                        } // if
102 >                                        
103 >                                        
104 >                        std::cout << "Configuring TCPUpdateTime\n";
105 >                        int TCPUpdateTime = config.getIntProperty("TCPUpdateTime");
106 >                        if ( TCPUpdateTime  == -1){
107 >                                if ( debug == 1 ){
108 >                                        std::cout << "Using Default time!\n";
109 >                                        TCPUpdateTime = 10;
110 >                                } // if
111 >                        } // if
112 >                        
113 >                        std::cout << "Configuring AveragerUpdateTime\n";
114 >                        int AveragerUpdateTime = config.getIntProperty("AVERAGERUpdateTime");
115 >                        if ( AveragerUpdateTime == -1){
116 >                                if ( debug == 1 ){
117 >                                        std::cout << "Using Default time!\n";
118 >                                } // if
119 >                                AveragerUpdateTime = 2;
120 >                        } // if
121 >                        
122 >                        std::cout << "Configuring Filter Retry Tolerances\n";
123 >                        int MaxFilterRetrys = config.getIntProperty("MAXTCPFilterRetries");
124 >                        if ( MaxFilterRetrys == -1){
125 >                                if ( debug == 1 ){
126 >                                        std::cout << "Using Default Tolerance\n";
127 >                                } // if
128 >                                MaxFilterRetrys = 5;
129 >                        } // if
130 >                        // reloadConfig is done now
131 >                        reloadConfig = 0;
132 >                } // if reloadconfig
133 >                
134 >                
135 >                
136 >                localTime = time(NULL);
137 >                //  std::cout << ".";
138                  // keep going while no non-fatal errors have occurred
139                  int waitTime = 0;
140                  
141                  if ( nextTCPTime  <= nextAveragerTime ){
142 <                        std::cout << "-";
142 >                        // std::cout << "-";
143                          if ( nextTCPTime >= nextUDPTime ){
144 <                                std::cout << "}";
144 >                                // std::cout << "}";
145                                  nextAction = 3;
146 <                                waitTime = nextUDPTime - time(NULL);
146 >                                waitTime = nextUDPTime - localTime;
147                          } else {
148                                  // set the heartbeat to be the next item
149 <                                std::cout << "{";
149 >                                // std::cout << "{";
150                                  nextAction = 1;
151 <                                waitTime = nextTCPTime - time(NULL);
151 >                                waitTime = nextTCPTime - localTime;
152                          } // if
153                  } else {
154 <                        std::cout << "+";
154 >                        // std::cout << "+";
155                          if ( nextAveragerTime >=  nextUDPTime ){
156 <                                std::cout << "[";
156 >                                // std::cout << "[";
157                                  nextAction = 3;
158 <                                waitTime = nextUDPTime - time(NULL);
158 >                                waitTime = nextUDPTime - localTime;
159                          } else {
160                                  // set grabstats to be in the next action
161 <                                std::cout << "]";
161 >                                // std::cout << "]";
162                                  nextAction = 2;
163 <                                waitTime = nextAveragerTime - time(NULL);
163 >                                waitTime = nextAveragerTime - localTime;
164                          } // if
165                  } // if
166                  
167                  // sleep until this time only if it is greater than 1!
168                  if ( waitTime >= 1 ){
106                        // need to output \n to std::cout or the wait is infinate!!!! ?????
107                        std::cout << "_\n";
169                          sleep(waitTime); /// crashes here
170 <                        std::cout << "_";
170 >                        
171                  }
172                  
173 <                std::cout << "~";
173 >                
174                  localTime = time(NULL);
175 +                int con = -1;
176 +                int conCount = 0;
177 +                
178                  // do the action
179                  switch (nextAction){
180 <                        case 1: std::cout << "T";
180 >                        case 1: std::cout << "Scheduled TCP Heartbeat Connection" << endl;
181                                  nextTCPTime = localTime + TCPUpdateTime;
182 <                                // SmallNet * net = config.getSmallNet();
183 <                                // net->connectHeartBeat(config.getFilterName(),config.getFilterPort());
182 >                                // connect to the filter - should do all the talking within config.
183 >                                con = (config.getSmallNet())->connectHeartBeat(config.getUDPFilterName(), config.getFilterPort());                            
184 >                                conCount = 0;
185 >                                while (( con != 0 ) && ( conCount < MaxFilterRetrys )){
186 >                                        int con = (config.getSmallNet())->connectHeartBeat(config.getUDPFilterName(), config.getFilterPort());                          
187 >                                        conCount++;
188 >                                }
189 >                                // if con != 0, then we must reconnect to the main filter manager and
190 >                                // reload our config!
191 >                                if ( con == 0 ){
192 >                                        // run the chat script
193 >                                        int result = config.chatHeartBeat();
194 >                                        if ( result != 0 ){
195 >                                                // gotta reload our config
196 >                                                reloadConfig = 1;
197 >                                        } // if
198 >                                } else {
199 >                                        // set the config to be reloaded next time
200 >                                        reloadConfig = 1;
201 >                                } // if con =!= 0
202 >                                
203                                  break;
204 <                        case 2: std::cout << "A";  
122 <                                nextAveragerTime = localTime + AveragerUpdateTime;
204 >                        case 2: nextAveragerTime = localTime + AveragerUpdateTime;
205                                  if ( sysMon.collect() > 0 ){
206                                          // suggests that there should be an alert
207 <                                        
207 >                                        std::cout << "Alert Status" << endl;                                    
208                                  }
209                                  break;
210 <                        default: std::cout << "U";
210 >                        default: std::cout << "Scheduled UDP Connection" << endl;
211                                   nextUDPTime = localTime + UDPUpdateTime;
212                                   // package up the system data
213 <                                 /// lovely HARD CODING!!!!
214 <                                 string h1 = "raptor.ukc.ac.uk";
215 <                                 string ip1 = "129.12.4.232";
216 <                                 string date1 = "00000001";
217 <                                 string seq = "-64773929";
218 <                                                                
219 <                                 string attributes = "type=\"data\" machine_name=\""+h1+"\" ip=\""+ip1+"\" date=\""+date1+"\" seq_no=\""+seq+"\"";
213 >                                 string host = (config.getSmallNet())->getHostName();
214 >                                 string ip = (config.getSmallNet())->getHostIP();
215 >                                
216 >                                 string seq = "";
217 >                                 // char * buffer;
218 >                                 char buffer[32];
219 >                                 sprintf(buffer,"%u", sequence);
220 >                                 seq = buffer;
221 >                                 string date = "";
222 >                                 sprintf(buffer,"%u", localTime);
223 >                                 date = buffer;
224 >                         string attributes = "type=\"data\" machine_name=\""+host+"\" ip=\""+ip+"\" date=\""+date+"\" seq_no=\""+seq+"\"";
225  
226                                   XMLFormatter xml("packet",attributes);
227                                   // put in the data
228                                   xml.addString(sysMon.getData());
229                                   (config.getSmallNet())->sendUPDPacket(config.getUDPFilterName(), config.getUDPFilterPort(), xml.returnXML());
230 <                                
230 >                                 sequence++;
231                                   break;
232                  } // switch
233                  
# Line 148 | Line 235 | int main(){
235          
236          std::cout << "A fatal error occurred which caused this program to quit\n";
237          std::cout << "It is suggested that all belly button lint should be removed\n";
238 <        std::cout << "prior to use of this program";
238 >        std::cout << "prior to use of this program\n";
239 >        std::cout << "Oh and BTW, All you BASE are belong to us!\n";
240          std::cout << "Error Code: " << noErrors << "\n";
241          
242          return 0;
243          
244 < } // main
244 > } // main

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines