Skip to content

Instantly share code, notes, and snippets.

@haproxytechblog
Last active July 27, 2022 13:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save haproxytechblog/a10075517f2185273c88e18fc570d8f9 to your computer and use it in GitHub Desktop.
Save haproxytechblog/a10075517f2185273c88e18fc570d8f9 to your computer and use it in GitHub Desktop.
HAProxy Data Plane API 2.6
global
# Uses a UDP port
log 192.168.56.30:514 local0
ring logbuffer
description "My log buffer"
format rfc3164
maxlen 1200
size 32764
timeout connect 5s
timeout server 10s
# Uses a TCP port
server mysyslogsrv 192.168.56.30:514 log-proto octet-count
global
log ring@logbuffer local0 info
$ curl -X POST \
--user admin:password \
-H "Content-Type: application/json" \
-d '{
"name": "logbuffer",
"description": "My log buffer",
"format": "rfc3164",
"maxlen": 1200,
"size": 32764,
"timeout_connect": 5000,
"timeout_server": 1000
}' \
"http://127.0.0.1:5555/v2/services/haproxy/configuration/rings?version=1"
$ curl -X POST \
-–user admin:password \
-H "Content-Type: application/json" \
-d '{
"name": "mysyslogsrv",
"address": "192.168.56.30",
"port": 514,
"log_proto": "octet-count"
}' \
"http://127.0.0.1:5555/v2/services/haproxy/configuration/servers?parent_type=ring&parent_name=logbuffer&version=2"
log-forward sylog
# receive log messages on UDP port
dgram-bind 192.168.56.20:514
# receive log messages on TCP port
bind 192.168.56.20:514
# forward to this syslog server using UDP
log 192.168.56.21:514 local0
$ curl -X POST \
-–user admin:password \
-H "Content-Type: application/json" \
-d '{
"name": "sylog",
"maxconn": 100
}' \
"http://127.0.0.1:5555/v2/services/haproxy/configuration/log_forwards?version=3"
$ curl -X POST \
-–user admin:password \
-H "Content-Type: application/json" \
-d '{
"address": "192.168.56.20",
"port": 514
}' \
"http://127.0.0.1:5555/v2/services/haproxy/configuration/binds?parent_type=log_forward&parent_name=syslog&version=4"
$ curl -X POST \
-–user admin:password \
-H "Content-Type: application/json" \
-d '{
"address": "192.168.56.20",
"port": 514
}' \
"http://127.0.0.1:5555/v2/services/haproxy/configuration/dgram_binds?log_forward=syslog&version=5"
$ curl -X POST \
-–user admin:password \
-H "Content-Type: application/json" \
-d '{
"address": "192.168.56.21:514",
"facility": "level0",
"sample_range": "1",
"sample_size": 2,
}' \
"http://127.0.0.1:5555/v2/services/haproxy/configuration/log_targets?parent_type=log_forward&parent_name=syslog&version=5"
frontend test
http-after-response set-header Cache-Control "no-store,no-cache,private"
$ curl -X GET \
-–user admin:password \
-H "Content-Type: application/json" \
"http://127.0.0.1:5555/v2/health"
HTTP/1.1 200 OK
Content-Type: application/json
Vary: Origin
Date: Thu, 14 Jul 2022 13:01:17 GMT
Content-Length: 22
Connection: close
{
"haproxy": "up"
}
haproxy {
config_file = "/etc/haproxy/haproxy.cfg"
haproxy_bin = "haproxy"
reload {
reload_delay = 5
reload_cmd = "systemctl reload haproxy"
restart_cmd = "systemctl restart haproxy"
status_cmd = "systemctl status haproxy"
reload_retention = 1
}
}
haproxy:
config_file: "/etc/haproxy/haproxy.cfg"
haproxy_bin: "haproxy"
reload:
reload_delay: 5
reload_cmd: "systemctl reload haproxy"
restart_cmd: "systemctl restart haproxy"
status_cmd: "systemctl status haproxy"
reload_retention: 1
$ curl -X POST \
-–user admin:password \
-H "Content-Type: application/json" \
-d '{
"index": 0,
"action": "set-header",
"hdr_name": "Cache-Control",
"hdr_fmt": "no-store,no-cache,private",
}' \
"http://127.0.0.1:5555/v2/services/haproxy/configuration/http_after_response_rules?parent_type=frontend&parent_name=test&version=1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment