Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
martinrusev committed Aug 7, 2015
0 parents commit 5d12a43
Show file tree
Hide file tree
Showing 22 changed files with 1,151 additions and 0 deletions.
58 changes: 58 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]

# C extensions
*.so
compilation/

# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover

# Translations
*.mo
*.pot

# Django stuff:
*.log

# Sphinx documentation
docs/_build/

# PyBuilder
target/
Binary file added Output/amon-agent-1.1.exe
Binary file not shown.
Binary file added Output/amon-agent.exe
Binary file not shown.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Amon Monitoring Agent for Windows

## Build

```
pyinstaller.exe --onefile --icon=amon.ico --version-file=version.txt amonagent/amon-agent.py
```
3 changes: 3 additions & 0 deletions amon-agent.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[Main]
amon_url=
server_key=
143 changes: 143 additions & 0 deletions amon-agent.iss
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!

#define NSSM "nssm.exe"
#define AmonServiceName "AmonAgent"
#define AmonApp "amon-agent.exe"


[Setup]
; NOTE: The value of AppId uniquely identifies this application.
; Do not use the same AppId value in installers for other applications.
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
AppId={{33541FBB-1B7C-4C64-8902-420ACE513DF9}
AppName=amon-agent
AppVersion=1.1
;AppVerName=amon-agent 1.0
AppPublisher=Simplistic LLC
AppPublisherURL=https://amon.cx
AppSupportURL=https://amon.cx
AppUpdatesURL=https://amon.cx
DefaultDirName={pf}\AmonAgent
DefaultGroupName=amon-agent
OutputBaseFilename=amon-agent-1.1
Compression=lzma
SolidCompression=yes
WizardImageFile=welcome.bmp
DisableDirPage=auto
DisableProgramGroupPage=yes
CloseApplications=yes
RestartApplications=yes
AlwaysRestart=no
UninstallDisplayIcon={app}\amon-agent.exe
PrivilegesRequired=admin

[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"

[Files]
Source: "dist\amon-agent.exe"; DestDir: "{app}"; Flags: ignoreversion restartreplace;
; NOTE: Don't use "Flags: ignoreversion" on any shared system files
Source: "nssm.exe"; DestDir: "{app}"
Source: "amon-agent.ini"; DestDir: "{app}"; Permissions: everyone-full;

[INI]
Filename: {app}\amon-agent.ini; Section: Main; Key: amon_url; String: {code:GetAmonUrl}
Filename: {app}\amon-agent.ini; Section: Main; Key: server_key; String: {code:GetKey}

[Icons]
Name: "{group}\amon-agent"; Filename: "{app}\amon-agent.exe"



[Run]
; post-install
Filename: "{sys}\msiexec.exe"; Parameters: "/package ""{app}\{#AmonApp}"" /qn /norestart /nocloseapplications /passive"; Flags: shellexec waituntilterminated;
Filename: "{sys}\netsh.exe"; Parameters: "advfirewall firewall add rule name=""AmonAgent Out"" program=""{app}\{#AmonApp}"" dir=out action=allow enable=yes"; Flags: runhidden;
Filename: "{app}\{#NSSM}"; Parameters: "install {#AmonServiceName} ""{app}\{#AmonApp}"" "; Flags: runhidden;
Filename: "{app}\{#NSSM}"; Parameters: "set {#AmonServiceName} AppDirectory {app}"; Flags: runhidden;
Filename: "{app}\{#NSSM}"; Parameters: "set {#AmonServiceName} AppStdout {userappdata}\Amon\amon.log"; Flags: runhidden;
Filename: "{app}\{#NSSM}"; Parameters: "set {#AmonServiceName} AppStderr {userappdata}\Amon\amon.log"; Flags: runhidden;
Filename: "{app}\{#NSSM}"; Parameters: "start {#AmonServiceName}"; Flags: runhidden;


[UninstallDelete]
Type: filesandordirs; Name: "{app}"


[UninstallRun]
; pre-uninstall
Filename: "{app}\{#NSSM}"; Parameters: "stop {#AmonServiceName}"; Flags: runhidden;
Filename: "{app}\{#NSSM}"; Parameters: "remove {#AmonServiceName} confirm"; Flags: runhidden;

[InstallDelete]
Type: files; Name: "{app}\amon-agent.exe"

[Code]
var
UserPage: TInputQueryWizardPage;
procedure InitializeWizard;
begin
{ Create the pages }
UserPage := CreateInputQueryPage(wpWelcome,
'Amon Information', '',
'Please specify the URL where your Amon instance is running and the agent server key, then click Next.');
UserPage.Add('Amon URL:', False);
UserPage.Add('Server Key:', False);
UserPage.Values[0] := GetIniString('Main', 'amon_url', '', WizardDirValue + '\amon-agent.ini');
UserPage.Values[1] := GetIniString('Main', 'server_key', '', WizardDirValue + '\amon-agent.ini');
end;
function GetAmonUrl(Param: String): string;
begin
result := UserPage.Values[0];
end;
function GetKey(Param: String): string;
begin
result := UserPage.Values[1];
end;
function GetUninstallString: string;
var
sUnInstPath: string;
sUnInstallString: String;
begin
Result := '';
sUnInstPath := ExpandConstant('Software\Microsoft\Windows\CurrentVersion\Uninstall\33541FBB-1B7C-4C64-8902-420ACE513DF9_is1'); //Your App GUID/ID
sUnInstallString := '';
if not RegQueryStringValue(HKLM, sUnInstPath, 'UninstallString', sUnInstallString) then
RegQueryStringValue(HKCU, sUnInstPath, 'UninstallString', sUnInstallString);
Result := sUnInstallString;
end;
function IsUpgrade: Boolean;
begin
Result := (GetUninstallString() <> '');
end;
function InitializeSetup: Boolean;
var
V: Integer;
iResultCode: Integer;
sUnInstallString: string;
begin
Result := True; // in case when no previous version is found
if RegValueExists(HKEY_LOCAL_MACHINE,'Software\Microsoft\Windows\CurrentVersion\Uninstall\33541FBB-1B7C-4C64-8902-420ACE513DF9_is1', 'UninstallString') then //Your App GUID/ID
begin
V := MsgBox(ExpandConstant('An old version of the Amon Agent was detected. Do you want to uninstall it?'), mbInformation, MB_YESNO); //Custom Message if App installed
if V = IDYES then
begin
sUnInstallString := GetUninstallString();
sUnInstallString := RemoveQuotes(sUnInstallString);
Exec(ExpandConstant(sUnInstallString), '', '', SW_SHOW, ewWaitUntilTerminated, iResultCode);
Result := True; //if you want to proceed after uninstall
//Exit; //if you want to quit after uninstall
end
else
Result := False; //when older version present and not uninstalled
end;
end;
Binary file added amon.ico
Binary file not shown.
1 change: 1 addition & 0 deletions amonagent/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = '1.1'
35 changes: 35 additions & 0 deletions amonagent/amon-agent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/python
import logging
import sys, time
import os.path

if __package__ is None and not hasattr(sys, "frozen"):
# It is a direct call to __main__.py

path = os.path.realpath(os.path.abspath(__file__))
sys.path.append(os.path.dirname(os.path.dirname(path)))

try:
import amonagent
except:
print 'amonagent is not installed'
sys.exit()

from amonagent import __version__
from amonagent.runner import Runner
from amonagent.remote import Remote
from amonagent.settings import settings

if __name__ == "__main__":
remote = Remote()
runner = Runner()
remote.save_system_info(runner.info())

while True:
runner = Runner()
stats = {
'system': runner.system(),
'processes': runner.processes(),
}
remote.save_system_stats(stats)
time.sleep(settings.SYSTEM_CHECK_PERIOD)
Loading

0 comments on commit 5d12a43

Please sign in to comment.