/[H9]/trunk/tntnet/dynamic/critical.ecpp
ViewVC logotype

Diff of /trunk/tntnet/dynamic/critical.ecpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 68 by torben, Tue Nov 27 14:28:59 2007 UTC revision 159 by torben, Wed Dec 5 14:39:35 2007 UTC
# Line 1  Line 1 
1    <%pre>
2    #include <tntdb/connect.h>
3    #include <tntdb/connection.h>
4    #include <tntdb/result.h>
5    #include <tntdb/row.h>
6    
7    </%pre>
8    
9  <%config>  <%config>
10  dburl;  dburl;
11  </%config>  </%config>
12    
13  <&header title="Critical systems">  <&header title="Critical systems">
14  </&header>  </&header>
15    <h2>Critical systems</h2>
16    
17    <{
18    
19    reply.setHeader("Refresh", "120");
20    
21    tntdb::Connection conn = tntdb::connect(dburl);
22    
23    
24    std::string query1;
25    query1 += "SELECT c.name, i.description, i.id, i.commerror ";
26    query1 += "FROM installation i INNER JOIN customer c ";
27    query1 += "ON i.customerid = c.id";
28    
29    
30    tntdb::Result inst_res = conn.select(query1);
31    
32    
33    std::string query2;
34    query2 += "SELECT temperature,flamedetector,conveyorerror,powerfailure ";
35    query2 += "FROM logtable ";
36    query2 += "WHERE installationnr = :v1 ";
37    query2 += "ORDER BY messagenr DESC,logtime DESC ";
38    query2 += "LIMIT 1";
39    
40    
41    tntdb::Statement st = conn.prepare(query2);
42    
43    std::ostream& out = reply.out();
44    
45    bool hasCritical = false;
46    
47    for (unsigned i=0; i<inst_res.size(); i++)
48    {
49            int id = inst_res[i].getInt(2);
50            st.clear();
51    
52            st.setInt("v1", id);
53            tntdb::Result res = st.select();
54    
55            bool commerror = inst_res[i].getBool(3);
56            int temperature = 50;
57            bool flameDetector = true;
58            bool conveyorError = false;
59            bool powerFailure = false;
60    
61            if (res.size() > 0)
62            {
63                    temperature = res[0].getInt(0);
64                    flameDetector = res[0].getBool(1);
65                    conveyorError = res[0].getBool(2);
66                    powerFailure = res[0].getBool(3);
67            }
68    
69            if (commerror || temperature > 90 || flameDetector == false || conveyorError || powerFailure)
70            {
71                    out << "<a href='installationdetails?id=" << id << "'><b>" << inst_res[i].getString(0) << "</b> : " << inst_res[i].getString(1) << "<br></a>\n";
72                    out << "<ul>";
73    
74                    if (temperature > 90)
75                            out << "<li>High temperature</li>\n";
76    
77                    if (commerror)
78                            out << "<li>Communication error</li>\n";
79    
80                    if (flameDetector == false)
81                            out << "<li>No flames</li>\n";
82    
83                    if (conveyorError)
84                            out << "<li>Conveyor error</li>\n";
85    
86                    if (powerFailure)
87                            out << "<li>Power failure</li>\n";
88    
89                    out << "</ul>\n";
90    
91                    hasCritical = true;
92            }
93    }
94    
95    if (hasCritical == false)
96    {
97            out << "<i>No critical installations found</i>\n";
98    }
99    
100  <$ dburl $>  }>
101    
102  <&footer>  <&footer>
103  </&footer>  </&footer>

Legend:
Removed from v.68  
changed lines
  Added in v.159

  ViewVC Help
Powered by ViewVC 1.1.20