Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/mjarkk/haproxysocket

A go wrapper around the haproxy unix socket
https://github.com/mjarkk/haproxysocket

Last synced: about 1 month ago
JSON representation

A go wrapper around the haproxy unix socket

Awesome Lists containing this project

README

        

# `haproxysocket` a go wrapper for the haproxy unix sock
This covers about 80% of the commandos, although the goal is to get 100%

## How to use
See [./example](./example) for a working example,
In your haproxy config under **global** add`stats timeout 2m` and add`stats socket [email protected]:9999 level admin` or`stats socket /var/run/haproxy.sock mode 666 level admin`

In your go code:
```go
package main

import (
"fmt"

"github.com/mjarkk/haproxysocket"
)

func main() {
// Create a instace of haproxy
// Make sure to change /var/run/haproxy.sock to where your haproxy sock file is
// For the tpc sock use: ("tcp", "localhost:9999")
h := haproxysocket.New("unix", "/var/run/haproxy.sock")

// Get the sessions
sessions, err := h.ShowSess()
if err != nil {
panic(err)
}
fmt.Println("Sessions:")
for _, session := range sessions {
fmt.Println("ID:", session.ID)
}

// Set a server to maintenance mode
s := h.Server("test-backend", "serv1")
err = s.State("maint")
if err != nil {
panic(err)
}
}
```

## Avaliable functions
Most functions have the same naming sceme as the socket commands, for example`show errors` will be `ShowErrors`
For documentatoin about the functions see: [mangement.txt > 9.3. Unix Socket commands](http://www.haproxy.org/download/2.0/doc/management.txt)
- `ShowErrors`
- `ClearCounters`
- `ShowInfo`
- `ShowStat`
- `ShowSchemaJSON`
- `DisableAgent`
- `DisableHealth`
- `DisableServer`
- `EnableAgent`
- `EnableHealth`
- `EnableServer`
- `SetMaxconnServer`
- `Server`
- `Server(..).Addr`
- `Server(..).Agent`
- `Server(..).AgentAddr`
- `Server(..).AgentSend`
- `Server(..).Health`
- `Server(..).CheckPort`
- `Server(..).State`
- `Server(..).Weight`
- `Server(..).FQDN`
- `GetWeight`
- `SetWeight`
- `ShowSess`
- `ShutdownSession`
- `ShutdownSessionsServer`
- `ClearTable` :x: Not inplemented yet
- `SetTable` :x: Not inplemented yet
- `ShowTable` :x: Not inplemented yet
- `DisableFrontend`
- `EnableFrontend`
- `SetMaxconnFrontend`
- `ShowServersState`
- `ShowBackend`
- `ShutdownFrontend`
- `SetDynamicCookieKeyBackend`
- `DynamicCookieBackend`
- `ShowStatResolvers`
- `SetMaxconnGlobal`
- `SetRateLimit`
- `ShowEnv`
- `ShowCliSockets`
- `AddACL` :x: Not inplemented yet
- `ClearACL` :x: Not inplemented yet
- `DelACL` :x: Not inplemented yet
- `GetACL` :x: Not inplemented yet
- `ShowACL` :x: Not inplemented yet
- `AddMap` :x: Not inplemented yet
- `ClearMap` :x: Not inplemented yet
- `DelMap` :x: Not inplemented yet
- `GetMap` :x: Not inplemented yet
- `SetMap` :x: Not inplemented yet
- `ShowMap`
- `ShowPools`