Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit a840a25
Showing
31 changed files
with
2,983 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
target/ | ||
modules/ | ||
lib/ | ||
|
||
#Eclipse | ||
.project | ||
.metadata | ||
eclipse/ | ||
test-result/ | ||
bin/** | ||
tmp/** | ||
tmp/**/* | ||
*.tmp | ||
*.bak | ||
*.swp | ||
*~.nib | ||
.classpath | ||
.settings/ | ||
.loadpath |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# HeartBeat Manager | ||
|
||
Cheers! | ||
|
||
Christophe H. | ||
@chamerling |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright 2011 Christophe Hamerling | ||
* | ||
* Licensed 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 models.Host; | ||
import play.jobs.Job; | ||
import play.jobs.OnApplicationStart; | ||
import play.test.Fixtures; | ||
|
||
/** | ||
* Bootstrap some init data to avoid some useless test for the application long | ||
* life time | ||
* | ||
* | ||
*/ | ||
@OnApplicationStart | ||
public class Bootstrap extends Job { | ||
|
||
@Override | ||
public void doJob() throws Exception { | ||
if (Host.count() == 0) { | ||
Fixtures.load("initial-data.yml"); | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright 2011 Christophe Hamerling | ||
* | ||
* Licensed 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. | ||
*/ | ||
package controllers; | ||
|
||
import models.Host; | ||
import play.mvc.With; | ||
|
||
/** | ||
* | ||
* @author chamerling | ||
* | ||
*/ | ||
@CRUD.For(Host.class) | ||
@With(Secure.class) | ||
public class AdminHost extends CRUD { | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright 2011 Christophe Hamerling | ||
* | ||
* Licensed 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. | ||
*/ | ||
package controllers; | ||
|
||
import java.util.List; | ||
|
||
import jobs.PingJob; | ||
import models.Host; | ||
import play.mvc.Controller; | ||
|
||
/** | ||
* | ||
* @author chamerling | ||
* | ||
*/ | ||
public class Application extends Controller { | ||
|
||
public static void index() { | ||
List<Host> hosts = Host.findAll(); | ||
render(hosts); | ||
} | ||
|
||
public static void hostInfo(String id) { | ||
index(); | ||
} | ||
|
||
public static void getHosts() { | ||
renderJSON(Host.findAll()); | ||
} | ||
|
||
public static void checkStatus() { | ||
PingJob job = new PingJob(); | ||
job.in(5); | ||
index(); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright 2011 Christophe Hamerling | ||
* | ||
* Licensed 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. | ||
*/ | ||
package controllers; | ||
|
||
import play.Play; | ||
|
||
/** | ||
* | ||
* @author chamerling | ||
* | ||
*/ | ||
public class Security extends Secure.Security { | ||
|
||
static boolean authenticate(String username, String password) { | ||
return username.equals(Play.configuration | ||
.getProperty("secure.admin.username")) | ||
&& password.equals(Play.configuration | ||
.getProperty("secure.admin.password")); | ||
} | ||
|
||
static boolean check(String profile) { | ||
if (profile.equals("Admin")) { | ||
return session.get("username").equals( | ||
Play.configuration.getProperty("secure.admin.username")); | ||
} | ||
return false; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/** | ||
* | ||
*/ | ||
package controllers; | ||
|
||
/* | ||
* Copyright 2011 Christophe Hamerling | ||
* | ||
* Licensed 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 java.io.InputStreamReader; | ||
|
||
import com.google.gson.Gson; | ||
import com.google.gson.stream.JsonReader; | ||
|
||
import models.Host; | ||
import play.mvc.Controller; | ||
|
||
/** | ||
* Exposed Web services | ||
* | ||
* @author chamerling | ||
* | ||
*/ | ||
public class Services extends Controller { | ||
|
||
public static void status() { | ||
System.out.println("Got a status call..."); | ||
Gson gson = new Gson(); | ||
Host newHost = gson.fromJson(new InputStreamReader(request.body), Host.class); | ||
|
||
long current = System.currentTimeMillis(); | ||
// get the host or register a new one is needed | ||
Host host = Host.getFromName(newHost.hostname); | ||
if (host != null) { | ||
host.lastPing = current; | ||
host.lastSuccess = current; | ||
host.save(); | ||
} else { | ||
newHost.lastPing = current; | ||
newHost.lastSuccess = current; | ||
newHost.save(); | ||
} | ||
} | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* Copyright 2011 Christophe Hamerling | ||
* | ||
* Licensed 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. | ||
*/ | ||
package jobs; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import notifiers.Mails; | ||
|
||
import models.Host; | ||
import play.jobs.Every; | ||
import play.jobs.Job; | ||
import play.libs.WS; | ||
import play.libs.WS.HttpResponse; | ||
import play.libs.WS.WSRequest; | ||
|
||
/** | ||
* | ||
* @author chamerling | ||
* | ||
*/ | ||
@Every("1h") | ||
public class PingJob extends Job<String> { | ||
|
||
@Override | ||
public void doJob() throws Exception { | ||
System.out.println("Let's ping all..."); | ||
|
||
List<Host> hosts = Host.findAll(); | ||
List<Host> failures = new ArrayList<Host>(); | ||
for (Host host : hosts) { | ||
long current = System.currentTimeMillis(); | ||
System.out.println("Calling host at " + host.hostname); | ||
String call = host.hostname; | ||
WSRequest request = WS.url(call).timeout("30s"); | ||
HttpResponse response = null; | ||
host.lastPing = current; | ||
|
||
try { | ||
response = request.get(); | ||
int status = response.getStatus(); | ||
if (status == 200) { | ||
host.lastSuccess = current; | ||
} else { | ||
failures.add(host); | ||
} | ||
} catch (Exception e) { | ||
failures.add(host); | ||
} | ||
host.save(); | ||
} | ||
|
||
if (failures.size() > 0) { | ||
Mails.failures(failures); | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package jobs; | ||
|
||
/* | ||
* Copyright 2011 Christophe Hamerling | ||
* | ||
* Licensed 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 java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import notifiers.Mails; | ||
|
||
import org.apache.commons.mail.SimpleEmail; | ||
|
||
import models.Host; | ||
import play.Play; | ||
import play.jobs.Every; | ||
import play.jobs.Job; | ||
import play.libs.Mail; | ||
|
||
/** | ||
* @author chamerling | ||
* | ||
*/ | ||
@Every("24h") | ||
public class ReportingJob extends Job<String> { | ||
|
||
/** | ||
* Get all the reports and generate a summary to be sent to the manager | ||
*/ | ||
@Override | ||
public void doJob() throws Exception { | ||
System.out.println("Fire Report"); | ||
List<Host> result = new ArrayList<Host>(); | ||
List<Host> hosts = Host.findAll(); | ||
for (Host host : hosts) { | ||
if (host.lastPing != host.lastSuccess) { | ||
result.add(host); | ||
} | ||
} | ||
|
||
if (result.size() > 0) { | ||
Mails.failures(result); | ||
} | ||
} | ||
} |
Oops, something went wrong.