Last active
May 23, 2016 01:34
-
-
Save maatthc/23ba002e55046eac23903e509b9147fa to your computer and use it in GitHub Desktop.
Generate Server list for mRemote3G from Datadog mRemote3G : https://github.com/kmscode/mRemote3G Datadog: app.datadoghq.com
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Generate Server list for mRemote3G (former mRemoteNG) from Datadog Infrastructure List | |
mRemote3G : https://github.com/kmscode/mRemote3G | |
Datadog: app.datadoghq.com | |
Author: Alexandre Andrade | |
""" | |
import json | |
from urllib.request import Request, urlopen | |
from urllib.error import URLError, HTTPError | |
import pprint | |
# Default login name to be used for each connection | |
so_username = '<YouUsernameHere>' | |
# On the Datadog system, create an application_key to be used on this script and set up there with the api_key | |
Datadog_API = "https://app.datadoghq.com/reports/v2/overview?application_key=<YOUR APP KEY>&api_key=<YOUR API KEY>&with_apps=true&with_sources=true&with_aliases=true&with_meta=true&with_mute_status=true&with_tags=true" | |
# Where to save the generated mRemote3G | |
xml_out_file = "c:\\temp\myconf.xml" | |
# XML Masks - TODO Make it clear/not repetitive. | |
xml_head = '<?xml version="1.0" encoding="utf-8"?>\n<Connections Name="Connections" Export="False" Protected="7Oyrgw+9IWjfJt31JKQGZo/iuIOOihNkE3T1+YYhstu+zJUdGvqsCwHNgNRxtNjq" ConfVersion="2.5">\n' | |
xml_folder = ' <Node Name="%s" Type="Container" Expanded="True" Descr="" Icon="mRemoteNG" Panel="General" Username="" Domain="" Password="" Hostname="" Protocol="RDP" PuttySession="Default Settings" Port="3389" ConnectToConsole="False" UseCredSsp="True" RenderingEngine="IE" RDPAuthenticationLevel="NoAuth" LoadBalanceInfo="" Colors="Colors16Bit" Resolution="FitToWindow" AutomaticResize="True" DisplayWallpaper="False" DisplayThemes="False" EnableFontSmoothing="False" EnableDesktopComposition="False" CacheBitmaps="True" RedirectDiskDrives="False" RedirectPorts="False" RedirectPrinters="False" RedirectSmartCards="False" RedirectSound="DoNotPlay" RedirectKeys="False" Connected="False" PreExtApp="" PostExtApp="" MacAddress="" UserField="" ExtApp="" VNCCompression="CompNone" VNCEncoding="EncHextile" VNCAuthMode="AuthVNC" VNCProxyType="ProxyNone" VNCProxyIP="" VNCProxyPort="0" VNCProxyUsername="" VNCProxyPassword="" VNCColors="ColNormal" VNCSmartSizeMode="SmartSAspect" VNCViewOnly="False" RDGatewayUsageMethod="Never" RDGatewayHostname="" RDGatewayUseConnectionCredentials="Yes" RDGatewayUsername="" RDGatewayPassword="" RDGatewayDomain="" InheritCacheBitmaps="False" InheritColors="False" InheritDescription="False" InheritDisplayThemes="False" InheritDisplayWallpaper="False" InheritEnableFontSmoothing="False" InheritEnableDesktopComposition="False" InheritDomain="False" InheritIcon="False" InheritPanel="False" InheritPassword="False" InheritPort="False" InheritProtocol="False" InheritPuttySession="False" InheritRedirectDiskDrives="False" InheritRedirectKeys="False" InheritRedirectPorts="False" InheritRedirectPrinters="False" InheritRedirectSmartCards="False" InheritRedirectSound="False" InheritResolution="False" InheritAutomaticResize="False" InheritUseConsoleSession="False" InheritUseCredSsp="False" InheritRenderingEngine="False" InheritUsername="False" InheritRDPAuthenticationLevel="False" InheritLoadBalanceInfo="False" InheritPreExtApp="False" InheritPostExtApp="False" InheritMacAddress="False" InheritUserField="False" InheritExtApp="False" InheritVNCCompression="False" InheritVNCEncoding="False" InheritVNCAuthMode="False" InheritVNCProxyType="False" InheritVNCProxyIP="False" InheritVNCProxyPort="False" InheritVNCProxyUsername="False" InheritVNCProxyPassword="False" InheritVNCColors="False" InheritVNCSmartSizeMode="False" InheritVNCViewOnly="False" InheritRDGatewayUsageMethod="False" InheritRDGatewayHostname="False" InheritRDGatewayUseConnectionCredentials="False" InheritRDGatewayUsername="False" InheritRDGatewayPassword="False" InheritRDGatewayDomain="False">\n' | |
xml_node = ' <Node Name="%s" Type="Connection" Descr="" Icon="Linux" Panel="General" Username="%s" Domain="" Password="" Hostname="%s" Protocol="SSH2" PuttySession="Default Settings" Port="22" ConnectToConsole="False" UseCredSsp="True" RenderingEngine="IE" RDPAuthenticationLevel="NoAuth" LoadBalanceInfo="" Colors="Colors16Bit" Resolution="FitToWindow" AutomaticResize="True" DisplayWallpaper="False" DisplayThemes="False" EnableFontSmoothing="False" EnableDesktopComposition="False" CacheBitmaps="True" RedirectDiskDrives="False" RedirectPorts="False" RedirectPrinters="False" RedirectSmartCards="False" RedirectSound="DoNotPlay" RedirectKeys="False" Connected="False" PreExtApp="" PostExtApp="" MacAddress="" UserField="" ExtApp="" VNCCompression="CompNone" VNCEncoding="EncHextile" VNCAuthMode="AuthVNC" VNCProxyType="ProxyNone" VNCProxyIP="" VNCProxyPort="0" VNCProxyUsername="" VNCProxyPassword="" VNCColors="ColNormal" VNCSmartSizeMode="SmartSAspect" VNCViewOnly="False" RDGatewayUsageMethod="Never" RDGatewayHostname="" RDGatewayUseConnectionCredentials="Yes" RDGatewayUsername="" RDGatewayPassword="" RDGatewayDomain="" InheritCacheBitmaps="False" InheritColors="False" InheritDescription="False" InheritDisplayThemes="False" InheritDisplayWallpaper="False" InheritEnableFontSmoothing="False" InheritEnableDesktopComposition="False" InheritDomain="False" InheritIcon="False" InheritPanel="False" InheritPassword="False" InheritPort="False" InheritProtocol="False" InheritPuttySession="False" InheritRedirectDiskDrives="False" InheritRedirectKeys="False" InheritRedirectPorts="False" InheritRedirectPrinters="False" InheritRedirectSmartCards="False" InheritRedirectSound="False" InheritResolution="False" InheritAutomaticResize="False" InheritUseConsoleSession="False" InheritUseCredSsp="False" InheritRenderingEngine="False" InheritUsername="False" InheritRDPAuthenticationLevel="False" InheritLoadBalanceInfo="False" InheritPreExtApp="False" InheritPostExtApp="False" InheritMacAddress="False" InheritUserField="False" InheritExtApp="False" InheritVNCCompression="False" InheritVNCEncoding="False" InheritVNCAuthMode="False" InheritVNCProxyType="False" InheritVNCProxyIP="False" InheritVNCProxyPort="False" InheritVNCProxyUsername="False" InheritVNCProxyPassword="False" InheritVNCColors="False" InheritVNCSmartSizeMode="False" InheritVNCViewOnly="False" InheritRDGatewayUsageMethod="False" InheritRDGatewayHostname="False" InheritRDGatewayUseConnectionCredentials="False" InheritRDGatewayUsername="False" InheritRDGatewayPassword="False" InheritRDGatewayDomain="False" />\n' | |
def generate_config_file(servers): | |
with open(xml_out_file, '+w') as f: | |
f.write(xml_head) | |
for game_n in servers: | |
print(game_n) | |
f.write(xml_folder % game_n) | |
for env_n in servers[game_n]: | |
print(" %s" % env_n) | |
f.write("\t") | |
f.write(xml_folder % env_n) | |
servers[game_n][env_n].sort() | |
for server_n in servers[game_n][env_n]: | |
print("----------->> %s" % server_n) | |
f.write(xml_node % (server_n, so_username, server_n)) | |
f.write(" </Node>\n") | |
f.write(" </Node>\n") | |
f.write("</Connections>\n") | |
return True | |
req = Request(Datadog_API) | |
try: | |
# use it | |
resp = urlopen(req) | |
content = resp.read().decode('utf8') | |
my_server_list = json.loads(content) | |
# Dic to keep all detail per game | |
servers = {} | |
for server in my_server_list.get('rows'): | |
server_name = server.get("name") | |
env_name, game_name, role_name = ("",)*3 | |
for tag in server.get("tags_by_source").get("Datadog"): | |
if "env" in tag: | |
env_name = tag.split(":")[1] | |
if "game" in tag: | |
game_name = tag.split(":")[1] | |
if "role" in tag: | |
role_name = tag.split(":")[1] | |
if game_name is "": | |
game_name = "devops" | |
print("Server: %s Env: %s, Game: %s, Role, %s" % (server_name, env_name, game_name, role_name)) | |
if not servers.get(game_name): | |
servers[game_name] = {} | |
if not servers[game_name].get(env_name): | |
servers[game_name][env_name] = [] | |
servers[game_name][env_name].append(server_name) | |
pprint.pprint(servers) | |
if generate_config_file(servers): | |
print("==========================") | |
print("mRemote3G generated successfully at %s" % xml_out_file) | |
except HTTPError as e: | |
print("Error: %s" % str(e)) | |
except URLError as e: | |
print("Error: %s" % str(e)) | |
except IOError as e: | |
print("Error: %s" % str(e)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment