Skip to content

Init #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 61 commits into from
Mar 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
200a8d3
init
Dec 11, 2024
9740f71
init
Dec 11, 2024
83d2158
init
Dec 11, 2024
488499e
init
Dec 11, 2024
a9d0b0f
init
Dec 11, 2024
576a8c0
init
Dec 11, 2024
b1859f8
init
Dec 11, 2024
9d96d5e
init
Dec 11, 2024
3c25601
init
Dec 11, 2024
de11abb
bird
james-otten Dec 20, 2024
60331ad
image
james-otten Dec 20, 2024
c36b1da
add requirements.yaml
james-otten Dec 20, 2024
6f89f98
fix image
james-otten Dec 20, 2024
9a97447
netplan -> network
james-otten Dec 20, 2024
cf7a290
network
james-otten Dec 20, 2024
39f48ed
network
james-otten Dec 20, 2024
746bab3
interface
james-otten Dec 20, 2024
e06e70e
deploy
james-otten Dec 22, 2024
e141b48
apc
james-otten Dec 23, 2024
84bbde6
apc
james-otten Dec 23, 2024
e11a060
ubiquiti
james-otten Dec 24, 2024
61e1d36
ubiquiti
james-otten Dec 24, 2024
86f3c23
siklu
james-otten Dec 24, 2024
1eed27d
siklu
james-otten Dec 24, 2024
7b30424
add siklus
james-otten Dec 24, 2024
c3e4ba7
add siklus
james-otten Dec 24, 2024
d9cde09
add brocade
james-otten Dec 25, 2024
2522a32
add brocade
james-otten Dec 25, 2024
1952003
add cambium
james-otten Dec 25, 2024
ef891ec
mesh dns + ssh
james-otten Dec 26, 2024
b834ec3
mesh dns + ssh
james-otten Dec 26, 2024
cefef23
mesh dns
james-otten Dec 26, 2024
3f2d0c4
support
james-otten Dec 26, 2024
788119c
support
james-otten Dec 26, 2024
38262b7
branch
james-otten Dec 26, 2024
d537da1
jb
james-otten Dec 26, 2024
dc43bc2
touch log files
james-otten Dec 27, 2024
b857fec
lint
james-otten Dec 27, 2024
7c64411
motd
james-otten Jan 10, 2025
a681b80
motd
james-otten Jan 10, 2025
a046567
motd
james-otten Jan 10, 2025
d7876de
server stuff
james-otten Jan 15, 2025
409c637
server stuff
james-otten Jan 15, 2025
0a0f07a
lint
james-otten Jan 16, 2025
5506067
lint
james-otten Jan 16, 2025
dd6d52a
lint
james-otten Jan 16, 2025
664c801
lint
james-otten Jan 16, 2025
d425bf8
lint
james-otten Jan 16, 2025
10b1323
lint
james-otten Jan 16, 2025
9ac9bc1
lint
james-otten Jan 16, 2025
fb20c12
lint
james-otten Jan 16, 2025
9ed0625
lint
james-otten Jan 16, 2025
cd5cb23
lint
james-otten Jan 16, 2025
e8fbcd9
use common bird role
james-otten Jan 24, 2025
286be11
dummy
james-otten Jan 24, 2025
211fb43
netgear
james-otten Feb 27, 2025
fe7cfe9
deploy
james-otten Mar 10, 2025
6e1bab7
deploy
james-otten Mar 10, 2025
a8b27c8
vars
james-otten Mar 10, 2025
22d056d
no3
james-otten Mar 10, 2025
d89e058
clean
james-otten Mar 11, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .github/workflows/ansible_lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: ansible-lint
on:
pull_request:
jobs:
build:
name: Ansible Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run ansible-lint
uses: ansible/ansible-lint@6178262c7e0d5e9792b5990d40029047760b8f09
with:
args: "--exclude .ansible/collections/"
setup_python: "true"
working_directory: "./ansible/"
requirements_file: ""
37 changes: 37 additions & 0 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Deploy Environments
permissions: read-all

