root / hci / trunk / eneraptor-web-app / grails-app / controllers / com / eneraptor / hci / SysLogController.groovy @ 16
History | View | Annotate | Download (2.95 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 |
/*
|
15 |
* DISK USAGE - ONLY IF ENERAPOTR HCI IS SUPERUSER
|
16 |
*/
|
17 |
def freeSpace = 0 |
18 |
def totalSpace = 0 |
19 |
def percent = 0 |
20 |
/*
|
21 |
def db_sql = new Sql(dataSource)
|
22 |
|
23 |
def single = db_sql.firstRow("show data_directory")
|
24 |
def loca = single.data_directory
|
25 |
def partition = new File(loca)
|
26 |
totalSpace = partition.getTotalSpace()
|
27 |
freeSpace = partition.getFreeSpace()
|
28 |
|
29 |
totalSpace = (int)((totalSpace/1024)/1024)
|
30 |
freeSpace = (int)((freeSpace/1024)/1024)
|
31 |
|
32 |
percent = 100 - ((int) ((freeSpace/totalSpace)*100))
|
33 |
*/
|
34 |
|
35 |
[totalSpace: totalSpace, freeSpace: freeSpace, percent: percent] |
36 |
|
37 |
} |
38 |
|
39 |
def browse = {
|
40 |
|
41 |
flash['warnings'] = null |
42 |
|
43 |
def entries = LoggedData.list()
|
44 |
Map devices = new HashMap() |
45 |
Map icons = new HashMap() |
46 |
List unknownDevices = new ArrayList() |
47 |
DeviceInfo.list().each { |
48 |
devices[it.deviceId] = it.friendlyName |
49 |
if(it.iconPath) { |
50 |
icons[it.deviceId] = it.iconPath |
51 |
} |
52 |
} |
53 |
entries.each { |
54 |
if(!devices[it.deviceId]) { |
55 |
if(!unknownDevices.contains(it.deviceId)) { |
56 |
unknownDevices << it.deviceId
|
57 |
} |
58 |
} |
59 |
} |
60 |
unknownDevices.each { |
61 |
if(!flash['warnings']) flash['warnings'] = "" |
62 |
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>" |
63 |
} |
64 |
|
65 |
[data: entries, devices: devices, icons: icons] |
66 |
|
67 |
} |
68 |
|
69 |
def detail = {
|
70 |
|
71 |
def detailsOf = LoggedData.findById(params.id)
|
72 |
if(!detailsOf) {
|
73 |
flash['errors'] = "<p>There is no logged data with id ${params.id}</p>" |
74 |
redirect(action: 'browse') |
75 |
return false |
76 |
} |
77 |
return detailsOf.getProperties()
|
78 |
} |
79 |
|
80 |
def deleteEntry = {
|
81 |
|
82 |
def entry = LoggedData.findById(params.id)
|
83 |
if(entry) {
|
84 |
entry.delete() |
85 |
flash['confirms'] = "<p>Log entry with id " + params.id + " deleted successfully.</p>" |
86 |
redirect(action: 'browse') |
87 |
} else {
|
88 |
flash['errors'] = "<p>Cannot find log entry with id " + params.id + "</p>" |
89 |
redirect(action: 'browse') |
90 |
} |
91 |
|
92 |
} |
93 |
|
94 |
def graph = {
|
95 |
|
96 |
List devices = new ArrayList() |
97 |
List data = new ArrayList() |
98 |
|
99 |
DeviceInfo.findAllByInputDevice(true).each {
|
100 |
devices << it
|
101 |
} |
102 |
|
103 |
if(params['dataList']) |
104 |
data = params['dataList']
|
105 |
else if(params['deviceId'] && params['fromDate'] && params['tillDate']) { |
106 |
|
107 |
def c = LoggedData.createCriteria()
|
108 |
def results = c {
|
109 |
and { |
110 |
eq("deviceId",params['deviceId']) |
111 |
between("dateRecieved",params['fromDate'],params['tillDate']) |
112 |
} |
113 |
order("dateRecieved","asc") |
114 |
} |
115 |
|
116 |
results.each { |
117 |
data << [it.dateRecieved.getTime(),it.reportedData] |
118 |
} |
119 |
|
120 |
} |
121 |
|
122 |
[data: data, devices: devices, params:params] |
123 |
|
124 |
} |
125 |
|
126 |
} |