Practical examples for common use cases
name: CIS Compliance Audit
on:
schedule:
- cron: '0 0 * * 0' # Weekly
push:
branches: [main]
jobs:
audit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.9'
- name: Install dependencies
run: |
pip install -r requirements.txt
python setup.py install
- name: Run CIS Audit
run: |
python -m cis_checker audit --format json
- name: Upload Report
uses: actions/upload-artifact@v3
with:
name: compliance-report
path: reports/
from cis_checker.auditors.ubuntu_auditor import UbuntuAuditor
from cis_checker.reports.html_reporter import HTMLReporter
# Create auditor
auditor = UbuntuAuditor("ubuntu_22_04", level=1)
# Run checks
results = auditor.run_all_checks()
# Get compliance score
score = auditor.get_compliance_score()
print(f"Compliance Score: {score}%")
# Export results
auditor.export_results("audit_results.json")
# Generate HTML report
import json
with open("audit_results.json") as f:
data = json.load(f)
reporter = HTMLReporter()
reporter.generate(data, "report.html")
#!/bin/bash
# Add to crontab for weekly audits
# 0 0 * * 0 /path/to/audit_script.sh
cd /path/to/CIS-Benchmark-Compliance-Checker
# Run audit
python -m cis_checker audit --format html --format json --output /var/reports
# Send notification
if [ $? -eq 0 ]; then
echo "CIS audit completed successfully" | mail -s "CIS Audit Report" admin@example.com
fi