on:
push:
branches:
- main
workflow_dispatch:
branches:
- main

jobs:
# deploy_prod3:
# name: Deploy prod3
# uses: ./.github/workflows/deploy_syslog.yaml
# with:
# environment: prod3
# secrets: inherit
# #if: github.ref == 'refs/heads/main'

deploy_prod2:
name: Deploy prod2
uses: ./.github/workflows/deploy_syslog.yaml
with:
environment: prod2
secrets: inherit
# needs: deploy_prod3
if: github.ref == 'refs/heads/main'

deploy_prod1:
name: Deploy prod1
uses: ./.github/workflows/deploy_syslog.yaml
with:
environment: prod1
secrets: inherit
needs: deploy_prod2
if: github.ref == 'refs/heads/main'
87 changes: 87 additions & 0 deletions .github/workflows/deploy_syslog.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: Deploy Syslog Infra
permissions: read-all

on:
workflow_call:
inputs:
environment:
required: true
type: string

env:
# Secrets
TF_VAR_proxmox_host: ${{ secrets.TF_VAR_PROXMOX_HOST }}
TF_VAR_proxmox_token_id: ${{ secrets.TF_VAR_PROXMOX_TOKEN_ID }}
TF_VAR_proxmox_token_secret: ${{ secrets.TF_VAR_PROXMOX_TOKEN_SECRET }}
TF_VAR_local_password: ${{ secrets.TF_VAR_LOCAL_PASSWORD }}
TF_VAR_datadog_api_key: ${{ secrets.DATADOG_API_KEY }}
TF_VAR_datadog_site: ${{ secrets.DATADOG_SITE }}
# Credentials for deployment to AWS
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
# S3 bucket for the Terraform state
BUCKET_TF_STATE: ${{ secrets.BUCKET_TF_STATE}}

jobs:
deploy:
runs-on: ubuntu-latest
environment: ${{ inputs.environment }}
steps:
- name: Checkout
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # @v4

- uses: actions/setup-python@82c7e631bb3cdc910f68e0081d67478d79c6982d #@v5
with:
python-version: '3.11'

- name: Setup ansible
run: pip install ansible passlib==1.7.4 && export PATH="$HOME/.local/bin:$PATH" && ansible-galaxy collection install -r ansible/roles/requirements.yml

- name: Setup Terraform with specified version on the runner
uses: hashicorp/setup-terraform@651471c36a6092792c552e8b1bef71e592b462d8 # @v3
with:
terraform_version: 1.8.3

- name: Setup backend
run: |
echo "bucket = \"${{ secrets.BUCKET_TF_STATE }}\"" > backend.tfvars
echo "key = \"terraform/state/syslog-${{ inputs.environment }}.tfstate\"" >> backend.tfvars
working-directory: ./terraform/

- name: Terraform init
id: init
run: terraform init -backend-config=backend.tfvars
working-directory: ./terraform/

- name: Terraform format
id: fmt
run: terraform fmt -check
working-directory: ./terraform/

- name: Terraform validate
run: |
echo "${{ secrets.SSH_PRIVATE_KEY }}" > logssh
echo "${{ secrets.SSH_PUBLIC_KEY }}" > logssh.pub
chmod 600 logssh
chmod 600 logssh.pub
terraform validate
working-directory: ./terraform/

- name: Setup WireGuard
run: |
sudo apt-get update && sudo apt-get install -y wireguard
echo "${{ secrets.WIREGUARD_PRIVATE_KEY }}" > privatekey
sudo ip link add dev wg0 type wireguard
sudo ip address add dev wg0 ${{ secrets.WIREGUARD_OVERLAY_NETWORK_IP }} peer ${{ secrets.WIREGUARD_PEER }}
sudo wg set wg0 listen-port 48123 private-key privatekey peer ${{ secrets.WIREGUARD_PEER_PUBLIC_KEY }} allowed-ips 0.0.0.0/0 endpoint ${{ secrets.WIREGUARD_ENDPOINT }}
sudo ip link set up dev wg0
rm privatekey

