Guest User

Untitled

a guest
Dec 16th, 2024
13
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 36.11 KB | None | 0 0
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <ManagementPack SchemaVersion="2.0" ContentReadable="true" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  3. <Manifest>
  4. <Identity>
  5. <ID>Test.Lala.Folders.Monitoring</ID>
  6. <Version>1.0.0.304</Version>
  7. </Identity>
  8. <Name>Test Lala Folders Monitoring</Name>
  9. <References>
  10. <Reference Alias="SC">
  11. <ID>Microsoft.SystemCenter.Library</ID>
  12. <Version>7.0.8433.0</Version>
  13. <PublicKeyToken>31bf3856ad364e35</PublicKeyToken>
  14. </Reference>
  15. <Reference Alias="Windows">
  16. <ID>Microsoft.Windows.Library</ID>
  17. <Version>7.5.8501.0</Version>
  18. <PublicKeyToken>31bf3856ad364e35</PublicKeyToken>
  19. </Reference>
  20. <Reference Alias="Health">
  21. <ID>System.Health.Library</ID>
  22. <Version>7.0.8433.0</Version>
  23. <PublicKeyToken>31bf3856ad364e35</PublicKeyToken>
  24. </Reference>
  25. <Reference Alias="System">
  26. <ID>System.Library</ID>
  27. <Version>7.5.8501.0</Version>
  28. <PublicKeyToken>31bf3856ad364e35</PublicKeyToken>
  29. </Reference>
  30. </References>
  31. </Manifest>
  32. <TypeDefinitions>
  33. <EntityTypes>
  34. <ClassTypes>
  35. <ClassType ID="Test.Lala.ConfigFile.Class" Accessibility="Internal" Abstract="false" Base="Windows!Microsoft.Windows.LocalApplication" Hosted="true" Singleton="false" Extension="false">
  36. <Property ID="FullName" Key="false" Type="string" Required="true" />
  37. <Property ID="FileName" Key="true" Type="string" Required="true" />
  38. <Property ID="LastWriteTime" Key="false" Type="string" Required="true" />
  39. <Property ID="Interval" Key="false" Type="int" Required="true" />
  40. </ClassType>
  41. <ClassType ID="Test.Lala.Folder.Class" Accessibility="Internal" Abstract="false" Base="Windows!Microsoft.Windows.ApplicationComponent" Hosted="true" Singleton="false" Extension="false">
  42. <Property ID="FolderPath" Key="true" Type="string" Required="true" />
  43. </ClassType>
  44. </ClassTypes>
  45. <RelationshipTypes>
  46. <RelationshipType ID="ConfigHostsFolder" Base="System!System.Hosting" Accessibility="Public">
  47. <Source ID="LocalApplication" Type="Test.Lala.ConfigFile.Class" />
  48. <Target ID="ApplicationComponent" Type="Test.Lala.Folder.Class" />
  49. </RelationshipType>
  50. </RelationshipTypes>
  51. </EntityTypes>
  52. <ModuleTypes>
  53. <DataSourceModuleType ID="PS.DS.With.SpreadInitializationOverInterval" Accessibility="Public">
  54. <Configuration>
  55. <IncludeSchemaTypes>
  56. <SchemaType>Windows!Microsoft.Windows.PowerShellSchema</SchemaType>
  57. </IncludeSchemaTypes>
  58. <xsd:element name="IntervalSeconds" type="xsd:int" xmlns:xsd="http://www.w3.org/2001/XMLSchema" />
  59. <xsd:element name="SpreadInitializationOverInterval" type="xsd:int" xmlns:xsd="http://www.w3.org/2001/XMLSchema" />
  60. <xsd:element name="ScriptName" type="NonNullString" xmlns:xsd="http://www.w3.org/2001/XMLSchema" />
  61. <xsd:element name="ScriptBody" type="NonNullString" xmlns:xsd="http://www.w3.org/2001/XMLSchema" />
  62. <xsd:element name="SnapIns" type="SnapInsType" minOccurs="0" maxOccurs="1" xmlns:xsd="http://www.w3.org/2001/XMLSchema" />
  63. <xsd:element name="Parameters" type="NamedParametersType" minOccurs="0" maxOccurs="1" xmlns:xsd="http://www.w3.org/2001/XMLSchema" />
  64. <xsd:element name="TimeoutSeconds" type="xsd:integer" xmlns:xsd="http://www.w3.org/2001/XMLSchema" />
  65. <xsd:element name="StrictErrorHandling" type="xsd:boolean" minOccurs="0" maxOccurs="1" xmlns:xsd="http://www.w3.org/2001/XMLSchema" />
  66. </Configuration>
  67. <OverrideableParameters>
  68. <OverrideableParameter ID="IntervalSeconds" Selector="$Config/IntervalSeconds$" ParameterType="int" />
  69. <OverrideableParameter ID="SpreadInitializationOverInterval" Selector="$Config/SpreadInitializationOverInterval$" ParameterType="int" />
  70. <OverrideableParameter ID="TimeoutSeconds" Selector="$Config/TimeoutSeconds$" ParameterType="int" />
  71. </OverrideableParameters>
  72. <ModuleImplementation>
  73. <Composite>
  74. <MemberModules>
  75. <DataSource TypeID="System!System.Discovery.Scheduler" ID="DS1">
  76. <Scheduler>
  77. <SimpleReccuringSchedule>
  78. <Interval>$Config/IntervalSeconds$</Interval>
  79. <SpreadInitializationOverInterval Unit="Seconds">$Config/SpreadInitializationOverInterval$</SpreadInitializationOverInterval>
  80. </SimpleReccuringSchedule>
  81. <ExcludeDates />
  82. </Scheduler>
  83. </DataSource>
  84. <ProbeAction TypeID="Windows!Microsoft.Windows.PowerShellDiscoveryProbe" ID="PSScript">
  85. <ScriptName>$Config/ScriptName$</ScriptName>
  86. <ScriptBody>$Config/ScriptBody$</ScriptBody>
  87. <SnapIns>$Config/SnapIns$</SnapIns>
  88. <Parameters>$Config/Parameters$</Parameters>
  89. <TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
  90. <StrictErrorHandling>$Config/StrictErrorHandling$</StrictErrorHandling>
  91. </ProbeAction>
  92. </MemberModules>
  93. <Composition>
  94. <Node ID="PSScript">
  95. <Node ID="DS1" />
  96. </Node>
  97. </Composition>
  98. </Composite>
  99. </ModuleImplementation>
  100. <OutputType>System!System.Discovery.Data</OutputType>
  101. </DataSourceModuleType>
  102. <DataSourceModuleType ID="PowerShellDataSource" Accessibility="Public">
  103. <Configuration>
  104. <IncludeSchemaTypes>
  105. <SchemaType>Windows!Microsoft.Windows.PowerShellSchema</SchemaType>
  106. </IncludeSchemaTypes>
  107. <xsd:element name="IntervalSeconds" type="xsd:int" xmlns:xsd="http://www.w3.org/2001/XMLSchema" />
  108. <xsd:element name="SyncTime" type="xsd:string" xmlns:xsd="http://www.w3.org/2001/XMLSchema" />
  109. <xsd:element name="ScriptName" type="NonNullString" xmlns:xsd="http://www.w3.org/2001/XMLSchema" />
  110. <xsd:element name="ScriptBody" type="NonNullString" xmlns:xsd="http://www.w3.org/2001/XMLSchema" />
  111. <xsd:element name="SnapIns" type="SnapInsType" minOccurs="0" maxOccurs="1" xmlns:xsd="http://www.w3.org/2001/XMLSchema" />
  112. <xsd:element name="Parameters" type="NamedParametersType" minOccurs="0" maxOccurs="1" xmlns:xsd="http://www.w3.org/2001/XMLSchema" />
  113. <xsd:element name="TimeoutSeconds" type="xsd:integer" xmlns:xsd="http://www.w3.org/2001/XMLSchema" />
  114. <xsd:element name="StrictErrorHandling" type="xsd:boolean" minOccurs="0" maxOccurs="1" xmlns:xsd="http://www.w3.org/2001/XMLSchema" />
  115. </Configuration>
  116. <ModuleImplementation>
  117. <Composite>
  118. <MemberModules>
  119. <DataSource ID="Scheduler" TypeID="System!System.SimpleScheduler">
  120. <IntervalSeconds>$Config/IntervalSeconds$</IntervalSeconds>
  121. <SyncTime>$Config/SyncTime$</SyncTime>
  122. </DataSource>
  123. <ProbeAction ID="PSScript" TypeID="Windows!Microsoft.Windows.PowerShellPropertyBagProbe">
  124. <ScriptName>$Config/ScriptName$</ScriptName>
  125. <ScriptBody>$Config/ScriptBody$</ScriptBody>
  126. <SnapIns>$Config/SnapIns$</SnapIns>
  127. <Parameters>$Config/Parameters$</Parameters>
  128. <TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
  129. <StrictErrorHandling>$Config/StrictErrorHandling$</StrictErrorHandling>
  130. </ProbeAction>
  131. </MemberModules>
  132. <Composition>
  133. <Node ID="PSScript">
  134. <Node ID="Scheduler" />
  135. </Node>
  136. </Composition>
  137. </Composite>
  138. </ModuleImplementation>
  139. <OutputType>System!System.PropertyBagData</OutputType>
  140. </DataSourceModuleType>
  141. </ModuleTypes>
  142. <MonitorTypes>
  143. <UnitMonitorType ID="CheckFolderDate.MonitorType" Accessibility="Public">
  144. <MonitorTypeStates>
  145. <MonitorTypeState ID="Healthy" />
  146. <MonitorTypeState ID="Critical" />
  147. </MonitorTypeStates>
  148. <Configuration>
  149. <IncludeSchemaTypes>
  150. <SchemaType>Windows!Microsoft.Windows.PowerShellSchema</SchemaType>
  151. <SchemaType>System!System.ExpressionEvaluatorSchema</SchemaType>
  152. </IncludeSchemaTypes>
  153. <xsd:element name="IntervalSeconds" type="xsd:int" xmlns:xsd="http://www.w3.org/2001/XMLSchema" />
  154. <xsd:element name="SyncTime" type="xsd:string" xmlns:xsd="http://www.w3.org/2001/XMLSchema" />
  155. <!--<xsd:element name="ScriptName" type="NonNullString" xmlns:xsd="http://www.w3.org/2001/XMLSchema" />
  156. <xsd:element name="ScriptBody" type="NonNullString" xmlns:xsd="http://www.w3.org/2001/XMLSchema" />-->
  157. <!--<xsd:element name="SnapIns" type="SnapInsType" minOccurs="0" maxOccurs="1" xmlns:xsd="http://www.w3.org/2001/XMLSchema" />-->
  158. <xsd:element name="Parameters" type="NamedParametersType" minOccurs="0" maxOccurs="1" xmlns:xsd="http://www.w3.org/2001/XMLSchema" />
  159. <!--<xsd:element name="TimeoutSeconds" type="xsd:integer" xmlns:xsd="http://www.w3.org/2001/XMLSchema" />-->
  160. <!--<xsd:element name="StrictErrorHandling" type="xsd:boolean" minOccurs="0" maxOccurs="1" xmlns:xsd="http://www.w3.org/2001/XMLSchema" />-->
  161. <!-- <xsd:element name="HealthyExpression" type="ExpressionType" xmlns:xsd="http://www.w3.org/2001/XMLSchema" />
  162. <xsd:element name="CriticalExpression" type="ExpressionType" xmlns:xsd="http://www.w3.org/2001/XMLSchema" />-->
  163. <!--<xsd:element name="Schedule" type="PublicSchedulerType" xmlns:xsd="http://www.w3.org/2001/XMLSchema" />-->
  164. </Configuration>
  165. <MonitorImplementation>
  166. <MemberModules>
  167. <DataSource ID="PSScript" TypeID="PowerShellDataSource">
  168. <IntervalSeconds>$Config/IntervalSeconds$</IntervalSeconds>
  169. <SyncTime />
  170. <ScriptName>CheckFolderDate10min.ps1</ScriptName>
  171. <ScriptBody><![CDATA[Param
  172. (
  173. [int]$Interval, ## $Target/Host/Property[Type="Test.Lala.ConfigFile.Class"]/Interval$</Value>
  174. [string]$FullName ## $Target/Host/Property[Type="Test.Lala.ConfigFile.Class"]/FullName$</Value>
  175. )
  176.  
  177. $oAPI = New-Object -comObject MOM.ScriptAPI
  178.  
  179. $limit = (Get-Date).AddMinutes(-($Interval))
  180.  
  181. try
  182. {
  183. $reader = [System.IO.File]::OpenText("$FullName")
  184.  
  185. while($null -ne ($line = $reader.ReadLine())) ## $line это каждая строка конфига
  186. {
  187. $folder,$schedule = $line.split('#')
  188.  
  189. ############### проверяем расписание
  190.  
  191. $OnSchedule = $false
  192. $DaysOfWeeks = $Schedule.Split(";")
  193. $CurrentLocalDateTime = Get-Date
  194.  
  195. #$oAPI.LogScriptEvent("CheckFolderDate.ps1", 19999, 1, "schedule == $schedule")
  196. foreach ($DayOfWeek in $DaysOfWeeks)
  197. {
  198.     $DayOfWeekString = $DayOfWeek.Split(",").GetValue(0)
  199.     $StartTime = ($DayOfWeek.Split(",").GetValue(1)).Split("-").GetValue(0)
  200.     $EndTime = ($DayOfWeek.Split(",").GetValue(1)).Split("-").GetValue(1)
  201.    
  202.      switch ($DayOfWeekString)
  203.     {
  204.         "Mon" {$DayOfWeekInt = 1}
  205.         "Tue" {$DayOfWeekInt = 2}
  206.         "Wed" {$DayOfWeekInt = 3}
  207.         "Thu" {$DayOfWeekInt = 4}
  208.         "Fri" {$DayOfWeekInt = 5}
  209.         "Sat" {$DayOfWeekInt = 6}
  210.         "Sun" {$DayOfWeekInt = 0}
  211.        
  212.          default {$DayOfWeekInt = 101}
  213.      }
  214.         
  215.      if ($DayOfWeekInt -eq $CurrentLocalDateTime.DayOfWeek)
  216.     {
  217.         if ($CurrentLocalDateTime -ge [datetime]$StartTime -and $CurrentLocalDateTime -le [datetime]$EndTime)
  218.         {
  219.            $OnSchedule = $true
  220.         }
  221.     }
  222. }
  223.  
  224. #################
  225.  
  226. if ($OnSchedule)
  227. {
  228.  
  229. #$type = ((Get-ChildItem -Path $folder -file).Where({$_.LastWriteTime -lt $limit})).gettype()
  230.  
  231. $old_files = @(Get-ChildItem -Path $folder -file).Where({$_.LastWriteTime -lt $limit}) | select Name,LastWriteTime | Sort-Object name ## берем только файлы
  232.  
  233. if ($old_files) # если что-то нашлось то делаем алерт со списком того что нашлось
  234. {
  235. $state = 'ERROR'
  236.  
  237. $alert = "<table style='border-collapse:collapse;'BORDER='1' CELLPADDING='5' CELLSPACING='0' BORDERCOLOR='GREY'>" ### таблица
  238.  
  239. $alert = $alert + "<tr style='background-color:lightgrey;'>
  240. <td style='padding-top: 3px; vertical-align: middle;'>File name</td>
  241. <td style='padding-top: 3px; vertical-align: middle;'>Date modified</td>
  242. </tr>" #># шапка
  243.  
  244.  
  245. ForEach ($old_file in $old_files)
  246. {
  247. #$alert = $alert+"File name: $($old_file.Name) date modified: $($old_file.LastWriteTime) "+[Environment]::NewLine
  248.  
  249. $alert = $alert + "<tr style='background-color:lightgrey;'>
  250. <td style='padding-top: 3px; vertical-align: middle;'>$($old_file.Name)</td>
  251. <td style='padding-top: 3px; vertical-align: middle;'>$($old_file.LastWriteTime)</td>
  252. </tr>"#>
  253. }
  254.  
  255. $alert=$alert + '</table>'
  256. }
  257. else
  258. {
  259. $state = 'OK'
  260. }
  261.  
  262. $bag = $oAPI.CreatePropertyBag()
  263. $bag.addValue('FOLDERPATH',$folder) # cookdown key
  264. $bag.AddValue('STATE',$State)
  265. $bag.AddValue('INTERVAL',$INTERVAL)
  266. $bag.AddValue('ALERT',$alert)
  267. $bag.AddValue('SCHEDULE',$schedule)
  268.  
  269. $bag
  270.  
  271. #$oAPI.LogScriptEvent("CheckFolderDate.ps1", 19999, 1, "bag=$folder.....$el.....$state.....$alert")
  272.  
  273. }
  274. else
  275. {
  276.  
  277. # $oAPI.LogScriptEvent("CheckFolderDate.ps1", 19999, 1, "out of sch")
  278.    
  279. }
  280.  
  281.  
  282. #########################
  283.  
  284. }
  285.  
  286. $reader.Close()
  287. }
  288. catch
  289. {
  290. $e = $_.Exception
  291. $line = $_.InvocationInfo.ScriptLineNumber
  292. $msg = $e.Message
  293.  
  294. $oAPI.LogScriptEvent("CheckFolderDate.ps1", 19999, 1, "$msg at $line /// folder= $folder /// limit = $limit /// state= $state /// alert = $alert /// gci var type = $type ")
  295.  
  296. }
  297.  
  298. ]]></ScriptBody>
  299. <SnapIns />
  300. <Parameters>$Config/Parameters$</Parameters>
  301. <TimeoutSeconds>60</TimeoutSeconds>
  302. <StrictErrorHandling>false</StrictErrorHandling>
  303. </DataSource>
  304. <ConditionDetection ID="HealthyFilter" TypeID="System!System.ExpressionFilter">
  305. <Expression>
  306. <And>
  307. <Expression>
  308. <SimpleExpression>
  309. <ValueExpression>
  310. <XPathQuery Type="String">Property[@Name="STATE"]</XPathQuery>
  311. </ValueExpression>
  312. <Operator>Equal</Operator>
  313. <ValueExpression>
  314. <Value Type="String">OK</Value>
  315. </ValueExpression>
  316. </SimpleExpression>
  317. </Expression>
  318. <Expression>
  319. <SimpleExpression>
  320. <ValueExpression>
  321. <XPathQuery Type="String">Property[@Name="FOLDERPATH"]</XPathQuery>
  322. </ValueExpression>
  323. <Operator>Equal</Operator>
  324. <ValueExpression>
  325. <Value Type="String">$Target/Property[Type="Test.Lala.Folder.Class"]/FolderPath$</Value>
  326. </ValueExpression>
  327. </SimpleExpression>
  328. </Expression>
  329. </And>
  330. </Expression>
  331. </ConditionDetection>
  332. <ConditionDetection ID="CriticalFilter" TypeID="System!System.ExpressionFilter" Comment="supression включен!!!">
  333. <Expression>
  334. <And>
  335. <Expression>
  336. <SimpleExpression>
  337. <ValueExpression>
  338. <XPathQuery Type="String">Property[@Name="STATE"]</XPathQuery>
  339. </ValueExpression>
  340. <Operator>Equal</Operator>
  341. <ValueExpression>
  342. <Value Type="String">ERROR</Value>
  343. </ValueExpression>
  344. </SimpleExpression>
  345. </Expression>
  346. <Expression>
  347. <SimpleExpression>
  348. <ValueExpression>
  349. <XPathQuery Type="String">Property[@Name="FOLDERPATH"]</XPathQuery>
  350. </ValueExpression>
  351. <Operator>Equal</Operator>
  352. <ValueExpression>
  353. <Value Type="String">$Target/Property[Type="Test.Lala.Folder.Class"]/FolderPath$</Value>
  354. </ValueExpression>
  355. </SimpleExpression>
  356. </Expression>
  357. </And>
  358. </Expression>
  359. </ConditionDetection>
  360. <!--<ConditionDetection ID="Filter" TypeID="System!System.SchedulerFilter">
  361. <SchedulerFilter>
  362. <ProcessDataMode>OnSchedule</ProcessDataMode>
  363. <Schedule>$Config/Schedule$</Schedule>
  364. <UseCurrentTime>true</UseCurrentTime>
  365. </SchedulerFilter>
  366. </ConditionDetection>-->
  367. </MemberModules>
  368. <RegularDetections>
  369. <RegularDetection MonitorTypeStateID="Healthy">
  370. <Node ID="HealthyFilter">
  371. <!--<Node ID="Filter">-->
  372. <Node ID="PSScript" />
  373. <!--</Node>-->
  374. </Node>
  375. </RegularDetection>
  376. <RegularDetection MonitorTypeStateID="Critical">
  377. <Node ID="CriticalFilter">
  378. <!--<Node ID="Filter">-->
  379. <Node ID="PSScript" />
  380. <!--</Node>-->
  381. </Node>
  382. </RegularDetection>
  383. </RegularDetections>
  384. </MonitorImplementation>
  385. </UnitMonitorType>
  386. </MonitorTypes>
  387. </TypeDefinitions>
  388. <Monitoring>
  389. <Discoveries>
  390. <Discovery ID="ConfigDiscovery" Target="Windows!Microsoft.Windows.Computer" Enabled="true" ConfirmDelivery="false" Remotable="false" Priority="Normal">
  391. <Category>Discovery</Category>
  392. <DiscoveryTypes>
  393. <DiscoveryClass TypeID="Test.Lala.ConfigFile.Class" />
  394. </DiscoveryTypes>
  395. <DataSource ID="DS" TypeID="Windows!Microsoft.Windows.TimedPowerShell.DiscoveryProvider">
  396. <IntervalSeconds>14400</IntervalSeconds>
  397. <SyncTime />
  398. <ScriptName>DiscoverConfigFiles.ps1</ScriptName>
  399. <ScriptBody><![CDATA[param($sourceID, $managedEntityID, $ComputerName)
  400.  
  401. [array]$configs = "E:\Monitoring\10min.txt
  402. E:\Monitoring\15min.txt
  403. E:\Monitoring\24h10min.txt
  404. E:\Monitoring\35min.txt
  405. D:\Monitoring\10min.txt
  406. D:\Monitoring\15min.txt
  407. D:\Monitoring\24h10min.txt
  408. D:\Monitoring\35min.txt
  409. C:\test\10min.txt".Split([environment]::NewLine) # -split [System.Environment]::NewLine will not work in ps module
  410.  
  411.  
  412. $oAPI = New-Object -comObject MOM.ScriptAPI
  413. $Discovery = $oAPI.CreateDiscoveryData(0, $sourceID, $managedEntityID)
  414.  
  415. try
  416. {
  417. ForEach ($config in $configs)
  418. {
  419. $info = Get-Item -path $config | select FullName,Name,LastWriteTime
  420.  
  421. if ($info -ne $null) ##
  422. {
  423. Switch -Wildcard ($config)
  424. {
  425. '*\24h10min.txt' {[int]$interval = 1450}
  426. '*\10min.txt' {[int]$interval = 10}
  427. '*\15min.txt' {[int]$interval = 15}
  428. '*\35min.txt' {[int]$interval = 35}
  429.  
  430. #'C:\test\10min.txt' {[int]$interval = 10}
  431. #'C:\test\15min.txt' {[int]$interval = 15}
  432.  
  433. Default {$oAPI.LogScriptEvent("DiscoverConfigFiles.ps1", 19999, 1, 'pls check $config variable and switch vars')}
  434. }
  435.  
  436. $Instance = $Discovery.CreateClassInstance("$MPElement[Name='Test.Lala.ConfigFile.Class']$")
  437.  
  438. $Instance.AddProperty("$MPElement[Name='Test.Lala.ConfigFile.Class']/FullName$",$info.FullName)
  439. $Instance.AddProperty("$MPElement[Name='Test.Lala.ConfigFile.Class']/FileName$",$info.Name)
  440. $Instance.AddProperty("$MPElement[Name='Test.Lala.ConfigFile.Class']/LastWriteTime$",$info.LastWriteTime)
  441. $Instance.AddProperty("$MPElement[Name='Test.Lala.ConfigFile.Class']/Interval$",$interval)
  442. $Instance.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", $ComputerName)
  443.  
  444. $Discovery.AddInstance($Instance)
  445. }
  446. }
  447. $Discovery
  448. }
  449. catch
  450. {
  451. $e = $_.Exception
  452. $line = $_.InvocationInfo.ScriptLineNumber
  453. $msg = $e.Message
  454.  
  455. $oAPI.LogScriptEvent("DiscoverConfigFiles.ps1.ps1", 19999, 1, "$msg at $line;info=$info,ComputerName=$ComputerName,sourceID=$sourceID,managedEntityID=$managedEntityID,$configs,$interval")
  456.  
  457. }
  458. ]]></ScriptBody>
  459. <Parameters>
  460. <Parameter>
  461. <Name>sourceID</Name>
  462. <Value>$MPElement$</Value>
  463. </Parameter>
  464. <Parameter>
  465. <Name>managedEntityID</Name>
  466. <Value>$Target/Id$</Value>
  467. </Parameter>
  468. <Parameter>
  469. <Name>ComputerName</Name>
  470. <Value>$Target/Property[Type="Windows!Microsoft.Windows.Computer"]/PrincipalName$</Value>
  471. </Parameter>
  472. </Parameters>
  473. <TimeoutSeconds>300</TimeoutSeconds>
  474. <StrictErrorHandling>false</StrictErrorHandling>
  475. </DataSource>
  476. </Discovery>
  477. <Discovery ID="FolderDiscovery" Target="Test.Lala.ConfigFile.Class" Enabled="true" ConfirmDelivery="false" Remotable="false" Priority="Normal">
  478. <Category>Discovery</Category>
  479. <DiscoveryTypes>
  480. <DiscoveryRelationship TypeID="ConfigHostsFolder" />
  481. </DiscoveryTypes>
  482. <DataSource ID="DS" TypeID="Windows!Microsoft.Windows.TimedPowerShell.DiscoveryProvider">
  483. <IntervalSeconds>14400</IntervalSeconds>
  484. <SyncTime />
  485. <!--<SpreadInitializationOverInterval>1200</SpreadInitializationOverInterval>-->
  486. <ScriptName>DiscoverFolder.ps1</ScriptName>
  487. <ScriptBody><![CDATA[param($sourceID, $managedEntityID, $ComputerName,$FileName,$FullName)
  488.  
  489. <#
  490. $sourceID = 'B37CDE83-8052-9E73-FEED-D15D0A7C580E'
  491. $managedEntityID = '84D1648B-3BC5-6270-FEF5-B01C7244AE99'
  492. $ComputerName = 'monms01.domain.com'
  493. $FullName = 'C:\test\10min.txt'
  494.  
  495. #>
  496. $oAPI = New-Object -ComObject MOM.ScriptAPI
  497. $Discovery = $oAPI.CreateDiscoveryData(0, $sourceID, $managedEntityID)
  498.  
  499. try
  500. {
  501. #$folders = Get-Content -Path $FullName # т.к. файлы маленькие можно юзать gc
  502.  
  503. $reader = [System.IO.File]::OpenText($FullName)
  504.  
  505. while($null -ne ($line = $reader.ReadLine())) ## $line это каждая строка
  506.  
  507. {
  508.  
  509. $folder = $line.split('#')[0]
  510.  
  511. $oAPI.LogScriptEvent("Discover_Lala_folder.ps1.ps1", 666, 1, "folder = $folder")
  512.  
  513. $configFileInstance = $Discovery.CreateClassInstance("$MPElement[Name='Test.Lala.ConfigFile.Class']$")
  514. $configFileInstance.AddProperty("$MPElement[Name='Test.Lala.ConfigFile.Class']/FileName$", $FileName)
  515. $configFileInstance.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", $computerName)
  516.  
  517. $Instance = $Discovery.CreateClassInstance("$MPElement[Name='Test.Lala.Folder.Class']$")
  518. $Instance.AddProperty("$MPElement[Name='Test.Lala.Folder.Class']/FolderPath$", $folder)
  519. $Instance.AddProperty("$MPElement[Name='Test.Lala.ConfigFile.Class']/FileName$", $FileName)
  520. $Instance.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$",$ComputerName)
  521.  
  522. $Discovery.AddInstance($Instance)
  523.  
  524. $RelationshipInstance = $Discovery.CreateRelationshipInstance("$MPElement[Name='ConfigHostsFolder']$")
  525. $RelationshipInstance.Source = $configFileInstance
  526. $RelationshipInstance.Target = $Instance
  527.  
  528. $Discovery.AddInstance($RelationshipInstance)
  529.  
  530. }
  531.  
  532. $reader.Close()
  533.  
  534. $Discovery
  535.  
  536. }
  537. catch
  538. {
  539. $e = $_.Exception
  540. $line = $_.InvocationInfo.ScriptLineNumber
  541. $msg = $e.Message
  542.  
  543.  
  544.  
  545. $oAPI.LogScriptEvent("Discover_Lala_folder.ps1", 19999, 1, "$msg at $line.....folder = $folder,FileName = $FileName")
  546.  
  547. }]]></ScriptBody>
  548. <Parameters>
  549. <Parameter>
  550. <Name>sourceID</Name>
  551. <Value>$MPElement$</Value>
  552. </Parameter>
  553. <Parameter>
  554. <Name>managedEntityID</Name>
  555. <Value>$Target/Id$</Value>
  556. </Parameter>
  557. <Parameter>
  558. <Name>ComputerName</Name>
  559. <Value>$Target/Host/Property[Type="Windows!Microsoft.Windows.Computer"]/PrincipalName$</Value>
  560. </Parameter>
  561. <Parameter>
  562. <Name>FullName</Name>
  563. <Value>$Target/Property[Type="Test.Lala.ConfigFile.Class"]/FullName$</Value>
  564. </Parameter>
  565. <Parameter>
  566. <Name>FileName</Name>
  567. <Value>$Target/Property[Type="Test.Lala.ConfigFile.Class"]/FileName$</Value>
  568. </Parameter>
  569. </Parameters>
  570. <TimeoutSeconds>300</TimeoutSeconds>
  571. <StrictErrorHandling>false</StrictErrorHandling>
  572. </DataSource>
  573. </Discovery>
  574. </Discoveries>
  575. <Monitors>
  576. <UnitMonitor ID="Lala.Log.Monitor" Accessibility="Internal" Enabled="true" Target="Test.Lala.Folder.Class" ParentMonitorID="Health!System.Health.ConfigurationState" Remotable="false" Priority="Normal" TypeID="CheckFolderDate.MonitorType" ConfirmDelivery="false">
  577. <Category>AvailabilityHealth</Category>
  578. <AlertSettings AlertMessage="Lala.Log.Monitor.AlertMessage">
  579. <AlertOnState>Error</AlertOnState>
  580. <AutoResolve>true</AutoResolve>
  581. <AlertPriority>Normal</AlertPriority>
  582. <AlertSeverity>MatchMonitorHealth</AlertSeverity>
  583. <AlertParameters>
  584. <AlertParameter1>$Data/Context/Property[@Name='FOLDERPATH']$</AlertParameter1>
  585. <AlertParameter2>$Data/Context/Property[@Name='INTERVAL']$</AlertParameter2>
  586. <AlertParameter3>$Data/Context/Property[@Name='SCHEDULE']$</AlertParameter3>
  587. <AlertParameter4>$Data/Context/Property[@Name='ALERT']$</AlertParameter4>
  588. </AlertParameters>
  589. </AlertSettings>
  590. <OperationalStates>
  591. <OperationalState ID="Healthy" MonitorTypeStateID="Healthy" HealthState="Success" />
  592. <OperationalState ID="Critical" MonitorTypeStateID="Critical" HealthState="Error" />
  593. </OperationalStates>
  594. <Configuration>
  595. <IntervalSeconds>60</IntervalSeconds>
  596. <SyncTime />
  597. <Parameters>
  598. <Parameter>
  599. <Name>Interval</Name>
  600. <Value>$Target/Host/Property[Type="Test.Lala.ConfigFile.Class"]/Interval$</Value>
  601. </Parameter>
  602. <Parameter>
  603. <Name>FullName</Name>
  604. <Value>$Target/Host/Property[Type="Test.Lala.ConfigFile.Class"]/FullName$</Value>
  605. </Parameter>
  606. </Parameters>
  607. </Configuration>
  608. </UnitMonitor>
  609. </Monitors>
  610. </Monitoring>
  611. <Presentation>
  612. <Views>
  613. <View ID="Test.Lala.ConfigFile.Class.View" Accessibility="Public" Enabled="true" Target="Test.Lala.ConfigFile.Class" TypeID="SC!Microsoft.SystemCenter.StateViewType" Visible="true">
  614. <Category>Operations</Category>
  615. <Criteria>
  616. <InMaintenanceMode>false</InMaintenanceMode>
  617. </Criteria>
  618. <Presentation>
  619. <ColumnInfo Index="0" SortIndex="0" Width="100" Grouped="false" Sorted="true" IsSortable="true" Visible="true" SortOrder="Descending">
  620. <Name>State</Name>
  621. <Id>Test.Lala.ConfigFile.Class-*-4d68fd6d-a65c-b7d5-a383-4defa600616c-*-Health</Id>
  622. </ColumnInfo>
  623. <ColumnInfo Index="1" SortIndex="-1" Width="100" Grouped="false" Sorted="false" IsSortable="true" Visible="true" SortOrder="Ascending">
  624. <Name>Maintenance Mode</Name>
  625. <Id>InMaintenanceMode</Id>
  626. </ColumnInfo>
  627. <ColumnInfo Index="2" SortIndex="-1" Width="100" Grouped="false" Sorted="false" IsSortable="true" Visible="true" SortOrder="Ascending">
  628. <Name>Name</Name>
  629. <Id>Name</Id>
  630. </ColumnInfo>
  631. <ColumnInfo Index="3" SortIndex="-1" Width="100" Grouped="false" Sorted="false" IsSortable="true" Visible="true" SortOrder="Ascending">
  632. <Name>Path</Name>
  633. <Id>Path</Id>
  634. </ColumnInfo>
  635. <ColumnInfo Index="4" SortIndex="-1" Width="100" Grouped="false" Sorted="false" IsSortable="true" Visible="false" SortOrder="Ascending">
  636. <Name>Display Name</Name>
  637. <Id>System.Entity/DisplayName</Id>
  638. </ColumnInfo>
  639. <ColumnInfo Index="5" SortIndex="-1" Width="100" Grouped="false" Sorted="false" IsSortable="true" Visible="false" SortOrder="Ascending">
  640. <Name>FullName</Name>
  641. <Id>Test.Lala.ConfigFile.Class/FullName</Id>
  642. </ColumnInfo>
  643. <ColumnInfo Index="6" SortIndex="-1" Width="100" Grouped="false" Sorted="false" IsSortable="true" Visible="false" SortOrder="Ascending">
  644. <Name>FileName</Name>
  645. <Id>Test.Lala.ConfigFile.Class/FileName</Id>
  646. </ColumnInfo>
  647. <ColumnInfo Index="7" SortIndex="-1" Width="100" Grouped="false" Sorted="false" IsSortable="true" Visible="false" SortOrder="Ascending">
  648. <Name>LastWriteTime</Name>
  649. <Id>Test.Lala.ConfigFile.Class/LastWriteTime</Id>
  650. </ColumnInfo>
  651. <ColumnInfo Index="8" SortIndex="-1" Width="100" Grouped="false" Sorted="false" IsSortable="true" Visible="false" SortOrder="Ascending">
  652. <Name>Interval</Name>
  653. <Id>Test.Lala.ConfigFile.Class/Interval</Id>
  654. </ColumnInfo>
  655. <ColumnInfo Index="9" SortIndex="-1" Width="100" Grouped="false" Sorted="false" IsSortable="true" Visible="false" SortOrder="Ascending">
  656. <Name>Test Lala Folder Class</Name>
  657. <Id>Test.Lala.Folder.Class</Id>
  658. </ColumnInfo>
  659. </Presentation>
  660. <Target />
  661. </View>
  662. <View ID="Test.Lala.Folder.Class.View" Accessibility="Public" Enabled="true" Target="Test.Lala.Folder.Class" TypeID="SC!Microsoft.SystemCenter.StateViewType" Visible="true">
  663. <Category>Operations</Category>
  664. <Criteria>
  665. <InMaintenanceMode>false</InMaintenanceMode>
  666. </Criteria>
  667. <Presentation>
  668. <ColumnInfo Index="0" SortIndex="0" Width="100" Grouped="false" Sorted="true" IsSortable="true" Visible="true" SortOrder="Descending">
  669. <Name>State</Name>
  670. <Id>Test.Lala.Folder.Class-*-e5232322-0c0c-0d0f-0dd6-4811b830ba51-*-Health</Id>
  671. </ColumnInfo>
  672. <ColumnInfo Index="1" SortIndex="-1" Width="100" Grouped="false" Sorted="false" IsSortable="true" Visible="true" SortOrder="Ascending">
  673. <Name>Maintenance Mode</Name>
  674. <Id>InMaintenanceMode</Id>
  675. </ColumnInfo>
  676. <ColumnInfo Index="2" SortIndex="-1" Width="100" Grouped="false" Sorted="false" IsSortable="true" Visible="true" SortOrder="Ascending">
  677. <Name>Name</Name>
  678. <Id>Name</Id>
  679. </ColumnInfo>
  680. <ColumnInfo Index="3" SortIndex="-1" Width="100" Grouped="false" Sorted="false" IsSortable="true" Visible="true" SortOrder="Ascending">
  681. <Name>Path</Name>
  682. <Id>Path</Id>
  683. </ColumnInfo>
  684. <ColumnInfo Index="4" SortIndex="-1" Width="100" Grouped="false" Sorted="false" IsSortable="true" Visible="false" SortOrder="Ascending">
  685. <Name>Display Name</Name>
  686. <Id>System.Entity/DisplayName</Id>
  687. </ColumnInfo>
  688. <ColumnInfo Index="5" SortIndex="-1" Width="100" Grouped="false" Sorted="false" IsSortable="true" Visible="false" SortOrder="Ascending">
  689. <Name>FolderPath</Name>
  690. <Id>Test.Lala.Folder.Class/FolderPath</Id>
  691. </ColumnInfo>
  692. </Presentation>
  693. <Target />
  694. </View>
  695. </Views>
  696. <Folders>
  697. <Folder ID="Lala.Folders.Monitoring.Folder" Accessibility="Public" ParentFolder="SC!Microsoft.SystemCenter.Monitoring.ViewFolder.Root" />
  698. </Folders>
  699. <FolderItems>
  700. <FolderItem ElementID="Test.Lala.ConfigFile.Class.View" ID="i95b2ac270f4f4f19bec10b15bb1f5811" Folder="Lala.Folders.Monitoring.Folder" />
  701. <FolderItem ElementID="Test.Lala.Folder.Class.View" ID="i963104f0516c436d832b08c67ed4ebb0" Folder="Lala.Folders.Monitoring.Folder" />
  702. </FolderItems>
  703. <StringResources>
  704. <StringResource ID="Lala.Log.Monitor.AlertMessage" />
  705. </StringResources>
  706. </Presentation>
  707. <LanguagePacks>
  708. <LanguagePack ID="ENU" IsDefault="true">
  709. <DisplayStrings>
  710. <DisplayString ElementID="ConfigDiscovery">
  711. <Name>Config Discovery</Name>
  712. <Description>Description for the new discovery.</Description>
  713. </DisplayString>
  714. <DisplayString ElementID="FolderDiscovery">
  715. <Name>Folder Discovery</Name>
  716. <Description>Description for the new discovery.</Description>
  717. </DisplayString>
  718. <DisplayString ElementID="Lala.Log.Monitor">
  719. <Name>Lala Log Monitor</Name>
  720. <Description>Finds old log files in folders</Description>
  721. </DisplayString>
  722. <DisplayString ElementID="Lala.Log.Monitor.AlertMessage">
  723. <Name>Old files alert</Name>
  724. <Description>Found old files in {0} older then {1} min.
  725.  
  726. Schedule = {2}
  727.  
  728. List:
  729.  
  730. {3}
  731. </Description>
  732. </DisplayString>
  733. <DisplayString ElementID="Lala.Log.Monitor" SubElementID="Healthy">
  734. <Name>Healthy</Name>
  735. <Description>Healthy</Description>
  736. </DisplayString>
  737. <DisplayString ElementID="Lala.Log.Monitor" SubElementID="Critical">
  738. <Name>Critical</Name>
  739. <Description>Critical</Description>
  740. </DisplayString>
  741. <DisplayString ElementID="Test.Lala.Folders.Monitoring">
  742. <Name>Test Lala Folders monitoring</Name>
  743. <Description>Test Lala Folders Monitoring (VSAE)
  744.  
  745. 11
  746. </Description>
  747. </DisplayString>
  748. <DisplayString ElementID="Lala.Folders.Monitoring.Folder">
  749. <Name>Lala Folders Monitoring</Name>
  750. </DisplayString>
  751. <DisplayString ElementID="Test.Lala.ConfigFile.Class.View">
  752. <Name>Lala Monitoring config files</Name>
  753. </DisplayString>
  754. <DisplayString ElementID="Test.Lala.Folder.Class.View">
  755. <Name>Lala Folders</Name>
  756. <Description />
  757. </DisplayString>
  758. <DisplayString ElementID="Test.Lala.Folder.Class">
  759. <Name>Test Lala Folder Class</Name>
  760. <Description>Test Lala Folder Class</Description>
  761. </DisplayString>
  762. <DisplayString ElementID="Test.Lala.Folder.Class" SubElementID="FolderPath">
  763. <Name>FolderPath</Name>
  764. <Description>FolderPath</Description>
  765. </DisplayString>
  766. <DisplayString ElementID="Test.Lala.ConfigFile.Class">
  767. <Name>Test Lala Config File Class</Name>
  768. <Description>Test Lala Config File Class</Description>
  769. </DisplayString>
  770. <DisplayString ElementID="Test.Lala.ConfigFile.Class" SubElementID="FullName">
  771. <Name>FullName</Name>
  772. <Description>FullName</Description>
  773. </DisplayString>
  774. <DisplayString ElementID="Test.Lala.ConfigFile.Class" SubElementID="FileName">
  775. <Name>FileName</Name>
  776. <Description>FileName</Description>
  777. </DisplayString>
  778. <DisplayString ElementID="Test.Lala.ConfigFile.Class" SubElementID="LastWriteTime">
  779. <Name>LastWriteTime</Name>
  780. <Description>LastWriteTime</Description>
  781. </DisplayString>
  782. <DisplayString ElementID="Test.Lala.ConfigFile.Class" SubElementID="Interval">
  783. <Name>Interval</Name>
  784. <Description>Interval (used by monitoring scripts)</Description>
  785. </DisplayString>
  786. </DisplayStrings>
  787. <KnowledgeArticles></KnowledgeArticles>
  788. </LanguagePack>
  789. </LanguagePacks>
  790. </ManagementPack>
Add Comment
Please, Sign In to add comment