-
Notifications
You must be signed in to change notification settings - Fork 0
/
plant.py
executable file
·1645 lines (1265 loc) · 43.2 KB
/
plant.py
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
from __future__ import division
import os
import shutil
import datetime
import time
import log
import urllib
import urllib2
import hashlib
import socket
from iniparser import IniParser
def get_hash(f):
log.log('get_hash function called')
input = open(f, 'rb')
md5 = hashlib.md5()
buffer = input.read(2 ** 20)
while buffer:
md5.update(buffer)
buffer = input.read(2 ** 20)
#endwhile
input.close()
return md5.hexdigest()
#enddef
def isfile(fn):
t = './temp'
log.log('asking for %s' % fn)
for d in sorted(os.listdir(t)):
if os.path.isfile('%s/%s/%s' % (t, d, fn)): return '%s/%s/%s' % (t, d, fn)
#endfor
log.log('no %s' % fn)
return False
#enddef
def prepare_temp(mj):
log.log('prepare_temp function called')
t = './temp'
a = '../../incoming/%s/archive' % mj
if not os.path.isdir(a):
a = './incoming/%s/archive' % mj
#endif
log_counter = 1
ret = None
l = None
if os.path.isdir(t): shutil.rmtree(t)
os.mkdir(t)
if not os.path.isdir(a):
log.log('no archive for %s' % mj)
return None, 0
#endif
l = sorted(os.listdir(a), reverse=True)
for f in l:
if 'log' in f and log_counter <= 3:
unpack('%s/%s' % (a, f), '%s/%s' % (t, log_counter))
if log_counter == 1: ret = f
log_counter += 1
# TODO kdyz se ini najde jako prvni, tak mi to nevezme zadny log
elif 'ini' in f:
unpack('%s/%s' % (a, f), '%s/ini' % t)
return ret, os.path.getmtime('%s/%s' % (a, f))
#endif
#endfor
return ret, 0
#enddef
def unpack(s, d):
log.log('unpacking %s' % s)
os.system('7z x %s -o%s' % (s, d))
#enddef
def give_lines(fn, source):
log.log('asked for lines %s, %s' % (fn, source))
t = './temp'
if source == 'ini':
f = open('%s/ini/%s' % (t, fn))
#for l in f.readlines():
for l in f:
yield l
#endfor
return
#endif
while source:
if not os.path.isfile('%s/%i/%s' % (t, source, fn)):
source -= 1
continue
#endif
f = open('%s/%i/%s' % (t, source, fn))
#for l in f.readlines():
for l in f:
yield l
#endfor
f.close()
source -= 1
#endwhile
#enddef
def get_datetime_from_log(l):
#TODO tohle vylepsit az bude jedina verze logu casu
try: ret = datetime.datetime.strptime(l.split(': ')[0], '%Y-%m-%d %H:%M:%S')
except:
try: ret = datetime.datetime.strptime(l.split(': ')[0], '%Y-%m-%d %H:%M:%S.%f')
except:
try: ret = datetime.datetime.strptime(l.split('[')[1].split(': ')[0], '%Y/%m/%d %H:%M:%S]')
except:
try: ret = datetime.datetime.strptime(l.split(': ')[0], '[%Y/%m/%d %H:%M:%S]')
except:
try: ret = datetime.datetime.strptime(l.split(']')[0], '[%Y-%m-%d %H:%M:%S.%f')
except:
try: ret = datetime.datetime.strptime(' '.join(l.split()[0:2]), '%Y-%m-%d %H:%M:%S.%f:')
except:
try: ret = datetime.datetime.strptime(' '.join(l.split()[0:2]), '[%Y-%m-%d %H:%M:%S]')
except:
try: ret = datetime.datetime.strptime(' '.join(l.split()[0:2]), '[%Y/%m/%d %H:%M:%S]')
except:
try: ret = datetime.datetime.strptime(' '.join(l.split()[0:2]), '%Y/%m/%d %H:%M:%S.%f')
except:
#log.info('%s' % l)
ret = datetime.datetime.strptime('1970/01/01 %s' % l.split()[0], '%Y/%m/%d %H:%M:%S.%f')
#endtry
#endtry
#endtry
#endtry
#endtry
#endtry
#endtry
#endtry
#endtry
return ret
#enddef
def get_adaptivity(mj):
log.log('get_adaptivity function called')
class Adaptivity():
def __init__(self, silo, scale, coefficient):
self.silo = silo
#log.info('creating new class for %s' % self.silo)
self.scale = scale
self.coefficient = coefficient
self.first = None
#enddef
def check_line(self, line):
if not self.scale in line: return
if not self.first and self.first != 0:
self.first = int(line.split('=')[1])
#log.info('%s first %s' % (self.silo, self.first))
else:
self.adaptivity = (int(line.split('=')[1]) - self.first) * self.coefficient
self.time = get_datetime_from_log(line)
return 'all done'
#endif
#enddef
#enclass
ret = {} # ret[silo] = [(time, adaptivity), ...]
materials = {'AGG': 'Aggregate', 'CEM': 'Cement', 'ADM': 'Admixture', 'WTR': 'Water'}
cache = {} # cache[silo] = {'Scale': scale, 'Coefficient': coefficient}
incompletes = [] # incompletes = [Adativity(), ...]
f = './temp/ini/base.ini'
if not os.path.isfile(f): return ret
base = IniParser()
base.read(f)
f = './temp/ini/settings.ini'
if not os.path.isfile(f): return ret
settings = IniParser()
settings.read(f)
fn = 'recordedsignals.log'
for l in give_lines(fn, 3):
for m in materials:
if m in l and 'O_' in l and 'intoBin' in l and ')=0' in l:
silo = '%s%s' % (m, l.split(m)[1].split('into')[0]) # for example AGG5
if not silo in cache:
bin = 'Bin%s' % l.split('intoBin')[1].split(')=')[0]
scale = '%s_Scale%s' % (materials[m], base.get('%s_%s' % (materials[m], bin), 'CorrespondingScale'))
signal = base.get('AnalogInput_Signals', scale)
coefficient = settings.getfloat('AnalogInput_Coefficients', 'Coefficient%s' % signal)
cache[silo] = {}
cache[silo]['Scale'] = scale
cache[silo]['Coefficient'] = coefficient
#endif
if not silo in ret: ret[silo] = []
# Adding new adaptivities to list
incompletes.append(Adaptivity(silo, cache[silo]['Scale'], cache[silo]['Coefficient']))
break
#endif
#endfor
if 'Scale' in l:
for i in incompletes:
if i.check_line(l):
ret[i.silo].append((i.time, i.adaptivity))
incompletes.remove(i)
#endif
#endfor
#endif
#endfor
# read alternately adaptivity from info.txt
fn = 'control.log'
materials = {'aggregate': 'AGG', 'cement': 'CEM', 'admixture': 'ADM', 'water': 'WTR'}
for l in give_lines(fn, 3):
if not 'adaptivity for' in l: continue
material_type = materials[l.split(' for ')[1].split(' bin ')[0]]
silo_number = l.split(' silo ')[1].split(':')[0]
adaptivity = l.split(': ')[-1].strip()
time = get_datetime_from_log(l)
silo = '%s%s' % (material_type, silo_number)
if not silo in ret: ret[silo] = []
ret[silo].append((time, float(adaptivity)))
#endfor
# create output files
for silo in ret:
log.info('creating file for silo %s' % silo)
a = '../public_html_incoming'
if not os.path.isdir(a):
a = './public_html_incoming'
#endif
f = open('%s/%s%s.csv' % (a, mj, silo), 'w')
for x,y in ret[silo]:
f.write('%s;%i\n' % (x.strftime('%Y-%m-%d %H:%M:%S'), y))
#endfor
f.close()
#endfor
return ret
#enddef
def assign_materials_to_silos(adaptivity):
log.info('assign_materials_to_silos function called')
pom = {'AGG': 'Aggregate', 'CEM': 'Cement', 'ADM': 'Admixture', 'WTR': 'Water'}
ret = {}
f = './temp/ini/placemnt.ini'
if not os.path.isfile(f): return ret
i = IniParser()
i.read(f)
for silo in adaptivity:
base = silo[0:3]
number = silo[3:]
for s in i.sections():
if pom[base] in s and 'Silo%s' % number in s:
ret[silo] = i.get(s, 'Name')
#endif
#endfor
#endfor
return ret
#enddef
def get_wiki(mj):
log.log('get_wiki function called')
d = {}
d['action'] = 'login'
d['name'] = 'ApplicationAnalyser'
d['password'] = 'atx43872298'
d['action'] = 'raw'
d['login'] = 'xx'
txheaders = {'User-agent': 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'}
url = 'http://wiki.asterix.cz/MixingPlants'
req = urllib2.Request(url, urllib.urlencode(d), txheaders)
r = None
while not r:
try: r = urllib2.urlopen(req)
except:
log.log('unable to get r1')
time.sleep(60)
#endtry
#endwhile
time.sleep(5) #pokus
wiki_list = r.read()
url = 'http://wiki.asterix.cz/%s' % mj.upper()
req = urllib2.Request(url, urllib.urlencode(d), txheaders)
r = None
while not r:
try: r = urllib2.urlopen(req)
except:
log.log('unable to get r2')
time.sleep(60)
#endtry
#endwhile
wiki_mj = r.read()
return wiki_list, wiki_mj
#enddef
def get_io_communication_failures():
log.log('get_io_communication_failures function called')
skip = datetime.datetime.now()
ret = {}
messages = ['[c200]', '[c201]', '[c202]', '[c203]']
fn = 'control.log'
if not isfile(fn):
return ret
#endif
for l in give_lines(fn, 3):
#TODO - vyresit nejak, ze kdyz to odklepnou, tak se to nezaznamena 2x
if '[C300]' in l or '[C301]' in l or '[C302]' in l: skip = get_datetime_from_log(l)
for e in messages:
if e in l.lower() and get_datetime_from_log(l) == skip:
if not e in ret: ret[e] = []
ret[e].append(get_datetime_from_log(l))
#endif
#endfor
#endfor
return ret
#enddef
def get_lan_settings():
log.log('get lan settings function called')
name = ''
domain = ''
ret = []
fn = 'adapters.txt'
if not isfile(fn):
return name, domain, ret
#endif
class Adapter():
def __init__(self):
self.adapter = ''
self.address = ''
self.subnet = ''
self.gateway = ''
self.dns = []
self.dhcp = 0
self.wins1 = ''
self.wins2 = ''
#enddef
def process(self, lines):
dns_watch = 0
for l in lines:
if 'adapt' in l.lower() and 'Ethernet ' in l and l.strip().endswith(':'):
pom = ''
try: pom = l.split(' adapter ')[1]
except: pass
if pom: self.adapter = pom[0:-1]
else:
pom = l.split('Ethernet ')[1]
if pom: self.adapter = pom[0:-1]
#endis
elif ' DHCP ' in l:
self.dhcp = 1
if ' Ne' in l or ' No' in l: self.dhcp = 0
elif ('Adresa IP' in l or 'IPv4 Address' in l) and not self.address:
self.address = l.split()[-1]
if '(' in self.address: self.address = self.address.split('(')[0]
elif 'Maska pods' in l or 'Subnet Mask' in l:
self.subnet = l.split()[-1]
elif ('choz' in l and 'br' in l) or 'Default Gateway' in l:
self.gateway = l.split()[-1]
if not '.' in self.gateway: self.gateway = ''
elif 'Servery DNS' in l or 'DNS Servers' in l:
dns_watch = 1
pom = l.split()[-1]
if '.' in pom: self.dns.append(pom)
else: dns_watch = 0
elif ('Pri' in l and 'server WINS' in l) or 'Primary WINS Server' in l:
dns_watch = 0
self.wins1 = l.split()[-1]
elif 'Sekund' in l and 'server WINS' in l or 'Secondary WINS Server' in l:
self.wins2 = l.split()[-1]
elif dns_watch == 1:
pom = ''
try: pom = l.split()[-1]
except: pass
if '.' in pom:
self.dns.append(pom)
#endif
#endif
#endfor
#enddef
#endclass
counter = 0
lines = {}
for l in give_lines(fn, 1):
if not l.startswith(' ') and 'adapt' in l.lower():
counter += 1
#endif
if not counter in lines: lines[counter] = []
lines[counter].append(l)
if 'hostitele' in l or 'Host Name' in l:
name = l.split()[-1]
elif ('Prim' in l and 'pona DNS' in l) or ('Primary Dns Suffix' in l):
pom = l.split()[-1]
if not ':' in pom: domain = pom
#endif
#endfor
for i in sorted(lines):
x = Adapter()
x.process(lines[i])
if x.adapter:
ret.append(x)
#endfor
print name, domain, ret
return name, domain, ret
#enddef
def get_last_state():
log.log('get_state function called')
ret = 'undetermined'
fn = 'loader.log'
if not isfile(fn):
return
#endif
for l in give_lines(fn, 3):
if 'unload_mode=\'True\'' in l: ret = ''
elif 'unload_mode=\'False\'' in l and 'reset_mode=\'False\'' in l: ret = 'running'
elif 'unload_mode=\'False\'' in l and 'reset_mode=\'True\'' in l: ret = 'restart'
#endfor
return ret
#enddef
class Plant():
def __init__(self, mj):
self.mj = mj
log.log('Processing %s' % self.mj)
#self.temp = './temp2'
self.archive = './archive'
self.cemex = {'mj143': '10.140.66.52',
'mj04': '10.140.8.52',
'mj101': '10.140.38.52',
'mj18': '10.140.23.52',
'mj125': '10.140.34.52',
'mj148': '10.140.36.52',
'mj22': '10.140.42.52',
'mj48': '10.140.44.52',
'mj107': '10.140.73.52',
'mj126': '10.140.74.52',
'mj36': '10.140.47.52',
'mj151': '10.140.62.52'}
self.now = datetime.datetime.now()
#self.latest_logs = get_latest_logs('%s/%s' % (self.mj, self.archive), self.now)
#log.log('latest logs: %s' % self.latest_logs)
#self.latest_ini = get_latest_ini('%s/%s' % (self.mj, self.archive))
#log.log('latest ini: %s' % self.latest_ini)
#enddef
def process(self):
self.latest_log, self.ini_created = prepare_temp(self.mj)
self.wiki_list, self.wiki_mj = get_wiki(self.mj)
self.adaptivity = get_adaptivity(self.mj)
self.materials_assignment = assign_materials_to_silos(self.adaptivity)
self.io_communication_failures = get_io_communication_failures()
self.last_state = get_last_state()
self.lan_name, self.lan_domain, self.lan_adapters = get_lan_settings()
self.get_tasks()
self.ports = self.get_open_ports()
self.get_last_restart()
self.get_bin_versions()
self.get_ini_hashes()
self.get_sizes()
self.get_cpu_usage()
self.get_app_name()
self.get_wiki_data()
self.get_hardware()
self.get_structure()
self.get_coefficients()
self.get_little_amounts()
self.get_smart()
self.get_router_errors()
self.get_libsh_errors()
self.get_control_errors()
self.get_control_messages()
self.get_aggregate_close_times()
#self.get_unauthorized_operations()
self.get_unhandled_exeptions()
#enddef
def get_little_amounts(self):
log.info('little amounts function called')
silo = {}
self.little_amounts_fails = {}
doba = None
vaha = None
navazeno = None
analog = None
adaptivita = None
pozadavek = None
zasobnik = 99 # can delete this line after three month (bacuse of error in info txt from Piestany)
fn = 'control.log'
for l in give_lines(fn, 3):
if 'poddavkovani ' in l.lower():
zasobnik = int(l.split()[-1])
vaha = None
navazeno = None
pozadavek = None
elif 'dobaotevreni ' in l.lower():
pom = float(l.split()[-1])
if pom > 3 or pom < 0: continue # filtrace demetskych hodnot v milisekundach a zapornych hodnot
doba = pom
elif 'mezistav1 ' in l.lower():
vaha = float(l.split()[-1])
elif 'NejblizsiCil2' in l and vaha:
pozadavek = float(l.split()[-1]) - vaha
elif 'PrumernaHodnotaAI[CisloAnalogu] - VychoziVaha' in l:
analog = float(l.split()[-1])
elif 'frakcenamereno2 ' in l.lower() and vaha:
navazeno = float(l.split()[-1]) - vaha
#endif
if doba and navazeno:
log.info('%i, %0.2f, %i' % (navazeno, doba, zasobnik))
if navazeno < 30 or navazeno > 500:
log.info('little amount fail: %i, %0.2f, %i' % (navazeno, doba, zasobnik))
if not zasobnik in self.little_amounts_fails:
self.little_amounts_fails[zasobnik] = []
#endif
self.little_amounts_fails[zasobnik].append('%i, %0.2f' % (navazeno, doba))
doba = None
continue
#endif
if analog: adaptivita = navazeno - analog + vaha
if not zasobnik in silo: silo[zasobnik] = []
silo[zasobnik].append((doba, navazeno, pozadavek, adaptivita))
doba = None
vaha = None
navazeno = None
analog = None
adaptivita = None
#endif
#endfor
#log.info('%s' % silo)
self.silo = {}
self.little_amounts_error = False
f = './temp/ini/adapt.ini'
if not os.path.isfile(f): return
adapt = IniParser()
adapt.read(f)
f = './temp/ini/parameters.ini'
if not os.path.isfile(f): return
parameters = IniParser()
parameters.read(f)
for k in silo:
self.little_amounts_error = adapt.has_option('Aggregate', 'VelocityOfFilling1-%s' % k)
param_velocity = 0
param_offset = 0
if parameters.has_option('Aggregate_Bin1_Silo%s' % k, 'Velocity_Base'):
param_velocity = parameters.getint('Aggregate_Bin1_Silo%s' % k, 'Velocity_Base')
param_offset = parameters.getfloat('Aggregate_Bin1_Silo%s' % k, 'Additional_Time')
else:
self.little_amounts_error = True
#endif
x = 0
sez = {}
while x < 1.5:
if not x in sez: sez[x] = []
for doba, navazeno, pozadavek, adaptivita in silo[k]:
if doba-x == 0: continue #I dont know why
sez[x].append(navazeno/(doba - x))
#endfor
x = x + 0.01
#endwhile
minimum = None
for x in sorted(sez):
sqr_sum = 0
avg = 0
dev = 0
avg = sum(sez[x]) * 1.0 / len(sez[x])
for velocity in sez[x]:
sqr_sum += ((velocity - avg) ** 2) / len(sez[x])
#endfor
dev = sqr_sum ** 0.5
if not minimum or dev < minimum:
#print dev
minimum = dev
self.silo[k] = (x, avg, len(sez[x]), dev, param_velocity, param_offset)
#endif
#endfor
#endfor
#enddef
def get_tasks(self):
log.log('get_tasks function called')
self.tasks = []
self.important_task = False
focus = False
for l in self.wiki_mj.split('\n'):
if 'koly ==' in l: focus = True
elif '==' in l: focus = False
elif '*' in l and focus:
if '!' in l: self.important_task = True
self.tasks.append(l.strip())
#endif
#endfor
log.log('%s' % self.tasks)
#enddef
def get_open_ports(self):
log.log('get_open_ports function called')
ports = []
try:
soc_family = socket.getaddrinfo('%s.asterix.cz' % self.mj, 0)[0][0]
except:
log.exception('socket.getaddrinfo exception')
soc_family = None
#endtry
if self.mj in self.cemex:
log.info('cemex')
f = os.popen('nmap -Pn -p 22,3389,5900 %s' % self.cemex[self.mj])
elif soc_family == socket.AF_INET:
log.info('IPv4')
f = os.popen('nmap -Pn -p 22,3389,5900 %s.asterix.cz' % self.mj)
elif soc_family == socket.AF_INET6:
log.info('IPv6')
f = os.popen('nmap -6 -Pn -p 22,3389,5900 %s.asterix.cz' % self.mj)
else:
log.error('unknown address family: %s' % soc_family)
return ports
#endif
for l in f.read().split('\n'):
log.info(l)
if '22/tcp' in l and 'open' in l:
ports.append('22')
elif '3389/tcp' in l and 'open' in l:
ports.append('3389')
elif '5900/tcp' in l and 'open' in l:
ports.append('5900')
#endif
#endfor
return ports
#enddef
def get_smart(self):
log.log('get_smart function called')
list_of_zero_attributes = (1, 5, 10, 184, 188, 196, 197, 198, 201, 250, 254, 199) #199 is not important marker
focus = False
self.smart_created = 0
self.count_of_smart_attributes = 0
self.smart_faults = []
self.last_long = 0
self.last_short = 0
self.power_on_hours = 0
self.smart_supported = 1
self.smart_log = []
restart = 0
fn = 'smart.log'
try: self.smart_created = os.path.getmtime(isfile(fn))
except: return
#endtry
for l in give_lines(fn, 1):
if 'ID' in l: focus = True
elif len(l) < 3: focus = False
elif 'Self-test Log not supported' in l: self.smart_supported = 0
elif 'Short offline' in l and 'Completed without error' in l and not self.last_short:
self.smart_log.append(l.strip())
self.last_short = int(l.split()[-2])
if self.last_short + restart <= self.power_on_hours: self.last_short = self.last_short + restart #because of restart counting every 65536 minutes
elif 'Extended offline' in l and 'Completed without error' in l and not self.last_long:
self.smart_log.append(l.strip())
self.last_long = int(l.split()[-2])
if self.last_long + restart <= self.power_on_hours: self.last_long = self.last_long + restart #because of restart counting every 65536 minutes
#endif
if not focus: continue
x = l.split()
try:
ident = int(x[0])
if ident == 9:
self.smart_log.append(l.strip())
self.power_on_hours = int(x[-1])
restart = self.power_on_hours*60//65536*65536//60 # time of counter restart for self-test log
#endif
if ident in list_of_zero_attributes:
self.smart_log.append(l.strip())
self.count_of_smart_attributes += 1
raw = int(x[-1])
if raw != 0:
self.smart_faults.append([ident, x[1], raw])
#endif
#endif
except: pass
#endtry
#endfor
#enddef
def get_bin_versions(self):
log.log('get_bin_versions function called')
fn = 'versions.txt'
self.versions_created = 0
self.versions = {}
try: self.versions_created = os.path.getmtime(isfile(fn))
except: return
#endtry
for l in give_lines(fn, 1):
app = l.split('.')[0]
ver = l.split()[1]
hash = l.split()[2]
self.versions[app] = (ver, hash)
#endfor
log.log('%s' % self.versions)
#enddef
def get_coefficients(self):
log.log('get_coefficients function called')
self.coefficients = {}
converter = 8192
if self.mj in ('mj04', 'mj22', 'mj36'): converter = 4096
l = []
f = './temp/ini/base.ini'
if not os.path.isfile(f): return
i = IniParser()
i.read(f)
for s in i.options('AnalogInput_Signals'):
if 'scale' in s.lower() and i.get('AnalogInput_Signals', s) != 'x': l.append((s, i.getint('AnalogInput_Signals', s)))
#endfor
f = './temp/ini/parameters.ini'
if not os.path.isfile(f): return
i = IniParser()
i.read(f)
for s, a in l:
self.coefficients[s] = i.getfloat(s, 'Range')
#endfor
f = './temp/ini/settings.ini'
if not os.path.isfile(f): return
i = IniParser()
i.read(f)
for s, a in l:
print s, a
print self.coefficients[s]
print i.getfloat('AnalogInput_Coefficients', 'Coefficient%i' % a)
print type(self.coefficients[s])
print type(i.getfloat('AnalogInput_Coefficients', 'Coefficient%i' % a))
capacity = self.coefficients[s]
difference = (i.getfloat('AnalogInput_Coefficients', 'Coefficient%i' % a) / (capacity/converter) - 1) * 100
offset = i.getint('AnalogInput_Offsets', 'Offset%i' % a)
self.coefficients[s] = (capacity, difference, offset)
#endfor
#enddef
def get_structure(self):
log.log('get_structure function called')
self.structure = []
f = './temp/ini/parameters.ini'
if not os.path.isfile(f): return
i = IniParser()
i.read(f)
self.structure.append(('mixer', i.get('Mixer', 'Volume')))
f = './temp/ini/base.ini'
if not os.path.isfile(f): return
i = IniParser()
i.read(f)
if i.getint('General', 'WeighingConveyer') > 0: self.structure.append(('weighing conv', i.getint('General', 'WeighingConveyer')))
if i.getint('Structure', 'Lifts') > 0: self.structure.append(('lifts', i.getint('Structure', 'Lifts')))
if i.getint('Structure', 'Conveyers') > 0: self.structure.append(('convs', i.getint('Structure', 'Conveyers')))
if i.getint('Structure', 'Reservoirs') > 0: self.structure.append(('reservoirs', i.getint('Structure', 'Reservoirs')))
for sec in ('Aggregate_Bin', 'Cement_Bin', 'Water_Bin', 'Admixture_Bin'):
silos = 0
#goes through up to 10 possible bins
for num in range(1, 10):
pom = i.getint('%s%i' % (sec, num), 'Silos', 0)
if pom > silos: silos = pom
#endfor
abr = sec.split('_')[0]
self.structure.append(('%s' % abr.lower(), '%i -> %i -> %i' % (silos, i.getint(abr, 'Bins'), i.getint(abr, 'Scales'))))
#endfor
x = i.get('BinaryInput_Signals', 'I_Bin1CEMclosed', 'x').strip()
if not x in ('x', '255'): self.structure.append(('cement_bin1 limit switch signal', x))
x = i.get('BinaryInput_Signals', 'I_Bin2CEMclosed', 'x').strip()
if not x in ('x', '255'): self.structure.append(('cement_bin2 limit switch signal', x))
if i.getint('Hardware', 'IND-1') > 2: self.structure.append(('hardware', 'old'))
else: self.structure.append(('hardware', 'new'))
x = i.get('Hardware', 'PointerCounts', 'x').strip()
self.structure.append(('pointercounts', x))
#enddef
def get_ini_hashes(self):
log.log('get_ini_hashes function called')
self.ini_hashes = {}
t = './temp/ini'
if not os.path.isdir(t): return
for f in os.listdir(t):
self.ini_hashes[f] = get_hash('%s/%s' % (t, f))
#endfor
#enddef
def get_sizes(self):
log.log('get_sizes function called')
fn = 'sizes.txt'
self.sizes = {}
self.sizes['created'] = 0
self.sizes['files'] = 0
self.sizes['size'] = 0
try: self.sizes['created'] = os.path.getmtime(isfile(fn))
except: return
#endtry
for l in give_lines(fn, 1):
if ' ..\\archive' in l: continue #excludes archive folder in root
if ' ..\\visual\\data\\' in l: continue #excludes visual data folder