-
Notifications
You must be signed in to change notification settings - Fork 5
/
butler.exec
1019 lines (862 loc) · 34.6 KB
/
butler.exec
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
/* BUTLER EXEC */
/* */
/* A VM general service program */
/* for z/VM, VM/ESA and VM/SP */
/* Moshix */
/* */
/* copyright 2021 by moshix */
/* Apache 2.0 license */
/***************************************/
/* execute this from RELAY VM before starting RELAY CHAT: */
/* defaults set tell msgcmd msgnoh to remove host(user) in output */
/* CHANGE HISTORY */
/* V0.1 : Humble beginnings */
/* V0.2 : Add user command history /users */
/* V0.3 : Add /benchmark command */
/* V0.4 : Add /store bcast: /store pswd linenr(1-5) msg */
/* V0.5 : Add /WAKEME at time 10.10.10 or IN 10 mini */
/* V0.6 : Regular wake up of BUTLER to run scheduler */
/* V0.7 : Use double linked list instead of scheduler array */
/* V0.8 : Fix logic in very complex (too?) wakeme module */
/* V1.0 : First web service !! /FOREX */
/* V1.1 : Moon phase indicator /MOON */
/* configuraiton parameters - IMPORTANT */
butlerversion="1.1" /* needed */
timezone="EDT" /* adjust for your server IMPORTANT */
localnode="" /* localnode is now autodetected as 2.7.1 */
osversion="z/VM 6.4" /* OS version for enquries and stats */
typehost="IBM z114" /* what kind of machine */
hostloc ="Stockholm,SE" /* where is this machine */
sysopname="zzzzzz " /* who is the sysop for this chat server */
sysopemail="zzzzzz@gmail" /* where to contact this systop */
postpswd="125" /* password needed to store bcast msgs */
compatibility=3 /* 1 VM/SP 6, 2=VM/ESA 3=z/VM and up */
sysopuser='MAINT' /* sysop user who can force users out */
sysopnode=translate(localnode) /* sysop node automatically set */
raterwatermark=18000 /* max msgs per minute set for this server */
log2file=1 /* log also to butler log file */
/* global variables */
isincluded=0 /* is keyword found ?? */
eStarttime=1 /* used for logged on users to start countdown to asleep */
LastSessionStart=3000000 /* last user session started at... */
InSessionUser="" /* which user is currently in session */
BIGLOCK=0 /* RESET LOCK FOR MULTITENANT */
returnNJEmsg="HCPMSG045E" /* messages returning for users not logged on */
returnNJEmsg2="DMTRGX334I"/* looping error message flushed */
returnNJEmsg3="HCPMFS057I"/* looping error message flushed */
returnNJEmsg4="HCPMSG045E"/* user not logged on */
returnNJEmsg5="DMSWTL648E"/* userid not found, no message sent */
loggedonusers = 0 /* online user at any given moment */
highestusers = 0 /* most users online at any given moment */
totmessages = 0 /* total number of msgs sent */
otime = 0 /* overtime to log off users after n minutes */
starttime=mytime() /* for /SYSTEM */
starttimeSEC=ExTime() /* for msg rate calculation */
logline = " " /* initialize log line */
receivedmsgs=0 /* number of messages received for stats and loop*/
err1="currently NOT"
err2="to logon on"
err3="Weclome to RELAY chat"
err4="logged off now"
illegaluser1="RSCS" /* we should never receive a message from these users */
illegaluser2="ROOT" /* we should never receive a message from these users */
historypointer=1
history.0=20 /* max 20 entries for user command history */
BCASTMSG.0=5 /* MAX 5 BROADCAST LINES */
BCASTMSG.1="Hello wonderful human and welcome to LILITH!"
BCASTMSG.2=" LILITH is currently operating at nominal WARP speed..."
BCASTMSG.3="No downtime is currently planned for the mainframe/HNET services"
BCASTMSG.4="***IMPORTANT! ALL USERS MUST CHECK BROADCAST MSGS UPON LOGIN!***"
BCASTMSG.5=""
sysperf=0 /* /benchmark system performance (in sec) holder */
call initbutler /* initalize butler and do all the fancy stuff to start */
/* Invoke WAKEUP first so it will be ready to receive msgs */
/* This call also issues a 'SET MSG IUCV' command. */
'SET MSG IUCV'
'MAKEBUF'
Do forever;
'wakeup +1 (iucvmsg QUIET' /* wake up every minute anyway */
/* parse pull text */ /* get what was send */
select
when Rc = 2 then do
/* timer has expired */
call scheduler /* check if any scheduled slots */
end
when Rc = 5 then do; /* we have a message */
/* parse it */
parse pull text
if pos('From', text) > 0 then do /* from RSCS */
parse var text type sender . nodeuser msg
parse var nodeuser node '(' userid '):'
CALL LOG('from '||userid||' @ '||node||' '||msg)
receivedmsgs= receivedmsgs + 1
/* below line checks if high rate watermark is exceeded */
/* and if so.... exits! */
call highrate (receivedmsgs)
uppuserid=TRANSLATE(userid)
/* below line eliminates service messages from other relay nodes and eliminates loops */
if pos(err1,msg) > 0 | pos(err2,msg) > 0 | pos(err3,msg) > 0 | pos(err4,msg) > 0 then do
end
else do
if detector(msg) > 0 then call handlemsg userid,node,msg
end
end
else do; /* simple msg from local user */
/* format is like this: */
/* *MSG MAINT hello */
parse var text type userid msg
node = localnode
call handlemsg userid,node,msg
end
end
when Rc = 6 then
signal xit
otherwise
end
end; /* of do forever loop */
xit:
/* when its time to quit, come here */
'WAKEUP RESET'; /* turn messages from IUCV to ON */
'SET MSG ON'
'DROPBUF'
exit;
handlemsg:
/* handle all incoming messages and send to proper method */
parse ARG userid,node,msg
userid=strip(userid)
node=strip(node)
if userid = illegaluser1 | userid = illegaluser2 then do
call log ('Message arrived from illegal user: '||userid)
return
end
CurrentTime=Extime()
umsg = translate(msg) /* make upper case */
umsg=strip(umsg)
/* below few lines: loop detector */
loopmsg=SUBSTR(umsg,1,11) /* extract RSCS error msg */
if (loopmsg = returnNJEmsg | loopmsg = returnNJEmsg2 | loopmsg = returnNJEmsg3 loopmsg = returnNJEmsg5 ) then do
call log('Loop detector triggered for user: '||userid||'@'||node)
return
end
commandumsg=SUBSTR(umsg,2,5)
updbuff=1
SELECT /* HANDLE MESSAGE TYPES */
when (umsg = "/BCAST") then
call sendbcast userid,node
when (LEFT(umsg,6) = "/STORE") then
call storebcast userid,node,msg
when (umsg = "/CPU") then
call sendcpu userid,node
when (umsg = "/SYSTEM") then
call systeminfo userid,node
when (umsg = "/STATS") then
call sendstats userid,node
when (umsg = "/LOGOFF") then do
call logoffuser userid,node
updbuff=0 /* removed, nothing to update */
end
when (umsg = "/USERS") then
call users userid,node
when (umsg = "/HISTORY") then
call users userid,node
when (umsg = "/FOREX") then
call forex userid,node
when (umsg = "/MOON") then
call moon userid,node
when (LEFT(umsg,9)g = "/FORECAST") then
call forecast userid,node
when (umsg = "/HELP") then
call helpuser userid,node
when (LEFT(umsg,7) = "/WAKEME") then
call wakeme userid,node,msg
when (umsg = "/BENCHMARK") then
call usrbenchmark userid,node
when (umsg = "/TIME") then
call sendtime userid,node
otherwise
call helpuser userid,node,msg
end
return
wakeme:
/*this function allows user to be sent wake up message in + min or at specific time */
parse ARG userid,node,msg
htime=mytime()
histuser=htime||" : "userid||" @ "||node||" : WAKEME !"
call inserthistory histuser,historypointer
if historypointer < history.0 then historypointer=historypointer +1
Parse Value msg With . wtype wtime wunit
wtype=translate(wtype) /* make upper case */
wunit=translate(wunit) /* make min or hour upper */
if wtype /= "AT" & wtype /= "IN" then do /* wrong type */
call RESPOND userid,node,"SYNTAX: /WAKEME AT|IN TIME (MIN|HOUR)"
call log (histuser||" wrong type specified: : "||wtype)
return -1
end
if wtype = "IN" & (wunit /= "MIN"& wunit /= "HOUR") then do
call RESPOND userid,node,"for /WAKEME only MIN or HOUR are allowed"
call log (histuser||" wrong unit specified : "||wunit)
return -1
end
if wtype = "IN" & datatype(wtime,W) /= "1" then do /* not an integer number */
call RESPOND userid,node,"for /WAKEME only integer hour or minute allowed"
call log (histuser||" wrong time amount : "||wtime)
return -1
end
wnow = epochtime() /* exact time now in seconds since epoch */
wadd=-5 /* default subtract 5 sec, so it expires immedaitely */
/* this results in no wake up being sent to user, safe option */
if wtype = "IN" & wunit = "MIN" then do
wadd=wtime * 60
end
if wtype = "IN" & wunit = "HOUR" then do
wadd=wtime * 60* 60
end
if wtype ="AT" then do
parse value wtime with phh':'pmm':'pss
if phh < 00 | phh > 24 then do
call respond userid,node,'Hour must be 00 to 24 because of the whole day rotation thing...'
return -1
end
if pmm < 00 | pmm > 59 then do
call respond userid,node,'Minutes must be between 00 and 59 dude...'
return -1
end
if pss < 00 | pss > 59 then do
call respond userid,node,'Seconds must be between 00 and 59 dude...'
return -1
end
end
wfuture=0
if wtype ="AT" then scheduletime=epochat(wtime)
if wtype ="IN" then scheduletime = wnow+wadd /* time at which to schedule wwake up time */
call schedule userid,node,scheduletime /* call time scheduler */
return 0
storebcast:
/* this function allows sysop/sysadmin to store bcast messages */
parse ARG userid,node,msg
htime=mytime()
histuser=htime||" : "userid||" @ "||node||" : STORE!!!!"
call inserthistory histuser,historypointer
if historypointer < history.0 then historypointer=historypointer +1
Parse Value msg With . pswd bnum pload
if pswd /= postpswd then do
call RESPOND userid,node,"STORE password is wrong!"
call log (histuser||" tried STORE of bcast with wrong password: "||msg)
return -1
end
/* ok, password was correct, let's get bcast line number and then the bcast message */
if bnum < 1 | bnum > 5 then do
call RESPOND userid,node,"You must select a broadcast line 1,2,3,4 or 5 after password!"
call log (histuser||" didn't indicate a broadcast line in : "||bnum)
return -1
end
bcastholder=bnum
/* ok, we now have a broadcast line number, let's get the line content */
rml=length(pload)
if rml<10 | rml>95 then do
call RESPOND userid,node,"Your broadcast line must be > 10 char, < 95 char "
call log (histuser||" broadcast line length was illegal with chars : "||rml)
return -1
end
/* ok, legnth is legal, let's store in appropriate bcast container */
bcaststr=pload
bcastmsg.bcastholder=bcaststr
call RESPOND userid,node,"Your broadcast line is stored in line nr: "||bcastholder
call log (histuser||" stored the following bcast line:"||bcaststr)
return 0
sendbcast:
/* SENDS TO REQUEST THE BROADCAST MESSAGE */
parse ARG userid,node
htime=mytime()
histuser=htime||" : "userid||" @ "||node||" : BCAST "
call inserthistory histuser,historypointer
if historypointer < history.0 then historypointer=historypointer +1
if node = localnode then do
CALL RESPOND userid,node,bcastmsg.1
do i=2 to bcastmsg.0
if bcastmsg.i /= " " then CALL RESPOND userid,node,bcastmsg.i
end
end
else do
call RESPOND userid,node,"Broadcast is only for local users... sorry..."
end
return 0
forex:
/* get forex infro from relayserv.bitnet.systems/cleanforex */
htime=mytime()
histuser=htime||" : "userid||" @ "||node||" : FOREX "
call inserthistory histuser,historypointer
if historypointer < history.0 then historypointer=historypointer +1
'ERASE FOREX OUT A'
'WW2GET https://relayserver.dynu.net/cleanforex FOREX OUT A'
do forever
'EXECIO 1 DISKR FOREX OUT A (VAR LINEIN'
if rc<>0 then leave
call respond userid,node,LINEIN
end
'FINIS' 'FOREX OUT A'
return 0
moon:
/* get moon phase from relayserver.bitnet.systems */
htime=mytime()
histuser=htime||" : "userid||" @ "||node||" : MOON "
call inserthistory histuser,historypointer
if historypointer < history.0 then historypointer=historypointer +1
'ERASE MOON OUT A'
'WW2GET http://relayserv.dynu.net/cleanmoon MOON OUT A'
do forever
'EXECIO 1 DISKR MOON OUT A (VAR LINEIN'
if rc<>0 then leave
call respond userid,node,LINEIN
end
'FINIS' 'MOON OUT A'
return 0
systeminfo:
/* send /SYSTEM info about this host */
parse ARG userid,node
listuser = userid"@"node
htime=mytime()
histuser=htime||" : "userid||" @ "||node||" : SYSINFO "
call inserthistory histuser,historypointer
if historypointer < history.0 then historypointer=historypointer +1
parse value translate(diag(8,"INDICATE LOAD"), " ", "15"x) ,
with 1 "AVGPROC-" cpu "%" 1 "PAGING-" page "/"
cpu = right( cpu+0, 3)
'TELL' userid 'AT' node '-> NJE node name : 'localnode
'TELL' userid 'AT' node '-> Butler version : 'butlerversion
'TELL' userid 'AT' node '-> OS for this host : 'osversion
'TELL' userid 'AT' node '-> Type of host : 'typehost
'TELL' userid 'AT' node '-> Location of this host: 'hostloc
'TELL' userid 'AT' node '-> Time Zone of : 'timezone
'TELL' userid 'AT' node '-> SysOp for this server: 'sysopname
'TELL' userid 'AT' node '-> SysOp email addr : 'sysopemail
'TELL' userid 'AT' node '-> System Load :'cpu'%'
if compatibility > 2 then do
page=paging()
rstor=rstorage()
cfg=configuration()
lcpus=numcpus()
/* parse var mcpu mpage mcf mrstor mlcpus */
'TELL' userid 'AT' node '-> Pages/Sec : 'page
'TELL' userid 'AT' node '-> IBM Machine Type : 'cfg
'TELL' userid 'AT' node '-> Memory in LPAR or VM : 'rstor
'TELL' userid 'AT' node '-> Number of CPUs : 'lcpus
end
if compatibility > 2 then do
totmessages = totmessages + 13
end
else do
totmessages = totmessages + 9
end
return
sendstats:
/* send usage statistics to whoever asks, even if not logged on */
parse ARG userid,node
htime=mytime()
histuser=htime||" : "userid||" @ "||node||" : STATS "
call inserthistory histuser,historypointer
if historypointer < history.0 then historypointer=historypointer +1
parse value translate(diag(8,"INDICATE LOAD"), " ", "15"x) ,
with 1 "AVGPROC-" cpu "%" 1 "PAGING-" page "/"
cpu = right( cpu+0, 3)
actualtime=Extime()
elapsedsec=(actualtime-starttimeSEC)
if elapsedsec = 0 then elapsedsec = 1 /* avoid division by zero on Jan 1 at 00:00 */
msgsrate = (receivedmsgs + totmessages) / elapsedsec
msgsratef= FORMAT(msgsrate,4,2) /* rounding */
msgsratef = STRIP(msgsratef)
listuser = userid"@"node
'TELL' userid 'AT' node '-> Total number of msgs : 'totmessages
'TELL' userid 'AT' node '-> Messages rate /minute: 'msgsratef
'TELL' userid 'AT' node '-> Server up since : 'starttime' 'timezone
'TELL' userid 'AT' node '-> System CPU load : 'STRIP(cpu)'%'
'TELL' userid 'AT' node '-> BUTLER version : v'butlerversion
totmessages = totmessages+ 5
return
helpuser:
/* send help menu */
parse ARG userid,node
htime=mytime()
histuser=htime||" : "userid||" @ "||node||" : HELP "
call inserthistory histuser,historypointer
if historypointer < history.0 then historypointer=historypointer +1
listuser = userid"@"node
'TELL' userid 'AT' node ' ____ __ __ ____ __ ____ ____ '
'TELL' userid 'AT' node ' ( _ \( )( )(_ _)( ) ( ___)( _ \ '
'TELL' userid 'AT' node ' ) _ < )(__)( )( )(__ )__) ) / '
'TELL' userid 'AT' node ' (____/(______) (__) (____)(____)(_)\_) '
'TELL' userid 'AT' node ' '
'TELL' userid 'AT' node ' for VM/SP, VM/ESA and z/VM '
'TELL' userid 'AT' node '/HELP for this help'
'TELL' userid 'AT' node '/BCAST to get teh broadcast message '
'TELL' userid 'AT' node '/STATS for ... you guessed it ...statistics!'
'TELL' userid 'AT' node '/SYSTEM for info about this host'
'TELL' userid 'AT' node '/STORE to store the broadcast message (requires pswd '
'TELL' userid 'AT' node '/USERS to see history of users commands'
'TELL' userid 'AT' node '/BENCHMARK to see the performance of this machien'
'TELL' userid 'AT' node '/TIME to get time zone and time of this server'
'TELL' userid 'AT' node '/WAKEME will wake you up at at the time specified (next 24 hours)'
'TELL' userid 'AT' node '/FOREX gets your updated foreign exchange prices from web '
'TELL' userid 'AT' node '/MOON check out the current moon phase!'
'TELL' userid 'AT' node ' '
'TELL' userid 'AT' node ' messages with -> are dialogues from Butler '
totmessages = totmessages + 20
return
users:
/* show history of last 20 chat messages to /users */
parse ARG userid,node
htime=mytime()
histuser=htime||" : "userid||" @ "||node||" : USERS "
call inserthistory histuser,historypointer
if historypointer < history.0 then historypointer=historypointer +1
i=0
found=0
z=history.0
'TELL 'userid' AT 'node '> Previous 'history.0' messages:'
totmessages = totmessages + 1
do i = 1 to z by 1
if history.i /= "" then do
'TELL 'userid' AT 'node '> 'history.i
totmessages = totmessages + 1
found=found+1
end
end
if found < 1 then 'TELL 'userid' AT 'node '> ...bummer... no chat history so far...'
totmessages = totmessages + 1
return
usrbenchmark:
/* send to user a fuller benchmark suite */
parse ARG userid,node
htime=mytime()
histuser=htime||" : "userid||" @ "||node||" : BENCHMARK"
call inserthistory histuser,historypointer
if historypointer < history.0 then historypointer=historypointer +1
'TELL' userid 'AT' node '-> Benchmark Overiew (smaller number is better)'
'TELL' userid 'AT' node '-> --------------------------------------------'
'TELL' userid 'AT' node '-> '
'TELL' userid 'AT' node '-> This system : 'sysperf
'TELL' userid 'AT' node '-> IBM z114 : 0.225'
'TELL' userid 'AT' node '-> IBM zEC12 : 0.230'
'TELL' userid 'AT' node '-> IBM z/PDT on Xeon 3.5Ghz : 0.850'
'TELL' userid 'AT' node '-> IBM z/PDT on Xeon 2.4Ghz : 1.250'
'TELL' userid 'AT' node '-> Hyperion 4.4 on Xeon 3.5Ghz : 8.800'
'TELL' userid 'AT' node '-> Hyperion 4.4 on Xeon 2.1Ghz : 12.200'
totmessages = totmessages + 9
return 0
sendtime:
/* send time and time zone to user */
parse ARG userid,node
htime=mytime()
histuser=htime||" : "userid||" @ "||node||" : TIME"
call inserthistory histuser,historypointer
if historypointer < history.0 then historypointer=historypointer +1
Parse Value Diag(8,'QUERY TIME') With . . timenow tz tday tdate
CALL RESPOND userid,node,"It is: "||timenow||" "||tday||" "||tdate
CALL RESPOND userid,node,"time zone: "||tz
return 0
sendcpu:
/* send cpu busy of this machine */
parse ARG userid,node
htime=mytime()
histuser=htime||" : "userid||" @ "||node||" : CPU "
call inserthistory histuser,historypointer
if historypointer < history.0 then historypointer=historypointer +1
CALL RESPOND userid,node,"CPU busy average for this machine: "cpubusy()||" %"
return 0
forecast:
/* send weather forecast thru RELAY service */
parse ARG userid,node
htime=mytime()
histuser=htime||" : "userid||" @ "||node||" : FORECAST"
call inserthistory histuser,historypointer
if historypointer < history.0 then historypointer=historypointer +1
/* extract city from /forecast xxx and send to RELAY as following:
smsg rscs cmd relay forecast CITY
*/
return 0
refreshTime:
/* Refresh last transaction time */
arg ctime,userid,node
listuser=userid'@'node
ppos=pos('/'listuser,$.@)
if ppos=0 then return /* user not logged on */
ppos=pos('(',$.@,ppos+1) /* find timestamp */
if ppos=0 then return /* not found, let it be */
rpos=pos(')',$.@,ppos+1)+1 /* find end of timestamp */
if rpos=0 then return /* ) not found, let it be */
rlen=rpos-ppos
$.@=overlay('('ctime')',$.@,ppos,rlen)
return
exTime:
/* Calculate Seconds in this year */
dd=(date('d')-1)*86400
parse value time() with hh':'mm':'ss
tt=hh*3600+mm*60+ss
return right(dd+tt,8,'0')
epochtime: procedure
/*return date and time of now since jan 1 2021 */
today = Date('Base')
days = today - Date('Base', '20210101', 'Standard')
/* TIME IS 00:09:05 EDT WEDNESDAY 03/03/21 */
qtime=time()
parse var qtime hh':'mm':'ss
tt=hh*3600+mm*60+ss
dd=days*86400
sincepoch=tt+dd
return sincepoch
epochat: procedure
/*return future epoch time based on date */
parse arg futuretime
today = Date('Base')
days = today - Date('Base', '20210101', 'Standard')
/* TIME IS 00:09:05 EDT WEDNESDAY 03/03/21 */
qtime=futuretime
parse var qtime hh':'mm':'ss
tt=hh*3600+mm*60+ss
dd=days*86400
sincepoch=tt+dd
return sincepoch
mytime: procedure
timenow = left(time(),5)
hr = left(timenow,2)
min = right(timenow,2)
if hr > 12 then timenow = (hr - 12)'.'min' pm'
else if hr = 12 then timenow = hr'.'min' pm'
else timenow = hr'.'min' am'
if left(timenow,1) = '0' then timenow = substr(timenow,2)
dow = left(date('weekday'),3)
day = right(date('sorted'),2)
if left(day,1) = '0' then day = substr(day,2)
month = left(date('month'),3)
year = left(date('sorted'),4)
return timenow',' dow day month year
log:
/* general logger function */
/* log a line to console and BUTLER LOG A */
parse ARG logline
say mytime()' :: 'logline
if log2file = 1 & compatibility > 0 then do
address command
/* 'PIPE (name logit)',
'| spec /'mytime()'/ 1 /::/ n /'logLine'/ n',
'| >> BUTLER LOG A'*/
logline=mytime()||' :: '||logline
'EXECIO 1 DISKW RELAY LOG A (STRING '||logline
'FINIS BUTLER LOG A'
end
return
cpubusy:
/* how busy are the CPU(s) on this LPAR */
/* extract CPU buy information for stats etc. */
cplevel = space(cp_id) sl
strlen = length(cplevel)
parse value translate(diag(8,"INDICATE LOAD"), " ", "15"x) ,
with 1 "AVGPROC-" cpu "%" 1 "PAGING-" page "/"
cpu = right( cpu+0, 3)
return cpu
paging:
/* how many pages per second is this LPAR doing? */
/* extra currenct OS paging activity */
sl = c2d(right(diag(0), 2))
cplevel = space(cp_id) sl
strlen = length(cplevel)
parse value translate(diag(8,"INDICATE LOAD"), " ", "15"x) ,
with 1 "AVGPROC-" cpu "%" 1 "PAGING-" page "/"
return page
rstorage:
parse value diag(8,"QUERY STORAGE") with . . rstor rstor? . "15"x
return rstor
configuration:
/* return machine configuration */
/* extract machine type etc. */
if compatibility > 2 then do
Parse Value Diag(8,'QUERY CPLEVEL') With ProdName .
Parse Value Diag(8,'QUERY CPLEVEL') With uptime , . . . . . . . ipltime
Parse Value Diag(8,'QUERY CPLEVEL') With ProdName .
Parse Value Diag(8,'QUERY CPLEVEL') With uptime , . . . . . . . ipltime
parse value stsi(1,1,1) with 49 type +4 ,
81 seq +16 ,
101 model +16 .
parse value stsi(2,2,2) with 33 lnum +2 , /* Partition number */
39 lcpus +2 , /* # of CPUs in the LPAR */
45 lname +8 /* partition name */
parse value stsi(3,2,2) with 39 vcpus +2 , /* # of CPUs in the v.m. */
57 cp_id +16
parse value c2d(lnum) c2d(lcpus) c2d(vcpus) right(seq,5) lname model ,
with lnum lcpus vcpus ser lname model .
blist = "- 2097 z10-EC 2098 z10-BC 2817 z196 2818 z114",
" 2827 zEC12 2828 zBC12 2964 z13 2965 z13s"
brand = strip(translate( word(blist, wordpos(type, blist)+1), " ", "-"))
end
return type
numcpus:
/* return number of CPUs in this LPAR */
parse value stsi(1,1,1) with 49 type +4 ,
81 seq +16 ,
101 model +16 .
parse value stsi(2,2,2) with 33 lnum +2 , /* Partition number */
39 lcpus +2 , /* # of CPUs in the LPAR */
45 lname +8 /* partition name */
parse value stsi(3,2,2) with 39 vcpus +2 , /* # of CPUs in the v.m. */
57 cp_id +16
parse value c2d(lnum) c2d(lcpus) c2d(vcpus) right(seq,5) lname model ,
with lnum lcpus vcpus ser lname model .
blist = "- 2097 z10-EC 2098 z10-BC 2817 z196 2818 z114",
" 2827 zEC12 2828 zBC12 2964 z13 2965 z13s 1090 zPDT 3096 z14"
brand = strip(translate( word(blist, wordpos(type, blist)+1), " ", "-"))
return lcpus
highrate:
/* when too many incoming messages per second exit server to avoid CPU overloading */
/* this function detects high msg rate for loop detection purposes
or for system load abatement purposes */
RATE = 0
parse ARG receivedmsg
currentime=Extime()
elapsedtime=currentime-starttimeSEC
if elapsedtime = 0 then elapsedtime = 3 /* some machines too fast */
rate = receivedmsg/elapsedtime
if rate > raterwatermark then do
call log ('Rate high watermark exceeded, rate: '||rate)
signal xit;
end
else do
return 0
end
return
detector:
/* detect if a message is looping by extracting middle of an incoming message-> comparing*/
parse ARG msg /* last message in */
Middle=center(prevmsg.1,20)
Middle=strip(middle) /* in case message <50 we will
have leading/trailing blanks, drop them */
Opos=pos(middle,msg) /* middle part in new message */
If opos>0 then do
prevmsg.1=msg
say "message looping deteced"
return -1
end
prevmsg.1=msg
return 1
whoami:
"id (stack"
pull whoamiuser . whoaminode . whoamistack
whoamistack=LEFT(whoamistack,5)
return
respond:
/* general TELL command for butler */
parse ARG userid,node,response
'TELL' userid 'AT' node '-> 'response
totmessages=totmessages+1
return 0
inithistory:
history.1=""
history.2=""
history.3=""
history.4=""
history.5=""
history.6=""
history.7=""
history.8=""
history.9=""
history.10=""
history.11=""
history.12=""
history.13=""
history.14=""
history.15=""
history.16=""
history.17=""
history.18=""
history.19=""
history.20=""
RETURN 0
inserthistory:
/* insert history item and scroll */
parse ARG hmsg,pointer
if pointer < history.0 then do
history.pointer = hmsg
end
if pointer >= history.0 then do
/* ok, we need to scroll up */
do i = 1 to history.0
d = i + 1
history.i =history.d
end
history.z = hmsg/* insert msg at the bottom */
end
return 0
schedule:
/* insert schedule for wakeup in linkedin list */
parse arg userid,node,scheduletime
schedulecontent = userid||"@"||node||":"||scheduletime /* jim@sevmm1 3282829 */
call @put schedulecontent
call log ("New Event to schedule list: "||schedulecontent)
call log ("New list size: "||@size())
call respond userid,node,"Got it. You will be getting a wake up message at the specified time."
return 0
scheduler:
/* called at each 1 minute by wakeup routine to send wakeme signals to users */
i=0
do i=0 to @size()
sentry=@get(i)
if sentry="" then iterate
parse value sentry with sendto':'stime
scurrenttime=epochtime()
if scurrenttime > (stime-3) then do
/* say "WMX: found matching scheduling slot. "*/
'TELL' sendto 'WAKEY WAKEY! THIS IS BUTLER WITH YOUR WAKE UP CALL!'
call compactor i /* tell compactor to remove entry i and compact the list */
end
end
return 0
compactor:
/* this s the garbage collector for the scheduler list */
parse arg delpointer /* which entry we elminate */
call @del delpointer
/* here is the algorithm to compact hte list */
return
benchmark:
/* benchmark relative system speed with nqueen problem 8x8 */
elp=time('E')
bsolution=queen(8,1)
elp=Trunc(time('e')-elp,3) /* number of seconds */
return elp
QUEEN: PROCEDURE expose count
parse arg n,noprint
chess.0=copies('. + ',n%2)
chess.1=copies('+ . ',n%2)
chessAl='a b c d e f g h i j k l m n o p q r s t u v x y z'
count = 0
k = 1
a.k = 0
do while k>0
a.k = a.k + 1
do while a.k<= n & place(k) =0
a.k = a.k +1
end
if a.k > n then k=k-1
else do /* a.k <= n */
if k=n then do
count=count+1
end
else do
k=k+1
a.k=0
end
end
end
return count
place: procedure expose a. count
/* place queens on chess board for /benchmark command */
parse arg ps
do i=1 to ps-1
if a.i = a.ps then return 0
if abs(a.i-a.ps)=(ps-i) then return 0
end
return 1
initbutler:
/* butler initialization routimes */
whoamiuser="" /* for autoconfigure */
whoaminode=""
whomistack=""
call whoami /* who the fahma am I?? */
say 'Hello, I am: '||whoamiuser||' at '||whoaminode||' with '||whoamistack
localnode=whoaminode /* set localnode */
if compatibility > 2 then do /* must be z/VM , ie min requirement VM level*/
say 'All CPU avg: 'cpu '% Paging: 'paging()
say 'Machine type: 'configuration()' RAM: 'rstorage()
say 'Number of CPU: in LPAR: 'numcpus()
END
say ' '
say '****** LOG BELOW *******'
/* some simple logging for stats etc */
CALL log('BUTLER '||butlerversion||' started. ')
Parse Value Diag(8,'QUERY TIME') With . . timenow tz tday tdate
/*-------------------------------------------*/
call inithistory
call log ('History initalized...')
call log ('Exact time in seconds: '||epochtime())
/* init double linked list of online users */
call @init
CALL log('List has been initialized.')
CALL log('List size: '||@size())
if @size() /= 0 then do
CALL log('Linked list init has failed! Abort ')
signal xit;
end
sysperf=benchmark()
CALL log('Benchmark performed. This machine speeed: '||sysperf)
CALL log('********** BUTLER START **********')
say ' ____ __ __ ____ __ ____ ____ '
say ' ( _ \( )( )(_ _)( ) ( ___)( _ \ '
say ' ) _ < )(__)( )( )(__ )__) ) / '
say ' (____/(______) (__) (____)(____)(_)\_) '
say ' '
say ' for VM/SP, VM/ESA and z/VM by Moshix '
say ' '
say ' Butler now listening for requests... '
say ' '
say ' '
say ' Feel free to #CP DISC.... '
return
p: return word(arg(1), 1) /*pick the first word out of many items*/
sy: say;
say left('', 30) " " arg(1) ' ';
return
@init: $.@=;
@adjust: $.@=space($.@);
$.#=words($.@);
return
@hasopt: arg o;
return pos(o, opt)\==0
@size: return $.#
/* */
@del: procedure expose $.;
arg k,m;
call @parms 'km'
_=subword($.@, k, k-1) subword($.@, k+m)
$.@=_;
call @adjust;
return
@get: procedure expose $.; arg k,m,dir,_
call @parms 'kmd'
do j=k for m by dir while j>0 & j<=$.#
_=_ subword($.@, j, 1)
end /*j*/
return strip(_)
@parms: arg opt /*define a variable based on an option.*/
if @hasopt('k') then k=min($.#+1, max(1, p(k 1)))
if @hasopt('m') then m=p(m 1)
if @hasopt('d') then dir=p(dir 1);
return
@put: procedure expose $.;
parse arg x,k;
k=p(k $.#+1);
call @parms 'k'
$.@=subword($.@, 1, max(0, k-1)) x subword($.@, k);
call @adjust
return
@show: procedure expose $.;
parse arg k,m,dir;
if dir==-1 & k=='' then k=$.#
m=p(m $.#);
call @parms 'kmd';
say @get(k,m, dir);
return