Skip to content

Instantly share code, notes, and snippets.

@karaaie
Created February 20, 2014 13:02
Show Gist options
  • Save karaaie/9113037 to your computer and use it in GitHub Desktop.
Save karaaie/9113037 to your computer and use it in GitHub Desktop.
This powershell script will generate the necessary IIS config for nxlog.
Param([string]$nxlog_dir = "c:\nxlog")
Import-Module WebAdministration;
$input_template = "<Input {0}>
Module im_file
File '{1}\W3SVC{2}\\*.log'
ReadFromLast TRUE
Exec if ((`$raw_event =~ /^#/) or (`$raw_event =~ /^$/)) drop(); \
else w3c->parse_csv(); \
`$service = '{0}';
</Input>"
$route_template = '
<Route iis>
Path {0} => \
iis_clean => iis_rewrite => \
logstash_iis
</Route>'
$nxlog_conf_dir = $nxlog_dir + "\conf"
$route_conf = @()
foreach ($site in Get-Website){
$site_name = $site.name.replace(' ','_')
$site_logfile = [System.Environment]::ExpandEnvironmentVariables($site.logfile.directory)
$input = [string]::Format($input_template, $site_name, $site_logfile, $site.id)
$route_conf += $site_name
$file = $nxlog_conf_dir+"\input."+$site.name+".conf"
new-item $file -type file -force
$input >> $file
}
if($route_conf.count -gt 0){
$route = [string]::Format($route_template, $route_conf -join ',')
$route_conf_file = $nxlog_conf_dir+"\routes.conf"
new-item $route_conf_file -type file -force
$route >> $route_conf_file
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment