{"id":21857189,"url":"https://github.com/upfluence/sensu-client-go","last_synced_at":"2025-04-14T18:31:40.855Z","repository":{"id":27002856,"uuid":"30466885","full_name":"upfluence/sensu-client-go","owner":"upfluence","description":"Portable / Embeddable version of the sensu client","archived":false,"fork":false,"pushed_at":"2017-07-27T19:03:55.000Z","size":2289,"stargazers_count":26,"open_issues_count":1,"forks_count":8,"subscribers_count":19,"default_branch":"master","last_synced_at":"2025-03-28T06:51:16.233Z","etag":null,"topics":["go","monitoring","sensu"],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/upfluence.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-02-07T19:15:50.000Z","updated_at":"2023-05-03T00:03:15.000Z","dependencies_parsed_at":"2022-08-31T12:12:38.673Z","dependency_job_id":null,"html_url":"https://github.com/upfluence/sensu-client-go","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/upfluence%2Fsensu-client-go","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/upfluence%2Fsensu-client-go/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/upfluence%2Fsensu-client-go/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/upfluence%2Fsensu-client-go/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/upfluence","download_url":"https://codeload.github.com/upfluence/sensu-client-go/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248936652,"owners_count":21186073,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["go","monitoring","sensu"],"created_at":"2024-11-28T02:25:58.363Z","updated_at":"2025-04-14T18:31:40.831Z","avatar_url":"https://github.com/upfluence.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Sensu Client\n  Portable / Embeddable lighweight version of the sensu client\n\n[![Circle CI](https://circleci.com/gh/upfluence/sensu-client-go.svg?style=svg)](https://circleci.com/gh/upfluence/sensu-client-go)\n\n## Usage\n\nYou can use this project by two different ways.\n\n  * The first is use the project as a standalone program and use\n    external checks/metrics.\n\n  * The second is to use the project as an external golang package and\n    write a project with another main method and add some checks /\n    metrics inside.\n\n\n### Standalone project\n\nThe easiest way to get started is to download the binary from your\ncommand line:\n\n* Linux\n\n```shell\n$ curl -sL https://github.com/upfluence/sensu-client-go/releases/download/v0.0.1/sensu-client-go-linux-amd64-0.0.1 \\\n  \u003e sensu-client\n\n$ chmod +x sensu-client\n```\n\n* OSX\n\n```shell\n$ curl -sL\nhttps://github.com/upfluence/sensu-client-go/releases/download/v0.0.1/sensu-client-go-darwin-amd64-0.0.1 \\\n  \u003e sensu-client\n\n$ chmod +x sensu-client\n```\n\nThen you just have to run the program as `./sensu-client -c /etc/sensu/config.json`. EASY!\n\n### Subpackage\n\n#### Barebone check\n\nIf you want to write a simple check you just have to write a function\nwith zero argument and which returns a check.ExtensionCheckResult. Wrap\nthis function pointer into an `check.ExtensionCheck` and add it into the\n`check.Store` map with check name as key,  such as:\n\npackage main\n\n```golang\npackage main\n\nimport (\n\t\"net/http\"\n\n\t\"github.com/upfluence/goutils/log\"\n\t\"github.com/upfluence/sensu-go/sensu/transport/rabbitmq\"\n\t\"github.com/upfluence/sensu-client-go/sensu\"\n\t\"github.com/upfluence/sensu-client-go/sensu/check\"\n\t\"github.com/upfluence/sensu-client-go/sensu/handler\"\n)\n\nfunc HTTPCheck() check.ExtensionCheckResult {\n\tresp, err := http.Get(\"http://example.com/\")\n\n\tif err != nil {\n\t\treturn handler.Error(err.Error())\n\t}\n\n\tif resp.StatusCode \u003e= 200 \u0026\u0026 resp.StatusCode \u003c 300 {\n\t\treturn handler.Ok(\"Example.com is alive!\")\n\t} else if resp.StatusCode \u003e= 500 {\n\t\treturn handler.Error(\"Example.com return an 5XX status code\")\n\t} else {\n\t\treturn handler.Warning(\"Example.com is not responding as expected\")\n\t}\n}\n\nfunc main() {\n\tcfg, err := sensu.NewConfigFromFlagSet(sensu.ExtractFlags())\n\n\tif err != nil {\n\t\tlog.Fatal(err.Error())\n\t}\n\n\tt, err := rabbitmq.NewRabbitMQTransport(cfg.RabbitMQURI())\n\n  if err != nil {\n\t\tlog.Fatal(err.Error())\n\t}\n\n  client := sensu.NewClient(t, cfg)\n\n\tcheck.Store[\"http_check\"] = \u0026check.ExtensionCheck{HTTPCheck}\n\n\tclient.Start()\n}\n```\n\n#### Standard check\n\nIf you want to write a check and a metric which inspect the same value\nyou can use the `StandardCheck` struct from the `github.com/upfluence/sensu-client-go/sensu/handler`\npackage. Such as:\n\n```golang\npackage main\n\nimport (\n\t\"fmt\"\n\t\"net/http\"\n\t\"time\"\n\n\t\"github.com/upfluence/goutils/log\"\n\t\"github.com/upfluence/sensu-go/sensu/transport/rabbitmq\"\n\t\"github.com/upfluence/sensu-client-go/sensu\"\n\t\"github.com/upfluence/sensu-client-go/sensu/check\"\n\t\"github.com/upfluence/sensu-client-go/sensu/utils\"\n)\n\nfunc HTTPCallDuration() (float64, error) {\n\tt0 := time.Now().Unix()\n\t_, err := http.Get(\"http://example.com/\")\n\n\treturn float64(time.Now().Unix() - t0), err\n}\n\nfunc main() {\n\tc := \u0026utils.StandardCheck{\n\t\tErrorThreshold:   20.0,\n\t\tWarningThreshold: 10.0,\n\t\tMetricName:       \"http_call.duration\",\n\t\tValue:            HTTPCallDuration,\n\t\tCheckMessage: func(v float64) string {\n\t\t\treturn fmt.Sprintf(\"Duration: %.2fs\", v)\n\t\t},\n\t\tComp: func(x, y float64) bool { return x \u003e y },\n\t}\n\n\tcfg, err := sensu.NewConfigFromFlagSet(sensu.ExtractFlags())\n\n\tif err != nil {\n\t\tlog.Fatal(err.Error())\n\t}\n\n\tt, err := rabbitmq.NewRabbitMQTransport(cfg.RabbitMQURI())\n\n  if err != nil {\n\t\tlog.Fatal(err.Error())\n\t}\n\n\tclient := sensu.NewClient(t, cfg)\n\n\tcheck.Store[\"http_duration_check\"] = \u0026check.ExtensionCheck{c.Check}\n\tcheck.Store[\"http_duration_metric\"] = \u0026check.ExtensionCheck{c.Metric}\n\n\tclient.Start()\n}\n```\n\nIf the duration exceed 20s the `http_duration_check` will return an\nError, if the duration exceed 10s the check will return a warning\notherwise it will returns an \"OK\" code.\n\nThe `http_duration_metric` will return `http_call_duration 5.000000 1438125085`\n\nwith 5.0 as the duration of the HTTP call and 1438125085 the timestamp\n\n### Running\n\nYou just have to compile it and execute it, such as:\n\n```shell\n$ ls\n\nmy_awesome_main.go sensu-config.json\n\n$ go build -o sensu-client .\n\n$ ./sensu-client -c sensu-config.json\n\n```\n\n### Options\n\nIn the both cases, you can use the  `-c` flag to use a specific\nconfiguration file, the configuration is pretty similar to the ruby\nclient [check out the doc](https://sensuapp.org/docs/0.26/reference/clients.html). The\ndifference is about the configuration of the RabbitMQ client. You have\nto provide an RabbitMQ URI through the `RABBITMQ_URI` environment\nvariable or by adding the `rabbit_uri` key into the root of the JSON\nconfiguration file.\n\nBy the way you can also specify some options through environment\nvariables:\n\n| variable | explanation | example |\n| -------  | ----------- | ------  |\n| SENSU_CLIENT_SUBSCRIPTIONS | Comma separated subscriptions | email,slack |\n| SENSU_CLIENT_NAME | The name of the client | node-01 |\n| SENSU_CLIENT_ADDRESS | The ip addres of the client | 127.0.0.1 |\n| RABBITMQ_URI | RabbitMQ URI | amqp://guest:guest@localhost:5672/%2f |\n\n## Roadmap\n\n* [ ] Implement the keep-alives specific configurations (thresholds and\n  hanlder)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fupfluence%2Fsensu-client-go","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fupfluence%2Fsensu-client-go","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fupfluence%2Fsensu-client-go/lists"}