Skip to content
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

Alpha2 #1

Merged
merged 19 commits into from
Jan 26, 2020
Merged
Changes from 1 commit
Commits
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
Prev Previous commit
Next Next commit
ralph demo data integration
mwalkowski committed Jan 7, 2020
commit 1dfe422b404b5f13fa23cf2abbb4553aa48b7c62
1 change: 1 addition & 0 deletions README.MD
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@ Open demo folder and build (it may take couple minutes)
git submodule update --init --recursive
make build
make up
make demodata
```
For now you must manually load dashboard config file to Kibana. Open Web GUI (default kibana port). Then go to _Management_ -> _Saved Objects_ -> Import and select _export.ndjson_

5 changes: 5 additions & 0 deletions demo/Makefile
Original file line number Diff line number Diff line change
@@ -25,8 +25,13 @@ build-elk:
docker-compose $(call compose-file,elk) build

up:
sudo sysctl -w vm.max_map_count=262144
docker-compose $(VMC) up

demodata:
@chmod +x config/demo_data.sh
@config/demo_data.sh

down:
docker-compose $(VMC) down

19 changes: 10 additions & 9 deletions demo/compose/docker-compose.ralph.yml
Original file line number Diff line number Diff line change
@@ -2,40 +2,41 @@ version: '3.3'

services:
web:
image: allegro/ralph:latest
image: allegro/ralph:20191219.1
volumes:
- ralph_media:/var/local/ralph/media
- ralph_static:/usr/share/ralph/static
- ../config/ralph/:/test_data
depends_on:
- mariadb
- ralph_mariadb
- redis
- nginx
- ralph_nginx
environment:
DATABASE_NAME: ${MYSQL_DATABASE}
DATABASE_USER: ${MYSQL_USER}
DATABASE_PASSWORD: ${MYSQL_PASSWORD}
DATABASE_HOST: mariadb
DATABASE_HOST: ralph_mariadb
REDIS_HOST: redis
REDIS_PASSWORD: ""
REDIS_PORT: 6379
REDIS_DB: 0

nginx:
image: allegro/ralph-static-nginx:latest
ralph_nginx:
image: allegro/ralph-static-nginx:20191219.1
restart: always
ports:
- "8081:80"
volumes:
- ralph_media:/opt/media

mariadb:
ralph_mariadb:
image: mariadb:${MARIADB_VERSION}
env_file: ../.env
volumes:
- mariadb-data:/var/lib/mysql

inkpy:
image: allegro/inkpy:latest
ralph_inkpy:
image: allegro/inkpy:0.1.4
environment:
REDIS_HOST: redis
REDIS_PASSWORD: ""
1 change: 1 addition & 0 deletions demo/compose/docker-compose.vmc.yml
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@ services:
- redis
volumes:
- ../config/vmc/demo.yml:/etc/vmc/config.yml
- ../config/vmc/demo_data.json:/tmp/demo_data.json

worker:
image: dsecureme/vmc:latest
15 changes: 15 additions & 0 deletions demo/config/demo_data.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
echo "Ralph: Make migrations"
docker exec -it compose_web_1 ralphctl migrate

echo "Ralph: Create demo superuser (login: ralph, password: ralph)"
docker exec -it compose_web_1 ralphctl loaddata /test_data/demo_admin_user.json

echo "Ralph: Load demo data"
docker exec -it compose_web_1 ralphctl demodata
docker exec -it compose_web_1 python3 /test_data/generate_ips.py

echo "VMC: Load data (superuser login: admin, password:adminadmin)"
docker exec -it compose_admin_1 vmc loaddata /tmp/demo_data.json

echo "VMC: Import Assets from Ralph"
docker exec -it compose_admin_1 vmc shell -c 'from vmc.ralph.tasks import load_all_assets; load_all_assets();'
40 changes: 40 additions & 0 deletions demo/config/ralph/demo_admin_user.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
[
{
"model": "accounts.ralphuser",
"fields": {
"password": "pbkdf2_sha256$20000$drcbYx2gY196$AyCQce6yDkhl6ygVlNQX8bp2HIkORqx+MfXJHLWzIUA=",
"last_login": null,
"is_superuser": true,
"username": "ralph",
"first_name": "",
"last_name": "",
"email": "",
"is_staff": true,
"is_active": true,
"date_joined": "2020-01-07T11:19:45",
"country": 153,
"city": "",
"company": "",
"employee_id": "",
"profit_center": "",
"cost_center": "",
"department": "",
"manager": "",
"location": "",
"segment": "",
"team": null,
"groups": [],
"user_permissions": [],
"regions": []
},
"pk": 1
},
{
"model": "authtoken.token",
"fields": {
"user": 1,
"created": "2020-01-07T11:19:45"
},
"pk": "42cd7772ba5857557d5220527a0c9796d61e54e6"
}
]
75 changes: 75 additions & 0 deletions demo/config/ralph/generate_ips.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
"""
* Licensed to DSecure.me under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. DSecure.me licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
"""
import os
import random
import ralph.settings

ralph.settings.CHECK_IP_HOSTNAME_ON_SAVE = False
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "ralph.settings")

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

from ralph.assets.models import Asset, Ethernet
from ralph.networks.models.networks import IPAddress

USED_IPS = []
USED_MAC = []


def _generate_mac():
while True:
mac = "52:54:00:%02x:%02x:%02x" % (
random.randint(0, 255),
random.randint(0, 255),
random.randint(0, 255),
)
if mac not in USED_MAC:
USED_MAC.append(mac)
return mac


def _random_ip_address():
while True:
octets = []
for x in range(4):
octets.append(str(random.randint(0, 255)))
ip = '.'.join(octets)
if ip not in USED_IPS:
USED_IPS.append(ip)
return ip


def main():
used_ips = []
dc_assets = Asset.objects.filter(backofficeasset__isnull=True)
print('Generating IP addesses for', dc_assets.count())

for idx, asset in enumerate(dc_assets):
ip = _random_ip_address()
used_ips.append(ip)
eth = Ethernet.objects.create(base_object=asset, mac=_generate_mac())
IPAddress.objects.create(address=_random_ip_address(), ethernet=eth, hostname=asset.hostname)

print('Generation done')


if __name__ == '__main__':
main()
76 changes: 76 additions & 0 deletions demo/config/vmc/demo_data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
[
{
"model": "auth.user",
"pk": 1,
"fields": {
"password": "pbkdf2_sha256$120000$0H3bVC5lUpTu$p8GDS9KUFy2cQzO9pGajRBBP6nzbo0Wxb5Ztj4394js=",
"last_login": "2019-03-05T18:22:41.092Z",
"is_superuser": true,
"username": "admin",
"first_name": "",
"last_name": "",
"email": "",
"is_staff": true,
"is_active": true,
"date_joined": "2019-03-05T18:21:42.000Z",
"groups": [],
"user_permissions": []
}
},
{
"model": "django_celery_beat.crontabschedule",
"pk": 1,
"fields": {
"minute": "0",
"hour": "6",
"day_of_week": "*",
"day_of_month": "*",
"month_of_year": "*",
"timezone": "UTC"
}
},
{
"model": "django_celery_beat.periodictasks",
"pk": 1,
"fields": {
"last_update": "2019-04-20T21:18:38.990Z"
}
},
{
"model": "django_celery_beat.periodictask",
"pk": 1,
"fields": {
"name": "Update CVE and CWE every night",
"task": "knowledge_base.tasks.update_cve_cwe",
"interval": null,
"crontab": 1,
"solar": null,
"args": "[]",
"kwargs": "{}",
"queue": null,
"exchange": null,
"routing_key": null,
"priority": null,
"expires": null,
"one_off": false,
"start_time": null,
"enabled": true,
"last_run_at": null,
"total_run_count": 0,
"date_changed": "2019-04-20T21:17:55.202Z",
"description": ""
}
},
{
"model": "ralph.config",
"pk": 1,
"fields": {
"name": "Demo Ralph",
"url": "http://web:8000",
"username": "ralph",
"password": "ralph",
"created_date": "2019-03-06T22:37:31.540Z",
"modified_date": "2019-03-06T22:37:31.540Z"
}
}
]