root / hci / trunk / eneraptor-web-app / grails-app / controllers / com / eneraptor / hci / SysLogController.groovy @ 11
History | View | Annotate | Download (2.83 KB)
1 |
package com.eneraptor.hci
|
---|---|
2 |
|
3 |
import groovy.sql.* |
4 |
import java.sql.* |
5 |
|
6 |
class SysLogController { |
7 |
|
8 |
def dataSource
|
9 |
|
10 |
def index = { }
|
11 |
|
12 |
def main = {
|
13 |
|
14 |
def db_sql = new Sql(dataSource) |
15 |
|
16 |
def single = db_sql.firstRow("show data_directory") |
17 |
def loca = single.data_directory
|
18 |
def partition = new File(loca) |
19 |
def totalSpace = partition.getTotalSpace()
|
20 |
def freeSpace = partition.getFreeSpace()
|
21 |
|
22 |
totalSpace = (int)((totalSpace/1024)/1024) |
23 |
freeSpace = (int)((freeSpace/1024)/1024) |
24 |
|
25 |
def percent = 100 - ((int) ((freeSpace/totalSpace)*100)) |
26 |
|
27 |
[totalSpace: totalSpace, freeSpace: freeSpace, percent: percent] |
28 |
|
29 |
} |
30 |
|
31 |
def browse = {
|
32 |
|
33 |
flash['warnings'] = null |
34 |
|
35 |
def entries = LoggedData.list()
|
36 |
Map devices = new HashMap() |
37 |
Map icons = new HashMap() |
38 |
List unknownDevices = new ArrayList() |
39 |
DeviceInfo.list().each { |
40 |
devices[it.deviceId] = it.friendlyName |
41 |
if(it.iconPath) { |
42 |
icons[it.deviceId] = it.iconPath |
43 |
} |
44 |
} |
45 |
entries.each { |
46 |
if(!devices[it.deviceId]) { |
47 |
if(!unknownDevices.contains(it.deviceId)) { |
48 |
unknownDevices << it.deviceId
|
49 |
} |
50 |
} |
51 |
} |
52 |
unknownDevices.each { |
53 |
if(!flash['warnings']) flash['warnings'] = "" |
54 |
flash['warnings'] += "<p>There was found at least one log entry for a device with id <b>${it}</b>, which is <b>unknown</b> to HCI. You should <b>add this device</b> by <b>" + g.link(controller: 'config', action: 'addDevice', params: ['deviceId' : it], "clicking here") + "</b>.</p>" |
55 |
} |
56 |
|
57 |
[data: entries, devices: devices, icons: icons] |
58 |
|
59 |
} |
60 |
|
61 |
def detail = {
|
62 |
|
63 |
def detailsOf = LoggedData.findById(params.id)
|
64 |
if(!detailsOf) {
|
65 |
flash['errors'] = "<p>There is no logged data with id ${params.id}</p>" |
66 |
redirect(action: 'browse') |
67 |
return false |
68 |
} |
69 |
return detailsOf.getProperties()
|
70 |
} |
71 |
|
72 |
def deleteEntry = {
|
73 |
|
74 |
def entry = LoggedData.findById(params.id)
|
75 |
if(entry) {
|
76 |
entry.delete() |
77 |
flash['confirms'] = "<p>Log entry with id " + params.id + " deleted successfully.</p>" |
78 |
redirect(action: 'browse') |
79 |
} else {
|
80 |
flash['errors'] = "<p>Cannot find log entry with id " + params.id + "</p>" |
81 |
redirect(action: 'browse') |
82 |
} |
83 |
|
84 |
} |
85 |
|
86 |
def graph = {
|
87 |
|
88 |
List devices = new ArrayList() |
89 |
List data = new ArrayList() |
90 |
|
91 |
DeviceInfo.findAllByInputDevice(true).each {
|
92 |
devices << it
|
93 |
} |
94 |
|
95 |
if(params['dataList']) |
96 |
data = params['dataList']
|
97 |
else if(params['deviceId'] && params['fromDate'] && params['tillDate']) { |
98 |
|
99 |
def c = LoggedData.createCriteria()
|
100 |
def results = c {
|
101 |
and { |
102 |
eq("deviceId",params['deviceId']) |
103 |
between("dateRecieved",params['fromDate'],params['tillDate']) |
104 |
} |
105 |
order("dateRecieved","asc") |
106 |
} |
107 |
|
108 |
results.each { |
109 |
data << [it.dateRecieved.getTime(),it.reportedData] |
110 |
} |
111 |
|
112 |
} |
113 |
|
114 |
[data: data, devices: devices, params:params] |
115 |
|
116 |
} |
117 |
|
118 |
} |