Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set logging custom fields #205

Open
spuder opened this issue Aug 24, 2015 · 12 comments
Open

Set logging custom fields #205

spuder opened this issue Aug 24, 2015 · 12 comments
Assignees
Milestone

Comments

@spuder
Copy link
Contributor

spuder commented Aug 24, 2015

I'm trying to figure out if this cookbook can automate creating a custom logging field.

screenshot 2015-08-24 15 39 33

This can be done with the following powershell.

Add-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST'  -filter "system.applicationHost/sites/site[@name='NetDocuments']/logFile/customFields" -name "." -value @{logFieldName='X-Forwarded-For';sourceName='X-FORWARDED-FOR';sourceType='RequestHeader'}

The cookbook only appears to support appcmd, and not Add-WetConfigurationProperty

Is there a way to do this? I'm happy to open a documentation request once I figure it out.

@EasyAsABC123
Copy link
Contributor

appcmd.exe set config -section:system.applicationHost/sites
/+"[name='ContosoSite'].logFile.customFields.[logFieldName='ContosoField',sourceName='ContosoSource',sourceType='ServerVariable']"
/commit:apphost

taken from
https://www.iis.net/configreference/system.applicationhost/sites/site/logfile/customfields/add

should be easy to add

On Mon, Aug 24, 2015 at 5:42 PM, Spencer Owen notifications@github.com
wrote:

I'm trying to figure out if this cookbook can automate creating a custom
logging field.

[image: screenshot 2015-08-24 15 39 33]
https://cloud.githubusercontent.com/assets/242382/9453278/88d1e658-4a76-11e5-8a13-06ff42585a3f.png

This can be done with the following powershell.

Add-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST' -filter "system.applicationHost/sites/site[@name='NetDocuments']/logFile/customFields" -name "." -value @{logFieldName='X-Forwarded-For';sourceName='X-FORWARDED-FOR';sourceType='RequestHeader'}

The cookbook only appears to support appcmd, and not
Add-WetConfigurationProperty

Is there a way to do this? I'm happy to open a documentation request once
I figure it out.


Reply to this email directly or view it on GitHub
#205.

@spuder
Copy link
Contributor Author

spuder commented Aug 24, 2015

Thanks @EasyAsABC123 Though it looks like /+ is not idempotent #89 (comment)

iis_config "/section:system.applicationHost/sites /+\"[name='foobar'].logFile.customFields.[logFieldName='X-Forwarded-For',sourceName='X-FORWARDED-FOR',sourceType='RequestHeader']\"  /commit:apphost" do
  action :config
end

Error

[2015-08-24T18:33:42-04:00] FATAL: Stacktrace dumped to c:/chef/cache/chef-stacktrace.out
[2015-08-24T18:33:42-04:00] FATAL: Mixlib::ShellOut::ShellCommandFailed: iis_config[/section:system.applicationHost/sites /+"[name='NetDocuments'].logFile.customFields.[logFieldName='X-Forwarded-For',sourceName='X-FORWARDED-FOR',sourceType='RequestHeader']"  /commit:apphost] (nd-web::xforward line 1) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '183'
---- Begin output of C:\Windows\System32\inetsrv\appcmd.exe set config /section:system.applicationHost/sites /+"[name='NetDocuments'].logFile.customFields.[logFieldName='X-Forwarded-For',sourceName='X-FORWARDED-FOR',sourceType='RequestHeader']"  /commit:apphost ----
STDOUT: ERROR ( message:New add object missing required attributes. Cannot add duplicate collection entry of type 'add' with unique key attribute 'logFieldName' set to 'X-Forwarded-For'
. )
STDERR:
---- End output of C:\Windows\System32\inetsrv\appcmd.exe set config /section:system.applicationHost/sites /+"[name='NetDocuments'].logFile.customFields.[logFieldName='X-Forwarded-For',sourceName='X-FORWARDED-FOR',sourceType='RequestHeader']"  /commit:apphost ----
Ran C:\Windows\System32\inetsrv\appcmd.exe set config /section:system.applicationHost/sites /+"[name='NetDocuments'].logFile.customFields.[logFieldName='X-Forwarded-For',sourceName='X-FORWARDED-FOR',sourceType='RequestHeader']"  /commit:apphost returned 183���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������

The only way I was able to work around it, was with returns [0,183]

iis_config "/section:system.applicationHost/sites /+\"[name='foobar'].logFile.customFields.[logFieldName='X-Forwarded-For',sourceName='X-FORWARDED-FOR',sourceType='RequestHeader']\"  /commit:apphost" do
  action :config
  returns [0,183]
end

Using returns feels like cheating. Is this still the recommended work around for /+ with appcmd?

@EasyAsABC123
Copy link
Contributor

No of course not, a config list would have to run first

Justin Schuhmann

On Aug 24, 2015, at 6:46 PM, Spencer Owen notifications@github.com wrote:

Thanks @EasyAsABC123 Though it looks like /+ is not idempotent #89 (comment)

iis_config "/section:system.applicationHost/sites /+"[name='foobar'].logFile.customFields.[logFieldName='X-Forwarded-For',sourceName='X-FORWARDED-FOR',sourceType='RequestHeader']" /commit:apphost" do
action :config
end
Error

