Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Requires -Version 4
- <#
- ___ ___ _____ ___
- | _ \ _ \_ _/ __|
- | _/ / | || (_ |
- |_| |_|_\ |_| \___|
- RSS Feed Checker
- (c) SLinke|Paessler AG
- =======================
- Description: This sensor will read RSS feeds configured in
- the configuration file and alert as soon as one of them is updated.
- The FriendlyName attribute will be used as channel name.
- #>
- $configurationFile = "C:\Program Files (x86)\PRTG Network Monitor\Custom Sensors\EXEXML\prtg.rsscheck.xml"
- $configuration = New-Object System.Xml.XmlDocument
- #region configuration
- $configuration.Load($configurationFile);
- $Feeds = $configuration.configuration.feeds.ChildNodes
- [System.Collections.ArrayList]$Updaters = @();
- $MaxMessageLength = 50;
- #endregion
- function Check-RSSFeed(){
- Write-Host '<?xml version="1.0" encoding="UTF-8"?><prtg>'
- foreach($feed in $Script:Feeds){
- # get the current messages
- [xml]$RSS = (Invoke-WebRequest -UseBasicParsing -Uri $feed.url)
- [string]$currentMessage = $RSS.SelectSingleNode($feed.node).Value
- [string]$oldMessage = $Configuration.SelectSingleNode([string]::Format("/configuration/feeds/feed[@id='{0}']",$feed.id)).saved
- Write-Host "<result><channel>$($Feed.FriendlyName)</channel><unit>count</unit><valuelookup>prtg.rssupdate</valuelookup>"
- if($oldMessage -ne $currentMessage){
- Write-Host "<value>1</value>"
- $Updaters.Add([string]::Format("[{0}] {1}", $Feed.FriendlyName,$currentMessage.Substring(0,$MaxMessageLength))) | Out-Null;
- # save the new message to the configuration file
- $Configuration.SelectSingleNode([string]::Format("/configuration/feeds/feed[@id='{0}']",$feed.id)).current = $currentMessage;
- $Configuration.SelectSingleNode([string]::Format("/configuration/feeds/feed[@id='{0}']",$feed.id)).saved = $currentMessage;
- $Configuration.Save($configurationFile);
- }
- else { write-host "<value>0</value>"; $Updaters.Add([string]::Format("[{0}] {1}", $Feed.FriendlyName,$currentMessage.Substring(0,$MaxMessageLength))) | Out-Null; }
- Write-Host "</result>"
- }
- Write-Host ("<text>{0}</text></prtg>" -f ($Updaters -join ", "))
- }
- Check-RSSFeed
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement