kellyjonbrazil / jc

CLI tool and python library that converts the output of popular command-line tools, file-types, and common strings to JSON, YAML, or Dictionaries. This allows piping of output to tools like jq and simplifying automation scripts.
MIT License
7.86k stars 204 forks source link

New parser: php-fpm8.2 -tt #546

Open chriscroome opened 7 months ago

chriscroome commented 7 months ago

The PHP-FPM configuration for a specific version of PHP is returned as standard error with:

/usr/sbin/php-fpm8.2 -tt
[25-Feb-2024 20:25:25] NOTICE: [global]
[25-Feb-2024 20:25:25] NOTICE:  pid = /run/php/php8.2-fpm.pid
[25-Feb-2024 20:25:25] NOTICE:  error_log = /var/log/php8.2-fpm.log
[25-Feb-2024 20:25:25] NOTICE:  syslog.ident = php-fpm
[25-Feb-2024 20:25:25] NOTICE:  syslog.facility = 24
[25-Feb-2024 20:25:25] NOTICE:  log_buffering = yes
[25-Feb-2024 20:25:25] NOTICE:  log_level = unknown value
[25-Feb-2024 20:25:25] NOTICE:  log_limit = 1024
[25-Feb-2024 20:25:25] NOTICE:  emergency_restart_interval = 0s
[25-Feb-2024 20:25:25] NOTICE:  emergency_restart_threshold = 0
[25-Feb-2024 20:25:25] NOTICE:  process_control_timeout = 0s
[25-Feb-2024 20:25:25] NOTICE:  process.max = 0
[25-Feb-2024 20:25:25] NOTICE:  process.priority = undefined
[25-Feb-2024 20:25:25] NOTICE:  daemonize = yes
[25-Feb-2024 20:25:25] NOTICE:  rlimit_files = 0
[25-Feb-2024 20:25:25] NOTICE:  rlimit_core = 0
[25-Feb-2024 20:25:25] NOTICE:  events.mechanism = epoll
[25-Feb-2024 20:25:25] NOTICE:  systemd_interval = 10s
[25-Feb-2024 20:25:25] NOTICE:  
[25-Feb-2024 20:29:38] NOTICE: [www]
[25-Feb-2024 20:29:38] NOTICE:  prefix = undefined
[25-Feb-2024 20:29:38] NOTICE:  user = www-data
[25-Feb-2024 20:29:38] NOTICE:  group = www-data
[25-Feb-2024 20:29:38] NOTICE:  listen = /run/php/php8.2-fpm.sock
[25-Feb-2024 20:29:38] NOTICE:  listen.backlog = -1
[25-Feb-2024 20:29:38] NOTICE:  listen.acl_users = undefined
[25-Feb-2024 20:29:38] NOTICE:  listen.acl_groups = undefined
[25-Feb-2024 20:29:38] NOTICE:  listen.owner = www-data
[25-Feb-2024 20:29:38] NOTICE:  listen.group = www-data
[25-Feb-2024 20:29:38] NOTICE:  listen.mode = undefined
[25-Feb-2024 20:29:38] NOTICE:  listen.allowed_clients = undefined
[25-Feb-2024 20:29:38] NOTICE:  process.priority = undefined
[25-Feb-2024 20:29:38] NOTICE:  process.dumpable = no
[25-Feb-2024 20:29:38] NOTICE:  pm = dynamic
[25-Feb-2024 20:29:38] NOTICE:  pm.max_children = 4
[25-Feb-2024 20:29:38] NOTICE:  pm.start_servers = 1
[25-Feb-2024 20:29:38] NOTICE:  pm.min_spare_servers = 1
[25-Feb-2024 20:29:38] NOTICE:  pm.max_spare_servers = 1
[25-Feb-2024 20:29:38] NOTICE:  pm.max_spawn_rate = 32
[25-Feb-2024 20:29:38] NOTICE:  pm.process_idle_timeout = 10
[25-Feb-2024 20:29:38] NOTICE:  pm.max_requests = 1000
[25-Feb-2024 20:29:38] NOTICE:  pm.status_path = undefined
[25-Feb-2024 20:29:38] NOTICE:  pm.status_listen = undefined
[25-Feb-2024 20:29:38] NOTICE:  ping.path = undefined
[25-Feb-2024 20:29:38] NOTICE:  ping.response = undefined
[25-Feb-2024 20:29:38] NOTICE:  access.log = undefined
[25-Feb-2024 20:29:38] NOTICE:  access.format = undefined
[25-Feb-2024 20:29:38] NOTICE:  slowlog = undefined
[25-Feb-2024 20:29:38] NOTICE:  request_slowlog_timeout = 0s
[25-Feb-2024 20:29:38] NOTICE:  request_slowlog_trace_depth = 20
[25-Feb-2024 20:29:38] NOTICE:  request_terminate_timeout = 0s
[25-Feb-2024 20:29:38] NOTICE:  request_terminate_timeout_track_finished = no
[25-Feb-2024 20:29:38] NOTICE:  rlimit_files = 0
[25-Feb-2024 20:29:38] NOTICE:  rlimit_core = 0
[25-Feb-2024 20:29:38] NOTICE:  chroot = undefined
[25-Feb-2024 20:29:38] NOTICE:  chdir = undefined
[25-Feb-2024 20:29:38] NOTICE:  catch_workers_output = no
[25-Feb-2024 20:29:38] NOTICE:  decorate_workers_output = yes
[25-Feb-2024 20:29:38] NOTICE:  clear_env = yes
[25-Feb-2024 20:29:38] NOTICE:  security.limit_extensions = .php .phar
[25-Feb-2024 20:29:38] NOTICE:  
[25-Feb-2024 20:29:38] NOTICE: configuration file /etc/php/8.2/fpm/php-fpm.conf test is successful

