Monitorizar JVM usando un CFC y JSON

Buscando una manera de estar monitorizando la JVM usando algo ‘light’, en este caso, llegué a la conclusión de usar un CFC como web service devolviendo en format JSON el estado actual de la JVM, ademas de permitirme escribir un log en ColdFusion.

Ejemplo del ‘output’:

{
  "PERCENTFREEALLOCATED":85.0,
  "FREEMEMORY":214.0,
  "MAXMEMORY":455.0,
  "TOTALMEMORY":253.0,
  "PERCENTALLOCATED":56.0
}

El código es muy simple para prevenir carga innecesaria en el servidor e incluso en la JVM.

Código wsJVM.cfc:

component {
  remote struct function getJVMstat()
    returnformat="JSON" {
      var result = {};
      var runtime = CreateObject("java","java.lang.Runtime").getRuntime();

      result.freememory = round(runtime.freeMemory()/1024^2);
      result.totalmemory = round(runtime.totalMemory()/1024^2);
      result.maxmemory = round(runtime.maxMemory()/1024^2);
      result.percentfreeallocated = round((result.freeMemory/result.totalMemory)*100);
      result.percentallocated = round((result.totalMemory/result.maxMemory)*100);

      writelog("freememory=#result.freememory# totalmemory=#result.totalmemory# maxmemory=#result.maxmemory# percentfreeallocated=#result.percentfreeallocated# percentallocated=#result.percentallocated#","information",false,"jvmstats");

      return result;
  }
}

 

ColdFusion Tip: Make HTML to Plain Text

#REReplace(htmlstr,”<[^>]*>”,”",”All”)#

Usando Splunk Storm REST API en ColdFusion

Comparto con todos ustedes este código para podes utilizar Splunk Storm REST API en ColdFusion, ya que ya pasé la terrible tarea de probar y probar hasta que por fin funciono, decidí compartirlo así no pierdan el tiempo ustedes y continuen con su ardua labor de programar.

splunkstorm.cfc

component {
variables.projectID = "9934fda08f5711e2ad4822000a1ea029";
variables.access_token = "HD2K2mfhhov_fiGZaAwx-7sxSpJcNwrtm33hdsKr0yWXY71KYWDdbRCk8XT3B2ou6e60eF-QDaE=";
variables.host = createObject("java", "java.net.InetAddress").getLocalHost().getHostName();

public void function send(string event="",
string sourcetype="coldfusion",
string source="",
string host=variables.host,
string projectID=variables.projectID,
string access_token=variables.access_token) {
var result = {};

httpService = new http();
httpService.setMethod("post");
httpService.setCharset("utf-8");
httpService.setUrl("https://api.splunkstorm.com/1/inputs/http?index=#arguments.projectID#&amp;sourcetype=#arguments.sourcetype#&amp;host=#arguments.host#");
httpService.setUsername("x");
httpService.setPassword("#arguments.access_token#");
httpService.addParam(type="header", name="Content-Type", value="text/plain");
httpService.addParam(type="body", value="#arguments.event#");

result = httpService.send().getPrefix();
}
}

Protección Adicional contra XSS en ColdFusion

xss

Hace un par de días atrás me encontre con el problema de que por alguna razón la opción “Protect Cross-Site Scripting” es ignorada cuando hay variables que vienen desde ColdFusion y no en JavaScript, por eso decidí hacer esta función que me ayuda a proteger mis JavaScript que tienen código ColdFusion insertas.

<!--- xssProtect: Prevent XSS attack --->
<cffunction name="xssProtect" access="public" returntype="string">
  <cfargument name="str" type="string" default="" required="no" />
  <cfscript>
    result = "";
    // result = HTMLEditFormat(arguments.str);
    result = REreplace(arguments.str,"<|>|/|(|)|'|'|;|:|=| ","","ALL");

    if(!isNumeric(result))
    result = "'#result#'";

    return result;
  </cfscript>
</cffunction>

Fast Public DNS

Free Public DNS Server

Service provider: Google
8.8.8.8
8.8.4.4

Service provider: DNSadvantage
156.154.70.1
156.154.71.1

Service provider: OpenDNS
208.67.222.222
208.67.220.220

Service provider: Norton
198.153.192.1
198.153.194.1

Service provider: GTEI DNS (now Verizon)
4.2.2.1
4.2.2.2
4.2.2.3
4.2.2.4
4.2.2.5
4.2.2.6

Service provider: ScrubIt
67.138.54.100
207.225.209.66

‘StartUp Code’ para Administrador usando FW/1 y Twitter Bootstrap

Esta aportación a la comunidad de desarrolladores de ColdFusion la hago pensando en ahorrarnos tiempo ha ciendo lo mismo casi siempre, así que con esto al menos entraremos en acción más rapidamente. Read more

Crear un archivo de configuración en onApplicationStart()

Aqui les comparto como pueden automatizar un archivo de configuración en onApplicationStart(). Read more

Enviar notificaciones de error en FW/1

Usando los principios de notificar cada vez que un error ocurre en nuestras aplicaciones, hice esta pequeña función para enviarnos correos cada vez que pasa un error en nuestra aplicación/website usando FW/1.

Read more