PerforceBackupProcedureRSS.ps1 #2

  • //
  • guest/
  • philip_kania/
  • AdminScripts/
  • PerforceBackupProcedureRSS.ps1
  • View
  • Commits
  • Open Download .zip Download (3 KB)
# Copyright (c) 2009 Exemplics LLC

# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:

# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

# Version 2009.3

# <Functions>

function CreateRssItem($logFile)
{
    $rssItem = $logFile.FullName -replace "\.xml",".rssitem.xml"
    # Generate new rssItem if logFile is newer than rssItem or rssItem
    # does not exist.
    if (-not [IO.File]::Exists($rssItem) -or ($logFile.LastWriteTime -gt $(Get-Item $rssItem).LastWriteTime))
    {
        $xmlDoc = New-Object Xml.XmlDocument
        $xmlDoc.Load($logFile.FullName)
        $nav = $xmlDoc.CreateNavigator()
        $writer = New-Object Xml.XmlTextWriter $rssItem,$([Text.Encoding]::UTF8)
        $argList = New-Object Xml.Xsl.XsltArgumentList
        $argList.AddParam("uri", "", $env:rssLink + "/" + $logFile.Name)
        $xslt.Transform($nav, $argList, $writer)
        $writer.Close()
    }
}

function RssStart()
{
    $rssGenerator = $MyInvocation.ScriptName | Split-Path -leaf
    $header = @(
        '<?xml version="1.0"?>'
        '<rss version="2.0">',
        "<channel>",
        "<title>$rssTitle</title>",
        "<link>$env:rssLink</link>",
        "<description>$rssDescription</description>",
        "<language>en-us</language>",
        "<pubDate>$(date)</pubDate>",
        "<lastBuildDate>$(date)</lastBuildDate>",
        "<docs>http://blogs.law.harvard.edu/tech/rss</docs>",
        "<generator>$rssGenerator</generator>",
        "<managingEditor>$env:rssManagingEditor</managingEditor>",
        "<webMaster>$env:rssWebMaster</webMaster>")
    return $header
}

function RssEnd()
{
  $footer = @(
      "</channel>",
      "</rss>")
  return $footer
}

# </Functions>

# <Initialize>

Push-Location "$env:logDirectory"

$rssTitle = "Perforce Backup Procedure Results"
$rssDescription = "Summary of Perforce server backup procedure results with links to full results."

$xslFile = Convert-Path PerforceBackupProcedureRSS.xsl
$xslt = New-Object Xml.Xsl.XslCompiledTransform
$xslt.Load($xslFile)

Pop-Location

# </Initialize>

# <Main>

Push-Location "$env:logDirectory"

# Create RSS fragments in the order the log files were created.
Get-ChildItem *.BackupProcedure.xml | Sort-Object LastWriteTime | ForEach-Object {
    CreateRssItem($_)
}

RssStart | Out-File "$env:rssFeedFile" -Encoding "UTF8"
# Concatenate the RSS fragments newest to oldest.
Get-ChildItem *.rssitem.xml | Sort-Object LastWriteTime -Descending | Get-Content | Out-File "$env:rssFeedFile" -Encoding "UTF8" -Append
RssEnd | Out-File "$env:rssFeedFile" -Encoding "UTF8" -Append

Pop-Location

# </Main>

# Change User Description Committed
#2 7203 Philip Kania Corrected Functions start tag.
#1 7202 Philip Kania Added scripts to generate RSS feeds.
Updated template configuration scripts to run RSS scripts.