Last active
July 27, 2022 13:42
-
-
Save haproxytechblog/a10075517f2185273c88e18fc570d8f9 to your computer and use it in GitHub Desktop.
HAProxy Data Plane API 2.6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
global | |
# Uses a UDP port | |
log 192.168.56.30:514 local0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
global | |
log ring@logbuffer local0 info |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
frontend test | |
http-after-response set-header Cache-Control "no-store,no-cache,private" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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