- name: Terraform Apply
run: |
terraform apply -auto-approve -input=false -var-file=${{ inputs.environment }}.tfvars
working-directory: ./terraform/

- name: Run playbook
run: sleep 20 && export PATH="$HOME/.local/bin:$PATH" && ansible-playbook -i inventory.yaml syslog.yaml
working-directory: ./ansible/
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
data/
.vscode/
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,20 @@
# syslog-infra

## Ports

| Port | Protocol | Device Type |
| ------------- | ------------- | ------------- |
| 514 | UDP | Mikrotik Router OS + Siklu (opt in static IPs) |
| 515 | UDP | APC UPS |
| 516 | UDP | Ubiquiti airOS |
| 517 | UDP | Brocade |
| 518 | UDP | iLO |
| 519 | UDP | iDRAC |
| 520 | UDP | Netgear |

## Add a new port

1. Add a new file under [ansible/roles/log_collector/files/](./ansible/roles/log_collector/files/)
2. Add the port + ruleset mapping to [ansible/roles/log_collector/files/rsyslog.conf](./ansible/roles/log_collector/files/rsyslog.conf)
3. Add the 3 mappings in [ansible/roles/log_collector/tasks/main.yaml](./ansible/roles/log_collector/tasks/main.yaml) for DD ingestion, file creation, and config file transfer.
4. Update the table in this file.
8 changes: 8 additions & 0 deletions ansible/ansible.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[defaults]
host_key_checking = False
callbacks_enabled = timer, profile_tasks, profile_roles
gathering = 'explicit'
pipelining = True

[ssh_connection]
ssh_args = '-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o CheckHostIP=no -o ControlMaster=auto -o ControlPersist=60s'
3 changes: 3 additions & 0 deletions ansible/inventory.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
plugin: cloud.terraform.terraform_provider
project_path: "../terraform"
23 changes: 23 additions & 0 deletions ansible/roles/log_collector/files/10-port514.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Siklu + Mikrotik Logs Conf

ruleset(name="port514"){
# Siklu nycmesh-162-eh8010-713
# Siklu nycmesh-713-eh8010-162
# Siklu nycmesh-5916-eh8010-1933
# Siklu nycmesh-1933-eh8010-5916
if
( $fromhost-ip == "10.96.40.189" ) or
( $fromhost-ip == "10.70.95.67" ) or
( $fromhost-ip == "10.70.181.10" ) or
( $fromhost-ip == "10.70.188.69" )
then {
action(type="omfile" template="siklu" file="/var/log/siklu.log")
} else if
( $fromhost-ip == "10.96.131.248" )
then {
action(type="omfile" file="/var/log/cambium.log")
# Standard mikrotik
} else {
action(type="omfile" file="/var/log/mikrotik.log")
}
}
4 changes: 4 additions & 0 deletions ansible/roles/log_collector/files/20-apc.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# UPS logs
ruleset(name="apc"){
action(type="omfile" file="/var/log/apc.log")
}
4 changes: 4 additions & 0 deletions ansible/roles/log_collector/files/30-ubiquiti.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Ubiquiti airOS logs
ruleset(name="ubiquiti"){
action(type="omfile" file="/var/log/ubiquiti.log")
}
4 changes: 4 additions & 0 deletions ansible/roles/log_collector/files/40-brocade.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Brocade logs
ruleset(name="brocade"){
action(type="omfile" file="/var/log/brocade.log")
}
4 changes: 4 additions & 0 deletions ansible/roles/log_collector/files/50-ilo.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# iLo logs
ruleset(name="ilo"){
action(type="omfile" file="/var/log/ilo.log")
}
4 changes: 4 additions & 0 deletions ansible/roles/log_collector/files/60-idrac.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# iDRAC logs
ruleset(name="idrac"){
action(type="omfile" file="/var/log/idrac.log")
}
4 changes: 4 additions & 0 deletions ansible/roles/log_collector/files/70-netgear.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# netgear logs
ruleset(name="netgear"){
action(type="omfile" file="/var/log/netgear.log")
}
130 changes: 130 additions & 0 deletions ansible/roles/log_collector/files/rsyslog.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
# /etc/rsyslog.conf configuration file for rsyslog
#
# For more information install rsyslog-doc and see
# /usr/share/doc/rsyslog-doc/html/configuration/index.html


