Refactoring: Changed all check parameters starting with an 'o' to the new rulespec...
[check_mk.git] / agents / check_mk_agent.openvms
blob82fa8e4466890a8477feddbec41b4cbcba6438a1
1 $!# Check_MK Agent for OpenVMS
2 $!# +------------------------------------------------------------------+
3 $!# |             ____ _               _        __  __ _  __           |
4 $!# |            / ___| |__   ___  ___| | __   |  \/  | |/ /           |
5 $!# |           | |   | '_ \ / _ \/ __| |/ /   | |\/| | ' /            |
6 $!# |           | |___| | | |  __/ (__|   <    | |  | | . \            |
7 $!# |            \____|_| |_|\___|\___|_|\_\___|_|  |_|_|\_\           |
8 $!# |                                                                  |
9 $!# | Copyright Mathias Kettner 2014             mk@mathias-kettner.de |
10 $!# +------------------------------------------------------------------+
11 $!#
12 $!# This file is part of Check_MK.
13 $!# The official homepage is at http://mathias-kettner.de/check_mk.
14 $!#
15 $!# check_mk is free software;  you can redistribute it and/or modify it
16 $!# under the  terms of the  GNU General Public License  as published by
17 $!# the Free Software Foundation in version 2.  check_mk is  distributed
18 $!# in the hope that it will be useful, but WITHOUT ANY WARRANTY;  with-
19 $!# out even the implied warranty of  MERCHANTABILITY  or  FITNESS FOR A
20 $!# PARTICULAR PURPOSE. See the  GNU General Public License for more de-
21 $!# tails. You should have  received  a copy of the  GNU  General Public
22 $!# License along with GNU Make; see the file  COPYING.  If  not,  write
23 $!# to the Free Software Foundation, Inc., 51 Franklin St,  Fifth Floor,
24 $!# Boston, MA 02110-1301 USA.
26 $!# Author:     Paul Aebersold, netPuls          info@netpuls.info
27 $if p1 .nes. "" then set verify
28 $msgOff := set message/nofacility/noseverity/noidentification/notext
29 $msgOn := set message/facility/severity/identification/text
30 $set noOn
31 $'msgOff'
32 $samplePeriod = 90
33 $sampleInterval = 3
34 $cmdProcedure = f$environment("procedure")
35 $actlDirectory = f$parse(cmdProcedure,,,"device") + -
36 f$parse(cmdProcedure,,,"directory")
37 $if f$search("''f$trnlnm("sys$scratch")'tmp.dir") .eqs. ""
38 $then
39 $tmpDirectory = f$trnlnm("sys$scratch")
40 $else
41 $tmpDirectory = f$trnlnm("sys$scratch")-"]"+".tmp]"
42 $endif
43 $errFile = "''tmpDirectory'VMSagent.err"
44 $cacheFile = "''actlDirectory'VMSagent.cache"
45 $cacheMaxAge = 120
46 $sampleFile = "''actlDirectory'myMon.lis"
47 $tempFile = "''tmpDirectory'outFile.tmp"
48 $tmpCMS = "''tmpDirectory'tmp.CMS"
49 $tmpDisksm = "''tmpDirectory'tmp.mDk"
50 $tmpDisks = "''tmpDirectory'tmp.Dsk"
51 $tmpNetif = "''tmpDirectory'tmp.nif"
52 $tmpQueues = "''tmpDirectory'tmp.Que"
53 $tmpUsr = "''tmpDirectory'tmp.Usr"
54 $say = "write sys$output"
55 $modeNet = f$edit(f$mode(),"lowercase,trim") .eqs. "network"
56 $modeDirect = f$environment("interactive") .and. "true"
57 $if .not. modeNet then define/nolog sys$error 'errFile'
58 $if modeDirect
59 $then
60 $samplePeriod = 10
61 $sampleInterval = 1
62 $cacheMaxAge = 45
63 $'msgOn'
64 $endif
65 $useCacheFile="false"
66 $if f$search("''cacheFile'") .nes. ""
67 $then
68 $if (f$cvtime(f$time(),,"secondofyear")-f$cvtime( -
69 f$file("''cacheFile'","rdt"),,"secondofyear") -
70 ) .le. 'cacheMaxAge' then useCacheFile="true"
71 $if f$getjpi("","prcnam") .nes. "VMSagnt$collect"
72 $then
73 $type/nohead 'cacheFile'
74 $else
75 $goto collectStart
76 $endif
77 $endif
78 $if (.not. useCacheFile) .and. (f$search("''cacheFile'_new") .eqs. "")
79 $then
80 $run sys$system:loginout.exe /detached/noswap/authorize -
81 /input='cmdProcedure'/process_name="VMSagnt$collect" -
82 /uic='f$getjpi("","uic")'/output=nl:/error='errFile'
83 $endif
84 $exit
85 $collectStart:
86 $'msgOff'
87 $set noVerify
88 $create/protection=(g:r,w) 'cacheFile'_new
89 $HWinfo = f$edit(f$getsyi("arch_name"),"trim")
90 $numCPU = f$getsyi("activecpu_cnt")
91 $MEMtotal = f$getsyi("memsize")
92 $PGinfo = f$getsyi("page_size")
93 $SWinfo = f$edit(f$getsyi("version"),"trim")
94 $if sampleInterval .gt. samplePeriod then sampleInterval=samplePeriod/5
95 $if (samplePeriod .gt. 600) .or. (samplePeriod .lt. 10) then -
96 samplePeriod=60
97 $if (sampleInterval .gt. 60) .or. (sampleInterval .lt. 1) then -
98 sampleInterval=10
99 $sMin=samplePeriod/60
100 $sSec=samplePeriod-sMin*60
101 $monitor/nodisplay/interval='sampleInterval'/summary='sampleFile' -
102 /ending="+0-0:''sMin':''sSec'" system/all, -
103 disk/all/item=operation_rate
104 $wait 0:0:0.50
105 $gosub create_tmpFiles
106 $gosub create_output
107 $gosub do_output
108 $if .not. modeNet then deassign sys$error
109 $if f$search("''errFile'") .nes. "" then purge/nolog/keep=2 'errFile'
110 $if f$search("''sampleFile'") .nes. "" then -
111 delete/noconfirm/nolog 'sampleFile';*
112 $if f$search("''tmpDirectory'tmp.*") .nes. "" then -
113 delete/noconfirm/nolog 'tmpDirectory'tmp.*;*
114 $pipe delete/noconfirm/nolog 'cacheFile';* && -
115 rename/nolog/noconfirm 'cacheFile'_new 'cacheFile' || -
116 rename/nolog/noconfirm 'cacheFile'_new 'cacheFile'
117 $exit
118 $create_tmpFiles:
119 $search/nowarnings/noheading/format=nonull/exact/output='tmpCMS' -
120 'sampleFile' "Interrupt State","MP Synchronization","User Mode", -
121 "Idle Time","Free List Size","Process Count","Direct I/O Rate", -
122 "Buffered I/O Rate"
123 $search/nowarnings/noheading/format=nonull/exact/output='tmpDisks' -
124 'sampleFile' "$DK","DSA","$1$DG"
125 $if f$extract(1,1,"''SWinfo'") .ge. 8
126 $then
127 $pipe tcpip netstat -in | search/wild/output='tmpNetif' -
128 sys$pipe *.*.*.*,127.0.0./match=xor
129 $else
130 $endif
131 $show system/batch/noheading/output='tmpQueues'
132 $show users/interactive/subprocess/batch/network/nohead/output='tmpUsr'
133 $return
134 $create_output:
135 $open/read inFile 'tmpCMS'
136 $CMSline:
137 $read/end_of_file=CMSdone/error=CMSdone inFile line
138 $cLine = f$edit(line,"compress,trim")
139 $if f$element(0," ",cLine) .eqs. "Interrupt" then -
140 wt0 = f$element(3," ",cLine)
141 $if f$element(1," ",cLine) .eqs. "Synchronization" then -
142 wt1 = f$element(3," ",cLine)
143 $if f$element(0," ",cLine) .eqs. "User" then -
144 cpu3 = f$element(3," ",cLine)
145 $if f$element(0," ",cLine) .eqs. "Idle" then -
146 cpu2 = f$element(3," ",cLine)
147 $if f$element(0," ",cLine) .eqs. "Free" then -
148 freeMem = f$element(0,".",f$element(4," ",cLine))
149 $if f$element(0," ",cLine) .eqs. "Process" then -
150 sys3 = f$element(3," ",cLine)
151 $if f$element(0," ",cLine) .eqs. "Direct" then -
152 sys1 = f$element(4," ",cLine)
153 $if f$element(0," ",cLine) .eqs. "Buffered" then -
154 sys2 = f$element(4," ",cLine)
155 $goto CMSline
156 $CMSdone:
157 $close inFile
158 $return
159 $do_output:
160 $if f$search("''cacheFile'_new") .nes. "" then -
161 delete/noconfirm/nolog 'cacheFile'_new;*
162 $set noVerify
163 $define sys$output "''cacheFile'_new"
164 $on error then goto WCFdone
165 $say "<<<check_mk>>>"
166 $say "Version: 1.6.0i1"
167 $say "AgentOS: openvms"
168 $say "Nodename: ",f$getsyi("nodename")
169 $say "Architecture: ''HWinfo'"
170 $say "SWversion: ''SWinfo'"
171 $say "<<<vms_cpu>>>"
172 $say "''numCPU' ''cpu2' ''cpu3' ''wt0' ''wt1'"
173 $say "<<<mem>>>"
174 $say "MemTotal: ",'MEMtotal'*('PGinfo'/1024)
175 $say "MemFree: ",'freeMem'*('PGinfo'/1024)
176 $say "SwapTotal: ",f$getsyi("swapfile_page")*('PGinfo'/1024)
177 $say "SwapFree: ",f$getsyi("swapfile_free")*('PGinfo'/1024)
178 $say "<<<vms_system>>>"
179 $say "''sys1' ''sys2' ''sys3'"
180 $say "<<<vms_diskstat>>>"
181 $gosub DSKloop
182 $say "<<<vms_if>>>"
183 $gosub NIFloop
184 $say "<<<vms_queuejobs>>>"
185 $gosub QUEloop
186 $say "<<<vms_users>>>"
187 $gosub USRloop
188 $WCFdone:
189 $set noOn
190 $deassign sys$output
191 $return
192 $DSKloop:
193 $open/read inFile 'tmpDisks'
194 $DSKline:
195 $read/end_of_file=DSKdone/error=DSKdone inFile line
196 $cLine = f$edit(line,"compress,trim")
197 $Dname = f$element(0," ",cLine)
198 $if f$extract(0,1,f$element(1," ",cLine)) .nes. "("
199 $then
200 $say f$element(0," ",cLine)," ",f$element(1," ",cLine)," ", -
201 f$getdvi("''Dname'","maxblock")," ", -
202 f$getdvi("''Dname'","freeblocks")," ",f$element(5," ",cLine)
203 $else
204 $say f$element(0," ",cLine)," ",f$element(2," ",cLine)," ", -
205 f$getdvi("''Dname'","maxblock")," ", -
206 f$getdvi("''Dname'","freeblocks")," ",f$element(6," ",cLine)
207 $endif
208 $goto DSKline
209 $DSKdone:
210 $close inFile
211 $return
212 $NIFloop:
213 $if f$extract(1,1,"''SWinfo'") .lt. 8 then return
214 $open/read inFile 'tmpNetif'
215 $NIFline:
216 $read/end_of_file=NIFdone/error=NIFdone inFile line
217 $cLine = f$edit(line,"compress,trim")
218 $say f$element(0," ",cLine)," ",0," ",f$element(4," ",cLine)," ", -
219 0," ",0," ",0," ",f$element(5," ",cLine)," ",0," ", -
220 f$element(6," ",cLine)," ",0," ",0," ",0," ",f$element(7," ",cLine)
221 $goto NIFline
222 $NIFdone:
223 $close inFile
224 $return
225 $USRloop:
226 $open/read inFile 'tmpUsr'
227 $USRline:
228 $read/end_of_file=USRdone/error=USRdone inFile line
229 $cLine = f$edit(line,"compress,trim")
230 $say f$element(0," ",cLine)," ",f$element(1," ",cLine)," ", -
231 f$element(2," ",cLine)," ",f$element(3," ",cLine)," ", -
232 f$element(4," ",cLine)
233 $goto USRline
234 $USRdone:
235 $close inFile
236 $return
237 $QUEloop:
238 $open/read inFile 'tmpQueues'
239 $QUEline:
240 $read/end_of_file=QUEdone/error=QUEdone inFile cLine
241 $say f$extract(0,8,cLine)," ", -
242 f$edit(f$extract(9,15,cLine),"trim")," ", -
243 f$edit(f$extract(25,4,cLine),"trim")," ", -
244 f$edit(f$extract(45,15,cLine),"trim")," ", -
245 f$edit(f$extract(35,10,cLine),"trim")," ", -
246 f$edit(f$extract(60,10,cLine),"trim")
247 $goto QUEline
248 $QUEdone:
249 $close inFile
250 $return
251 $!######################[:END:  check_mk_agent.com  :END:]######################