This can be parsed using the ini parser and some pre-processing:

php-fpm8.2 -tt |& sed 's/.*NOTICE://' | sed 's/configuration file.*//' | jc --ini -p
{
  "global": {
    "pid": "/run/php/php8.2-fpm.pid",
    "error_log": "/var/log/php8.2-fpm.log",
    "syslog.ident": "php-fpm",
    "syslog.facility": "24",
    "log_buffering": "yes",
    "log_level": "unknown value",
    "log_limit": "1024",
    "emergency_restart_interval": "0s",
    "emergency_restart_threshold": "0",
    "process_control_timeout": "0s",
    "process.max": "0",
    "process.priority": "undefined",
    "daemonize": "yes",
    "rlimit_files": "0",
    "rlimit_core": "0",
    "events.mechanism": "epoll",
    "systemd_interval": "10s"
  },
  "www": {
    "prefix": "undefined",
    "user": "www-data",
    "group": "www-data",
    "listen": "/run/php/php8.2-fpm.sock",
    "listen.backlog": "-1",
    "listen.acl_users": "undefined",
    "listen.acl_groups": "undefined",
    "listen.owner": "www-data",
    "listen.group": "www-data",
    "listen.mode": "undefined",
    "listen.allowed_clients": "undefined",
    "process.priority": "undefined",
    "process.dumpable": "no",
    "pm": "dynamic",
    "pm.max_children": "4",
    "pm.start_servers": "1",
    "pm.min_spare_servers": "1",
    "pm.max_spare_servers": "1",
    "pm.max_spawn_rate": "32",
    "pm.process_idle_timeout": "10",
    "pm.max_requests": "1000",
    "pm.status_path": "undefined",
    "pm.status_listen": "undefined",
    "ping.path": "undefined",
    "ping.response": "undefined",
    "access.log": "undefined",
    "access.format": "undefined",
    "slowlog": "undefined",
    "request_slowlog_timeout": "0s",
    "request_slowlog_trace_depth": "20",
    "request_terminate_timeout": "0s",
    "request_terminate_timeout_track_finished": "no",
    "rlimit_files": "0",
    "rlimit_core": "0",
    "chroot": "undefined",
    "chdir": "undefined",
    "catch_workers_output": "no",
    "decorate_workers_output": "yes",
    "clear_env": "yes",
    "security.limit_extensions": ".php .phar"
  }
}

Would this be a suitable candidate for a dedicated parser?

kellyjonbrazil commented 7 months ago

Hey there! Yeah, this could be a new simple parser that wraps the ini parser. Are the datetimes important? We could keep those in, too, if needed.

Another idea might be to post "recipes" for different types of output like this. Maybe we could have a recipes section to the Discussions page, or a Wiki, and/or a blog post with various ones.

chriscroome commented 7 months ago

The datetime is simply the time it was run at so I don't think there is any point in saving it.

The Bash >= 4 method of sending standard error to standard out, |& would make sense in the documentation or a wiki page (for older versions 2>&1 | can be used), perhaps with examples for other shells as well.