[2015-08-24T18:33:42-04:00] FATAL: Stacktrace dumped to c:/chef/cache/chef-stacktrace.out
[2015-08-24T18:33:42-04:00] FATAL: Mixlib::ShellOut::ShellCommandFailed: iis_config[/section:system.applicationHost/sites /+"[name='NetDocuments'].logFile.customFields.[logFieldName='X-Forwarded-For',sourceName='X-FORWARDED-FOR',sourceType='RequestHeader']" /commit:apphost](nd-web::xforward line 1) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '183'
---- Begin output of C:\Windows\System32\inetsrv\appcmd.exe set config /section:system.applicationHost/sites /+"[name='NetDocuments'].logFile.customFields.[logFieldName='X-Forwarded-For',sourceName='X-FORWARDED-FOR',sourceType='RequestHeader']" /commit:apphost ----
STDOUT: ERROR ( message:New add object missing required attributes. Cannot add duplicate collection entry of type 'add' with unique key attribute 'logFieldName' set to 'X-Forwarded-For'
. )
STDERR:
---- End output of C:\Windows\System32\inetsrv\appcmd.exe set config /section:system.applicationHost/sites /+"[name='NetDocuments'].logFile.customFields.[logFieldName='X-Forwarded-For',sourceName='X-FORWARDED-FOR',sourceType='RequestHeader']" /commit:apphost ----
Ran C:\Windows\System32\inetsrv\appcmd.exe set config /section:system.applicationHost/sites /+"[name='NetDocuments'].logFile.customFields.[logFieldName='X-Forwarded-For',sourceName='X-FORWARDED-FOR',sourceType='RequestHeader']" /commit:apphost returned 183
The only way I was able to work around it, was with returns [0,183]

iis_config "/section:system.applicationHost/sites /+"[name='foobar'].logFile.customFields.[logFieldName='X-Forwarded-For',sourceName='X-FORWARDED-FOR',sourceType='RequestHeader']" /commit:apphost" do
action :config
returns [0,183]
end
Using returns feels like cheating. Is this still the recommended work around for /+ with appcmd?


Reply to this email directly or view it on GitHub.

@spuder
Copy link
Contributor Author

spuder commented Sep 9, 2015

Been working on this for a while. I'm unable to figure out how to create a guard based on appcmd list config.

Hopefully someone else will figure it out someday. For now, I'm cheating and using returns[0,183]. Closing issue.

@spuder spuder closed this as completed Sep 9, 2015
@EasyAsABC123 EasyAsABC123 reopened this Sep 10, 2015
@EasyAsABC123
Copy link
Contributor

@spuder might add this code to master, going to look into it now.

@EasyAsABC123 EasyAsABC123 added this to the 4.2 milestone Oct 30, 2015
@EasyAsABC123 EasyAsABC123 self-assigned this Oct 30, 2015
@spuder spuder changed the title Question - Can cookbook set logging custom fields Set logging custom fields Dec 1, 2015
@Rovastar
Copy link

Rovastar commented Dec 2, 2015

Been lurking here for ages. For this one it is an IIS8.5 and above only feature if you add this you probably need to do some checking before you add it.

@EasyAsABC123
Copy link
Contributor

@Rovastar https://github.com/chef-cookbooks/iis/blob/master/libraries/helper.rb#L93 is the function for this, thanks for the intel on iis 8.5 and higher

@EasyAsABC123 EasyAsABC123 modified the milestones: 4.3, 4.2 Jun 23, 2016
@dmalikov
Copy link

In IIS8.5 there is a special clear command to empty a collection. I.e:

/~logFile.customFields

Enormously helpful to get rid of these 'key already exist' errors.

@EasyAsABC123
Copy link
Contributor

EasyAsABC123 commented Jun 27, 2016

note: I am aware this is specifically mimeMap, but they are both iis collections which means they behave very similarly.

For reference later,
add a mime type:

appcmd.exe set config "Default Web Site" /section:system.webServer/staticContent /+[fileExtension='.haha',mimeType='text']
Applied configuration changes to section "system.webServer/staticContent" for "MACHINE/WEBROOT/APPHOST/Default Web Site at configuration commit path "MACHINE/WEBROOT/APPHOST/Default Web Site"

clear single mimeType:

appcmd.exe clear config "Default Web Site" /section:system.webServer/staticContent /[fileExtension='.haha']
Cleared section "system.webServer/staticContent" at configuration path "MACHINE/WEBROOT/APPHOST/Default Web Site"

clear whole section:

C:\Windows\System32\inetsrv>appcmd.exe clear config "test" /section:system.webServer/staticContent
Cleared section "system.webServer/staticContent" at configuration path "MACHINE/WEBROOT/APPHOST/test"

@EasyAsABC123 EasyAsABC123 modified the milestones: 4.2, 4.3 Jun 29, 2016
@EasyAsABC123 EasyAsABC123 modified the milestones: v7, 4.2 May 12, 2017
@seeven-kathan
Copy link

Hello,

I've been able to set an not_if for X-Forward-For :

not_if 'cmd /c C:\Windows\System32\inetsrv\appcmd.exe list config -section:system.applicationHost/sites | findstr "X-Forward-For"'

@EasyAsABC123
Copy link
Contributor

@seeven-kathan awesome solution!

@duyster
Copy link

duyster commented Mar 27, 2018

@seeven-kathan thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants