github.com/Pankov404/juju@v0.0.0-20150703034450-be266991dceb/utils/syslog/testing/syslogconf.go (about) 1 // Copyright 2014 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package testing 5 6 import ( 7 "bytes" 8 "text/template" 9 10 jc "github.com/juju/testing/checkers" 11 gc "gopkg.in/check.v1" 12 ) 13 14 var expectedAccumulateSyslogConfTemplate = ` 15 $ModLoad imuxsock 16 $ModLoad imfile 17 18 # Messages received from remote rsyslog machines have messages prefixed with a space, 19 # so add one in for local messages too if needed. 20 $template JujuLogFormat{{.Namespace}},"%syslogtag:{{.Offset}}:$%%msg:::sp-if-no-1st-sp%%msg:::drop-last-lf%\n" 21 22 $template LongTagForwardFormat,"<%PRI%>%TIMESTAMP:::date-rfc3339% %HOSTNAME% %syslogtag%%msg:::sp-if-no-1st-sp%%msg%" 23 24 25 # start: Forwarding rule for foo 26 $ActionQueueType LinkedList 27 $ActionQueueFileName {{.MachineTag}}{{.Namespace}}_0 28 $ActionResumeRetryCount -1 29 $ActionQueueSaveOnShutdown on 30 $ActionQueueMaxDiskSpace 512M 31 $DefaultNetstreamDriver gtls 32 $DefaultNetstreamDriverCAFile /var/log/juju{{.Namespace}}/ca-cert.pem 33 $ActionSendStreamDriverAuthMode anon 34 $ActionSendStreamDriverMode 1 # run driver in TLS-only mode 35 36 :syslogtag, startswith, "juju{{.Namespace}}-" @@foo:{{.Port}};LongTagForwardFormat 37 # end: Forwarding rule for foo 38 39 :syslogtag, startswith, "juju{{.Namespace}}-" stop 40 41 $FileCreateMode 0600 42 43 # Maximum size for the log on this outchannel is 512MB 44 # The command to execute when an outchannel as reached its size limit cannot accept any arguments 45 # that is why we have created the helper script for executing logrotate. 46 $outchannel logRotation,/var/log/juju{{.Namespace}}/all-machines.log,536870912,/var/log/juju{{.Namespace}}/logrotate.run 47 48 $RuleSet remote 49 $FileCreateMode 0600 50 :syslogtag, startswith, "juju{{.Namespace}}-" :omfile:$logRotation;JujuLogFormat{{.Namespace}} 51 :syslogtag, startswith, "juju{{.Namespace}}-" stop 52 $FileCreateMode 0600 53 54 $InputFilePersistStateInterval 50 55 $InputFilePollInterval 5 56 $InputFileName /var/log/juju{{.Namespace}}/{{.MachineTag}}.log 57 $InputFileTag juju{{.Namespace}}-{{.MachineTag}}: 58 $InputFileStateFile {{.MachineTag}}{{.Namespace}} 59 $InputRunFileMonitor 60 61 $ModLoad imtcp 62 $DefaultNetstreamDriver gtls 63 $DefaultNetstreamDriverCAFile /var/log/juju{{.Namespace}}/ca-cert.pem 64 $DefaultNetstreamDriverCertFile /var/log/juju{{.Namespace}}/rsyslog-cert.pem 65 $DefaultNetstreamDriverKeyFile /var/log/juju{{.Namespace}}/rsyslog-key.pem 66 $InputTCPServerStreamDriverAuthMode anon 67 $InputTCPServerStreamDriverMode 1 # run driver in TLS-only mode 68 $InputTCPMaxSessions 10000 # default is 200, all agents connect to all rsyslog daemons 69 70 $InputTCPServerBindRuleset remote 71 $InputTCPServerRun {{.Port}} 72 73 # switch back to default ruleset for further rules 74 $RuleSet RSYSLOG_DefaultRuleset 75 ` 76 77 type templateArgs struct { 78 MachineTag string 79 LogDir string 80 Namespace string 81 BootstrapIP string 82 Port int 83 Offset int 84 } 85 86 // ExpectedAccumulateSyslogConf returns the expected content for a rsyslog file on a state server. 87 func ExpectedAccumulateSyslogConf(c *gc.C, machineTag, namespace string, port int) string { 88 if namespace != "" { 89 namespace = "-" + namespace 90 } 91 t := template.Must(template.New("").Parse(expectedAccumulateSyslogConfTemplate)) 92 var conf bytes.Buffer 93 err := t.Execute(&conf, templateArgs{ 94 MachineTag: machineTag, 95 Namespace: namespace, 96 Offset: len("juju-") + len(namespace) + 1, 97 Port: port, 98 }) 99 c.Assert(err, jc.ErrorIsNil) 100 return conf.String() 101 } 102 103 var expectedForwardSyslogConfTemplate = ` 104 $ModLoad imuxsock 105 $ModLoad imfile 106 107 $InputFilePersistStateInterval 50 108 $InputFilePollInterval 5 109 $InputFileName {{.LogDir}}/{{.MachineTag}}.log 110 $InputFileTag juju{{.Namespace}}-{{.MachineTag}}: 111 $InputFileStateFile {{.MachineTag}}{{.Namespace}} 112 $InputRunFileMonitor 113 114 # start: Forwarding rule for server 115 $ActionQueueType LinkedList 116 $ActionQueueFileName {{.MachineTag}}{{.Namespace}}_0 117 $ActionResumeRetryCount -1 118 $ActionQueueSaveOnShutdown on 119 $ActionQueueMaxDiskSpace 512M 120 $DefaultNetstreamDriver gtls 121 $DefaultNetstreamDriverCAFile {{.LogDir}}/ca-cert.pem 122 $ActionSendStreamDriverAuthMode anon 123 $ActionSendStreamDriverMode 1 # run driver in TLS-only mode 124 125 $template LongTagForwardFormat,"<%PRI%>%TIMESTAMP:::date-rfc3339% %HOSTNAME% %syslogtag%%msg:::sp-if-no-1st-sp%%msg%" 126 :syslogtag, startswith, "juju{{.Namespace}}-" @@{{.BootstrapIP}}:{{.Port}};LongTagForwardFormat 127 # end: Forwarding rule for server 128 129 & ~ 130 ` 131 132 // ExpectedForwardSyslogConf returns the expected content for a rsyslog file on a host machine. 133 func ExpectedForwardSyslogConf(c *gc.C, machineTag, logDir, namespace, bootstrapIP string, port int) string { 134 if namespace != "" { 135 namespace = "-" + namespace 136 } 137 t := template.Must(template.New("").Parse(expectedForwardSyslogConfTemplate)) 138 var conf bytes.Buffer 139 err := t.Execute(&conf, templateArgs{ 140 MachineTag: machineTag, 141 LogDir: logDir, 142 Namespace: namespace, 143 BootstrapIP: bootstrapIP, 144 Port: port, 145 }) 146 c.Assert(err, jc.ErrorIsNil) 147 return conf.String() 148 }