Exemple #1
0
func (s *ClientSuite) TestClose(c *gc.C) {
	client := syslog.Client{Sender: s.sender}

	err := client.Close()
	c.Assert(err, jc.ErrorIsNil)

	s.stub.CheckCallNames(c, "Close")
}
Exemple #2
0
func (s *ClientSuite) TestSendLogLevels(c *gc.C) {
	tag := names.NewMachineTag("99")
	cID := "9f484882-2f18-4fd2-967d-db9663db7bea"
	mID := "deadbeef-2f18-4fd2-967d-db9663db7bea"
	ver := version.MustParse("1.2.3")
	rec := logfwd.Record{
		Origin:    logfwd.OriginForMachineAgent(tag, cID, mID, ver),
		Timestamp: time.Unix(12345, 0),
		Level:     loggo.ERROR,
		Location: logfwd.SourceLocation{
			Module:   "juju.x.y",
			Filename: "x/y/spam.go",
			Line:     42,
		},
		Message: "(╯°□°)╯︵ ┻━┻",
	}
	client := syslog.Client{Sender: s.sender}

	levels := map[loggo.Level]rfc5424.Severity{
		loggo.ERROR:   rfc5424.SeverityError,
		loggo.WARNING: rfc5424.SeverityWarning,
		loggo.INFO:    rfc5424.SeverityInformational,
		loggo.DEBUG:   rfc5424.SeverityDebug,
		loggo.TRACE:   rfc5424.SeverityDebug,
	}
	for level, expected := range levels {
		c.Logf("trying %s -> %s", level, expected)
		s.stub.ResetCalls()
		rec.Level = level

		err := client.Send([]logfwd.Record{rec})
		c.Assert(err, jc.ErrorIsNil)

		msg := s.stub.Calls()[0].Args[0].(rfc5424.Message)
		c.Check(msg.Severity, gc.Equals, expected)
	}
}
Exemple #3
0
func (s *ClientSuite) TestSendLogFull(c *gc.C) {
	tag := names.NewMachineTag("99")
	cID := "9f484882-2f18-4fd2-967d-db9663db7bea"
	mID := "deadbeef-2f18-4fd2-967d-db9663db7bea"
	ver := version.MustParse("1.2.3")
	ts := time.Unix(12345, 0)
	rec := logfwd.Record{
		Origin:    logfwd.OriginForMachineAgent(tag, cID, mID, ver),
		Timestamp: time.Unix(12345, 0),
		Level:     loggo.ERROR,
		Location: logfwd.SourceLocation{
			Module:   "juju.x.y",
			Filename: "x/y/spam.go",
			Line:     42,
		},
		Message: "(╯°□°)╯︵ ┻━┻",
	}
	client := syslog.Client{Sender: s.sender}

	err := client.Send([]logfwd.Record{rec})
	c.Assert(err, jc.ErrorIsNil)

	s.stub.CheckCallNames(c, "Send")
	s.stub.CheckCall(c, 0, "Send", rfc5424.Message{
		Header: rfc5424.Header{
			Priority: rfc5424.Priority{
				Severity: rfc5424.SeverityError,
				Facility: rfc5424.FacilityUser,
			},
			Timestamp: rfc5424.Timestamp{ts},
			Hostname: rfc5424.Hostname{
				FQDN: "machine-99.deadbeef-2f18-4fd2-967d-db9663db7bea",
			},
			AppName: "jujud-machine-agent-deadbeef-2f18-4fd2-967d-db96",
		},
		StructuredData: rfc5424.StructuredData{
			&sdelements.Origin{
				EnterpriseID: sdelements.OriginEnterpriseID{
					Number: 28978,
				},
				SoftwareName:    "jujud-machine-agent",
				SoftwareVersion: ver,
			},
			&sdelements.Private{
				Name: "model",
				PEN:  28978,
				Data: []rfc5424.StructuredDataParam{{
					Name:  "controller-uuid",
					Value: "9f484882-2f18-4fd2-967d-db9663db7bea",
				}, {
					Name:  "model-uuid",
					Value: "deadbeef-2f18-4fd2-967d-db9663db7bea",
				}},
			},
			&sdelements.Private{
				Name: "log",
				PEN:  28978,
				Data: []rfc5424.StructuredDataParam{{
					Name:  "module",
					Value: "juju.x.y",
				}, {
					Name:  "source",
					Value: "x/y/spam.go:42",
				}},
			},
		},
		Msg: "(╯°□°)╯︵ ┻━┻",
	})
}