Skip to content

Commit 2851156

Browse files
author
nalexand
committed
go
1 parent fa3ebd9 commit 2851156

File tree

1 file changed

+324
-0
lines changed

1 file changed

+324
-0
lines changed
Lines changed: 324 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,324 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Export generator="Cache" version="25">
3+
<Class name="kutac.monitor.utils.Installer">
4+
<TimeCreated>63732,50627.865496</TimeCreated>
5+
6+
<XData name="Install">
7+
<XMLNamespace>INSTALLER</XMLNamespace>
8+
<Data><![CDATA[
9+
<Manifest>
10+
<IfNotDef Var="Namespace">
11+
<Var Name="Namespace" Value="SYSMON"/>
12+
<Log Text="Set namespace to ${Namespace}" Level="0"/>
13+
</IfNotDef>
14+
<If Condition='(##class(Config.Namespaces).Exists("${Namespace}")=0)'>
15+
<Log Text="Creating namespace ${Namespace}" Level="0"/>
16+
<Namespace Name="${Namespace}" Create="yes" Code="CACHESYS" Ensemble="" Data="CACHESYS">
17+
<Configuration>
18+
<Database Name="${Namespace}" Dir="${MGRDIR}/${Namespace}" Create="yes" MountRequired="true" Resource="%DB_${Namespace}" PublicPermissions="RW" MountAtStartup="true"/>
19+
</Configuration>
20+
<Log Text="Creating web application /csp/${Namespace}" Level="0"/>
21+
<CSPApplication Url='#{$ZCONVERT("/csp/${Namespace}", "L")}' Directory='#{##class(%DeepSee.Report.UI.reportModelServer).GetCSPDirectory()_$ZCONVERT("${Namespace}", "L")}' AuthenticationMethods="64" IsNamespaceDefault="true" />
22+
<RunInstall Class="kutac.monitor.utils.Installer" Method="EnableDeepSee"/>
23+
</Namespace>
24+
<Log Text="End Creating namespace ${Namespace} and web application /csp/${Namespace}" Level="0"/>
25+
</If>
26+
27+
<Namespace Name="${Namespace}" Create="no">
28+
<IfDef Var="SourceDir">
29+
<Log Text="SourceDir defined - offline install from ${SourceDir}" Level="0"/>
30+
<Import File="${SourceDir}"/>
31+
</IfDef>
32+
33+
<IfNotDef Var="SourceDir">
34+
<Log Text="SourceDir undefined - online install from GitHub" Level="0"/>
35+
<RunInstall Class="kutac.monitor.utils.Installer" Method="DownloadFromGitHub"/>
36+
</IfNotDef>
37+
38+
39+
40+
</Namespace>
41+
42+
43+
44+
<Log Text="Mapping kutac package to choosed namespace" Level="0"/>
45+
<Namespace Name="${Namespace}" Create="no">
46+
<ClassMapping From="${Namespace}" Package="kutac.*"/>
47+
</Namespace>
48+
49+
50+
51+
<Log Text="Moving to configuring monitor" Level="0"/>
52+
<RunInstall Class="kutac.monitor.utils.Installer" Method="ConfiguringMonitor"/>
53+
54+
55+
<!--<Log Text="Configuring startup namespace" Level="0"/>
56+
<RunInstall Class="kutac.monitor.utils.Installer" Method="ConfiguringClasses"/>
57+
58+
<Log Text="Activating Monitor Classes" Level="0"/>
59+
<RunInstall Class="kutac.monitor.utils.Installer" Method="ActivatingingClasses"/>
60+
61+
<Log Text="Starting Monitor" Level="0"/>
62+
<RunInstall Class="kutac.monitor.utils.Installer" Method="RunningMonitor"/>-->
63+
64+
65+
66+
</Manifest>
67+
]]></Data>
68+
</XData>
69+
70+
<Method name="setup">
71+
<Description>
72+
This is a method generator whose code is generated by XGL.
73+
Set pVars("Namespace")="SYSMON"
74+
Set pVars("SourceDir")="C:\temp\SYSMON\cls\kutac\"
75+
do ##class(kutac.monitor.utils.Installer).setup(.pVars)</Description>
76+
<Internal>1</Internal>
77+
<ClassMethod>1</ClassMethod>
78+
<CodeMode>objectgenerator</CodeMode>
79+
<FormalSpec><![CDATA[&pVars,pLogLevel:%Integer=0,pInstaller:%Installer.Installer]]></FormalSpec>
80+
<ReturnType>%Status</ReturnType>
81+
<Implementation><![CDATA[ Quit ##class(%Installer.Manifest).%Generate(%compiledclass, %code, "Install")
82+
]]></Implementation>
83+
</Method>
84+
85+
<Method name="EnableDeepSee">
86+
<ClassMethod>1</ClassMethod>
87+
<FormalSpec>pVars,pLogLevel,tInstaller</FormalSpec>
88+
<ReturnType>%Status</ReturnType>
89+
<Implementation><![CDATA[
90+
do EnableDeepSee^%SYS.cspServer("/csp/"_$ZCONVERT(pVars("Namespace"), "L")_"/")
91+
quit $$$OK
92+
]]></Implementation>
93+
</Method>
94+
95+
<Method name="DownloadFromGitHub">
96+
<ClassMethod>1</ClassMethod>
97+
<FormalSpec>pVars,pLogLevel,tInstaller</FormalSpec>
98+
<ReturnType>%Status</ReturnType>
99+
<Implementation><![CDATA[
100+
Set Namespace=tInstaller.Evaluate("${Namespace}")
101+
Do tInstaller.PushNS("%SYS")
102+
Set tSC = ..Update(Namespace, "intersystems-ru", "deepsee-sysmon-dashboards", "master")
103+
Do tInstaller.PopNS()
104+
If $$$ISERR(tSC) Throw ##class(%Installer.Exception).CreateFromStatus(tSC)
105+
quit $$$OK
106+
]]></Implementation>
107+
</Method>
108+
109+
<Method name="Update">
110+
<ClassMethod>1</ClassMethod>
111+
<FormalSpec>Namespace=$Namespace,Owner:%String="intersystems-ru",Repository:%String="deepsee-sysmon-dashboards",Branch:%String,Username:%String="alexandrov-nikita",Password:%String="lolipops561azaza"</FormalSpec>
112+
<ReturnType>%Status</ReturnType>
113+
<Implementation><![CDATA[
114+
Set namespace = $Namespace
115+
Set SSLConfig = "GitHub"
116+
Zn "%SYS"
117+
Do:'##class(Security.SSLConfigs).Exists(SSLConfig) ##class(Security.SSLConfigs).Create(SSLConfig)
118+
119+
Set req=##class(%Net.HttpRequest).%New()
120+
Set req.Https=1
121+
Set req.SSLConfiguration=SSLConfig
122+
Set req.Server="api.github.com"
123+
Set req.Location = "repos/" _ Owner _ "/" _ Repository _ "/contents" // as described in https://developer.github.com/v3/repos/
124+
Do:$d(Branch) req.SetParam("ref",Branch) // if omitted the repository’s default branch (usually master) would be used
125+
Do req.SetHeader("Accept","application/vnd.github.v3+json") // we want to receive API v3
126+
127+
If ($d(Username) && $d(Password)) { // supply Username and Passwor, if both are provided. GitHub accept Basic Auth
128+
Set req.Username = Username // https://developer.github.com/v3/auth/
129+
Set req.Password = Password
130+
}
131+
132+
Set links = ##class(%ListOfDataTypes).%New()
133+
Set st = ..ProcessDirectory("",req,.links)
134+
Return:$$$ISERR(st) st
135+
136+
Zn Namespace
137+
Set st = ..DownloadFiles(links,req,.list)
138+
Set st2 = $system.OBJ.CompileList(.list)
139+
Zn namespace
140+
141+
Return $$$ADDSC(st, st2)
142+
]]></Implementation>
143+
</Method>
144+
145+
<Method name="ProcessDirectory">
146+
<ClassMethod>1</ClassMethod>
147+
<FormalSpec><![CDATA[Path:%String="",Request:%Net.HttpRequest,&Links:%ListOfDataTypes]]></FormalSpec>
148+
<ReturnType>%Status</ReturnType>
149+
<Implementation><![CDATA[
150+
Set location = Request.Location
151+
Set Request.Location = Request.Location _ Path
152+
153+
Set st = Request.Get()
154+
Return:$$$ISERR(st) st
155+
Return:(Request.HttpResponse.StatusCode = 404) $$$ERROR($$$GeneralError,"Repository doesn't exist OR you don't have access")
156+
Return:((Request.HttpResponse.StatusCode = 403) && (Request.HttpResponse.GetHeader("X-RATELIMIT-REMAINING")=0)) $$$ERROR($$$GeneralError,"API rate limit exceeded. Try logging in.")
157+
Return:(Request.HttpResponse.StatusCode '= 200) $$$ERROR($$$GeneralError,"Received " _ Request.HttpResponse.StatusCode _ " status, expected 200")
158+
159+
#dim objects As List of %ZEN.proxyObject
160+
#dim obj As %ZEN.proxyObject
161+
Set st = ##class(%ZEN.Auxiliary.jsonProvider).%ConvertJSONToObject(Request.HttpResponse.Data,,.objects,1)
162+
Return:$$$ISERR(st) st
163+
164+
For i = 1:1:objects.Count() {
165+
Set obj = objects.GetAt(i)
166+
If (obj.type = "dir") {
167+
Set st = ..ProcessDirectory("/"_obj.name,Request,.Links)
168+
Return:$$$ISERR(st) st
169+
} ElseIf (obj.type = "file") {
170+
Do:..IsCacheFile(obj) Links.Insert(obj."download_url")
171+
} Else {
172+
// obj.type = "symlink" or obj.type = "submodule"
173+
}
174+
}
175+
Set Request.Location = location // to keep track of where in the repository tree we are
176+
Return $$$OK
177+
]]></Implementation>
178+
</Method>
179+
180+
<Method name="IsCacheFile">
181+
<ClassMethod>1</ClassMethod>
182+
<FormalSpec>File:%ZEN.proxyObject</FormalSpec>
183+
<ReturnType>%Boolean</ReturnType>
184+
<Implementation><![CDATA[
185+
Set extensions = ",xml,cls,csp,csr,mac,int,bas,inc,gbl,prj,obj,pkg,gof,"
186+
Return:($L(File.name,".")=1) 0 //no extension
187+
Set File.Extension = $P(File.name,".",$L(File.name,"."))
188+
Return $F(extensions,","_$ZCVT(File.Extension,"l")_",")
189+
]]></Implementation>
190+
</Method>
191+
192+
<Method name="DownloadFiles">
193+
<ClassMethod>1</ClassMethod>
194+
<FormalSpec>Links:%ListOfDataTypes,Request:%Net.HttpRequest,*Items</FormalSpec>
195+
<ReturnType>%Status</ReturnType>
196+
<Implementation><![CDATA[
197+
Kill Items
198+
Set Request.Server = "raw.githubusercontent.com"
199+
Set st = $$$OK
200+
201+
For i = 1:1:Links.Count() {
202+
Set streq = Request.Get($e(Links.GetAt(i),35,*)) // Remove "https://raw.githubusercontent.com/" from URL.
203+
Set:$$$ISERR(streq) st=$$$ADDSC(st, streq)
204+
Set stload = $system.OBJ.LoadStream(Request.HttpResponse.Data,"",.error,.items)
205+
Set:$$$ISERR(stload) st=$$$ADDSC(st, stload)
206+
Merge Items = items
207+
}
208+
209+
Set Request.Server="api.github.com"
210+
Return st
211+
]]></Implementation>
212+
</Method>
213+
214+
<Method name="ConfiguringMonitor">
215+
<ClassMethod>1</ClassMethod>
216+
<FormalSpec>pVars,pLogLevel,tInstaller</FormalSpec>
217+
<ReturnType>%Status</ReturnType>
218+
<Implementation><![CDATA[
219+
Set Namespace=tInstaller.Evaluate("${Namespace}")
220+
Do tInstaller.PushNS("%SYS")
221+
write !, "Configuring startup namespace"
222+
set st1 = ..ConfiguringClasses(Namespace)
223+
write !, "Activating Monitor Classes"
224+
set st2 = ..ActivatingClasses()
225+
write !, "Starting Monitor"
226+
set st3 = ..RunningMonitor()
227+
write !, "Creating Task"
228+
Do tInstaller.PopNS()
229+
Do tInstaller.PushNS(Namespace)
230+
set st4 = ..CreateTask()
231+
Do tInstaller.PopNS()
232+
set st = $$$ADDSC(st4, $$$ADDSC(st1, $$$ADDSC(st2, st3)))
233+
if $$$ISERR(st) Throw ##class(%Installer.Exception).CreateFromStatus(st)
234+
quit $$$OK
235+
]]></Implementation>
236+
</Method>
237+
238+
<Method name="ConfiguringClasses">
239+
<ClassMethod>1</ClassMethod>
240+
<FormalSpec>Namespace=$Namespace</FormalSpec>
241+
<ReturnType>%Status</ReturnType>
242+
<Implementation><![CDATA[
243+
Set rsm = ##class(%SYS.Monitor).SetStartNS(Namespace)
244+
if rsm'=1
245+
{
246+
write !, "Error setting Monitor namespaces: "_$ze,!
247+
//quit $$$ISERR
248+
}
249+
250+
Set rsys = ##class(%SYS.Monitor).SetStartNS("%SYS")
251+
if rsys'=1
252+
{
253+
write !, "Error setting Monitor namespaces: "_$ze,!
254+
//quit $$$ISERR
255+
}
256+
//quit $$$OK
257+
return $$$ADDSC(rsm, rsys)
258+
]]></Implementation>
259+
</Method>
260+
261+
<Method name="ActivatingClasses">
262+
<ClassMethod>1</ClassMethod>
263+
<ReturnType>%Status</ReturnType>
264+
<Implementation><![CDATA[
265+
set act = $LISTBUILD("%Monitor.System.HistoryPerf","%Monitor.System.Diskspace","%Monitor.System.License","%Monitor.System.Processes","%Monitor.System.HistorySys","%Monitor.System.Freespace","%Monitor.System.LockTable","%Monitor.System.Routines")
266+
set str = $LISTTOSTRING(act)
267+
for i = 1:1:$LISTLENGTH(act)
268+
{
269+
set cls = $PIECE(str, ",", i)
270+
set id = ""
271+
do ##class(%Monitor.ItemGroup).MetricsClassItemGroup(cls,.id)
272+
s class = ##class(%Monitor.ItemGroup).%OpenId(id)
273+
if '$IsObject(class)
274+
{
275+
write !,"ERROR: Class '"_cls_"' does not exist",!
276+
}
277+
else
278+
{
279+
set class.Activated = 1
280+
set status = class.%Save()
281+
if ('status)
282+
{
283+
w $System.Status.GetErrorText(st)
284+
}
285+
}
286+
}
287+
return $$$OK
288+
]]></Implementation>
289+
</Method>
290+
291+
<Method name="RunningMonitor">
292+
<ClassMethod>1</ClassMethod>
293+
<ReturnType>%Status</ReturnType>
294+
<Implementation><![CDATA[
295+
set sc = ##class(%SYS.Monitor).Start()
296+
if sc = 1
297+
{
298+
write !, " System Monitor started"
299+
}
300+
elseif sc = -1
301+
{
302+
write !, " System Monitor already running!"
303+
}
304+
else
305+
{
306+
write !,"ERROR: "_$ZE
307+
return sc
308+
}
309+
return $$$OK
310+
]]></Implementation>
311+
</Method>
312+
313+
<Method name="CreateTask">
314+
<ClassMethod>1</ClassMethod>
315+
<FormalSpec>hrs:%Integer=3</FormalSpec>
316+
<ReturnType>%Status</ReturnType>
317+
<Implementation><![CDATA[
318+
319+
//q ##class(%DeepSee.CubeManager.Task.Synch).Schedule(0, 1, 1, hrs, ($p($H, ",", 2) + 60) # 10800, 0)
320+
q ##class(%DeepSee.CubeManager.Task.Build).Schedule(0, 0, 1, "", ($p($H, ",", 2) + 60))
321+
]]></Implementation>
322+
</Method>
323+
</Class>
324+
</Export>

0 commit comments

Comments
 (0)