#################
#### MODULES ####
#################

module(load="imuxsock") # provides support for local system logging
#module(load="imklog") # provides kernel logging support
#module(load="immark") # provides --MARK-- message capability

# provides UDP syslog reception
module(load="imudp")
input(type="imudp" port="514" ruleset="port514")
input(type="imudp" port="515" ruleset="apc")
input(type="imudp" port="516" ruleset="ubiquiti")
input(type="imudp" port="517" ruleset="brocade")
input(type="imudp" port="518" ruleset="ilo")
input(type="imudp" port="519" ruleset="idrac")
input(type="imudp" port="520" ruleset="netgear")

# provides TCP syslog reception
module(load="imtcp")
input(type="imtcp" port="514")

###################
#### TEMPLATES ####
###################

# Siklu
template(name="siklu" type="list"){
property(name="timestamp" dateFormat="rfc3339")
constant(value=" ")
property(name="fromhost")
constant(value=" ")
property(name="syslogtag")
property(name="msg" controlcharacters="drop")
constant(value="\n")
}

# For debugging
template(name="RSYSLOG_DebugFormat" type="list") {
constant(value="Debug line with all properties:\nFROMHOST: '")
property(name="fromhost")
constant(value="', fromhost-ip: '")
property(name="fromhost-ip")
constant(value="', HOSTNAME: '")
property(name="hostname")
constant(value="', PRI: '")
property(name="pri")
constant(value=",\nsyslogtag '")
property(name="syslogtag")
constant(value="', programname: '")
property(name="programname")
constant(value="', APP-NAME: '")
property(name="app-name")
constant(value="', PROCID: '")
property(name="procid")
constant(value="', MSGID: '")
property(name="msgid")
constant(value="',\nTIMESTAMP: '")
property(name="timereported")
constant(value="', STRUCTURED-DATA: '")
property(name="structured-data")
constant(value="',\nmsg: '")
property(name="msg")
constant(value="'\nescaped msg: '")
property(name="msg" controlcharacters="drop")
constant(value="'\ninputname: ")
property(name="inputname")
constant(value=" rawmsg: '")
property(name="rawmsg")
constant(value="'\n$!:")
property(name="$!")
constant(value="\n$.:")
property(name="$.")
constant(value="\n$/:")
property(name="$/")
constant(value="\n\n")
}

###########################
#### GLOBAL DIRECTIVES ####
###########################

#
# Set the default permissions for all log files.
#
$FileOwner root
$FileGroup dd-agent
$FileCreateMode 0640
$DirCreateMode 0755
$Umask 0022

#
# Where to place spool and state files
#
$WorkDirectory /var/spool/rsyslog

#
# Include all config files in /etc/rsyslog.d/
#
$IncludeConfig /etc/rsyslog.d/*.conf


###############
#### RULES ####
###############

#
# Log anything besides private authentication messages to a single log file
#
*.*;auth,authpriv.none -/var/log/syslog

#
# Log commonly used facilities to their own log file
#
auth,authpriv.* /var/log/auth.log
cron.* -/var/log/cron.log
kern.* -/var/log/kern.log
mail.* -/var/log/mail.log
user.* -/var/log/user.log

#
# Emergencies are sent to everybody logged in.
#
*.emerg :omusrmsg:*
Loading