diff --git a/Makefile b/Makefile index 558582f..d04d6b8 100644 --- a/Makefile +++ b/Makefile @@ -18,10 +18,10 @@ docker-compose: docker-build BRANCH=$(shell git branch --show-current | sed -e 's:/:-:g') $${DOCKER_COMPOSE} up --force-recreate --build .PHONY: devel -devel: athena-monitor athena-processor docker-build docker-compose +devel: install docker-build docker-compose -.PHONY: common-docker monitor processor -docker-build: athena-monitor docker-build-monitor athena-processor docker-build-processor docker-build-debug-container +.PHONY: docker-build monitor processor +docker-build: install docker-build-monitor docker-build-processor docker-build-debug-container .PHONY: docker-build-monitor docker-build-processor docker-build-monitor docker-build-processor: docker-build-%: @@ -84,7 +84,7 @@ test: install: build rm -rf build mkdir build - cp athena-monitor athena-processor build/ + cp --verbose athena-monitor athena-processor build/ .PHONY: docs docs: diff --git a/pkg/common/salesforce.go b/pkg/common/salesforce.go index 0434933..8e1c5ec 100644 --- a/pkg/common/salesforce.go +++ b/pkg/common/salesforce.go @@ -82,6 +82,7 @@ func (sf *BaseSalesforceClient) GetCaseByNumber(number string) (*Case, error) { } func (sf *BaseSalesforceClient) PostComment(caseId, body string, isPublic bool) *simpleforce.SObject { + log.Debugf("Posting comment for case %s", caseId) return sf.SObject("CaseComment"). Set("ParentId", caseId). Set("CommentBody", html.UnescapeString(body)). @@ -90,15 +91,32 @@ func (sf *BaseSalesforceClient) PostComment(caseId, body string, isPublic bool) } func (sf *BaseSalesforceClient) PostChatter(caseId, body string, isPublic bool) *simpleforce.SObject { + log.Debugf("Posting comment to chatter for case %s", caseId) visibility := "InternalUsers" if isPublic { visibility = "AllUsers" } - return sf.SObject("FeedItem"). + newComment := sf.SObject("FeedItem"). Set("ParentId", caseId). Set("Body", body). Set("Visibility", visibility). Create() + if newComment != nil { + log.Debugf("Successfully posted comment as FeedItem to case %s", caseId) + return newComment + } + log.Warnf("Unable to post comment as FeedItem object to case %s", caseId) + newComment = sf.SObject("CaseFeed"). + Set("ParentId", caseId). + Set("Body", body). + Set("Visibility", visibility). + Create() + if newComment != nil { + log.Debugf("Successfully posted comment as CaseFeed object to case %s", caseId) + return newComment + } + log.Errorf("Unable to post comment as either FeedItem or CaseFeed object for %s", caseId) + return newComment } func GetCaseNumberFromFilename(filename string) (string, error) { diff --git a/pkg/config/config.go b/pkg/config/config.go index 555894d..8ff7d20 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -72,12 +72,12 @@ func NewProcessor() Processor { } type SalesForce struct { + EnableChatter bool `yaml:"enable-chatter"` Endpoint string `yaml:"endpoint"` - Username string `yaml:"username"` + MaxCommentLength int `yaml:"max-comment-length"` Password string `yaml:"password"` SecurityToken string `yaml:"security-token"` - MaxCommentLength int `yaml:"max-comment-length"` - EnableChatter bool `yaml:"enable-chatter"` + Username string `yaml:"username"` } func NewSalesForce() SalesForce { diff --git a/pkg/monitor/monitor.go b/pkg/monitor/monitor.go index 25e3793..cd7eb28 100644 --- a/pkg/monitor/monitor.go +++ b/pkg/monitor/monitor.go @@ -86,11 +86,14 @@ func (m *Monitor) GetMatchingProcessorByFile(files []db.File) (map[string][]db.F for _, file := range files { var processors []string + log.Debugf("Analyzing file %s", file.Path) caseNumber, err := common.GetCaseNumberFromFilename(file.Path) if err == nil { sfCase, err = salesforceClient.GetCaseByNumber(caseNumber) if err != nil { log.Warningf("Failed to get a case from number: '%s'", caseNumber) + } else { + log.Debugf("Found customer '%s' for case number %s", sfCase.Customer, caseNumber) } } else { log.Warningf("Failed to identify case from filename '%s': %s", file.Path, err) diff --git a/pkg/processor/processor.go b/pkg/processor/processor.go index e23bb4f..f3bbdc5 100644 --- a/pkg/processor/processor.go +++ b/pkg/processor/processor.go @@ -508,6 +508,7 @@ func (p *Processor) BatchSalesforceComments(ctx *context.Context, interval time. log.Infof("Processing comment for case %s", caseId) commentChunks := splitComment(renderedComment, p.Config.Salesforce.MaxCommentLength) + wasPosted := true for i, chunk := range commentChunks { var chunkHeader string if len(commentChunks) > 1 { @@ -523,16 +524,21 @@ func (p *Processor) BatchSalesforceComments(ctx *context.Context, interval time. } if comment == nil { log.Errorf("Failed to post comment to case id: %s", caseId) + wasPosted = false continue } } - log.Infof("Successfully posted comment on case %s for %d reports", caseId, len(reports)) - for _, report := range reports { - report.Commented = true - p.Db.Save(report) + if wasPosted { + log.Infof("Successfully posted comment on case %s for %d reports", caseId, len(reports)) + for _, report := range reports { + report.Commented = true + p.Db.Save(report) + } + reportMap = nil + } else { + log.Errorf("Could not post comment to case id: %s", caseId) } - reportMap = nil } } }