server {
  server_name nagios nagios.* icinga icinga.* alert alert.*;

  <%- if scope.lookupvar('::aws_migration') %>
  listen 80;
  <%- else %>
  listen                    443 ssl;
  ssl_certificate           /etc/nginx/ssl/nagios.crt;
  ssl_certificate_key       /etc/nginx/ssl/nagios.key;
  <%- end %>
  include                   /etc/nginx/ssl.conf;

  index index.html;
  root /usr/share/icinga/htdocs;

  access_log /var/log/nginx/nagios-access.log timed_combined;
  access_log /var/log/nginx/nagios-json.event.access.log json_event;
  error_log /var/log/nginx/nagios-error.log;

  location /stylesheets {
    alias /etc/icinga/stylesheets;
  }

  location ~ \.cgi$ {
    root /usr/lib/cgi-bin/icinga;
    rewrite ^/cgi-bin/icinga/(.*)$ /$1;

    include /etc/nginx/fastcgi_params;

    fastcgi_param AUTH_USER $remote_user;
    fastcgi_param REMOTE_USER $remote_user;
    fastcgi_param SCRIPT_FILENAME /usr/lib/cgi-bin/icinga$fastcgi_script_name;

    fastcgi_pass fcgiwrap;
  }

}

server {
  server_name nagios nagios.* icinga icinga.* alert alert.*;

  <%- if scope.lookupvar('::aws_migration') %>
  listen 80;
  <%- else %>
  listen                    443 ssl;
  ssl_certificate           /etc/nginx/ssl/nagios.crt;
  ssl_certificate_key       /etc/nginx/ssl/nagios.key;
  <%- end %>
  include                   /etc/nginx/ssl.conf;

  index index.html;
  root /usr/share/icinga/htdocs;

  access_log /var/log/nginx/nagios-access.log timed_combined;
  access_log /var/log/nginx/nagios-json.event.access.log json_event;
  error_log /var/log/nginx/nagios-error.log;

  location /stylesheets {
    alias /etc/icinga/stylesheets;
  }

  location ~ \.cgi$ {
    root /usr/lib/cgi-bin/icinga;
    rewrite ^/cgi-bin/icinga/(.*)$ /$1;

    add_header Access-Control-Allow-Origin *;

    include /etc/nginx/fastcgi_params;

    fastcgi_param AUTH_USER $remote_user;
    fastcgi_param REMOTE_USER $remote_user;
    fastcgi_param SCRIPT_FILENAME /usr/lib/cgi-bin/icinga$fastcgi_script_name;

    fastcgi_pass fcgiwrap;
  }

}

Add Access-Control-Allow-Origin header for Icinga
Add Access-Control-Allow-Origin header for Icinga

This commit adds a `Access-Control-Allow-Origin` CORS header to all `.cgi` files for Icinga. This will allow the JSON output of these files to be read by other services, such as a proposed client-side implementation of Blinken.