Use “the big E” for quick and clean monitoring

Despite all the great tools out there these days for monitoring, it’s difficult to get away without writing a custom monitoring script or two. Spools, various types of cache, multi-server indexing. So many things that can go wrong.

Once upon a time I used to write quick and dirty complex scripts that would email in one case, otherwise do some-such-thing, etc. They were brittle with questionable reliability. Talk about a false sense of security.

These days I like to use an untouted feature of mail to keep things simpler. The idea is to only make noise when there is a problem. If all is well, keep silent.

Take this cron job for example:


*/5 * * * * root /somedir/check-spool.sh | mail -E -s 'Spool Monitor' problem@somedomain.com

check-spool.sh will do just that: Check a spool each time it is run. If everything is fine, no output. If it finds a problem then it outputs what it finds. The “big E” (-E) switch tells mail to ignore any body-less input, and will therefore only spam us when there is some panic-worthy output.

Thanks big E.

JMS\Serializer\Exception\RuntimeException: “Resources are not supported in serialized data…” Yadda yadda

Been bit by this a couple of times now. It’s really a problem with a bad route. In my case I had some ajax using the FOSJsRoutingBundle to generate a route along the lines of:

Routing.generate('some_titles', {id: $(this).val()});

where val() was actually returning an empty string. The resulting URL (“some//titles”) was invalid, looks to JMSSerializer like a resource thanks to the double slash, and badda bing badda boom: completely irrelevant error.

I think this may also be the source of “Cannot redeclare class Doctrine\ORM\Mapping\Annotation” errors to boot. Double whammy.

Couldn’t reserve space for cygwin’s heap, Win32 error 0

Cygwin and Windows git stopped playing nicely together after a recent Windows update. There’s a variety of recommendations for how to fix this this on StackOverflow and elsewhere, but this post actually makes the most sense. In a nutshell, msys-1.0.dll (installed into your Program Files\Git\bin directory) is not built to be position independent. Use the dll rebaser to get it to load at a new address, like so:

$ rebase.exe -b 0x50000000 msys-1.0.dll

And voila, git goodness restored.

Simple Twig Fallback

Love the simplicity of Twig; mainly that it allows us to do away with the conditionals that tend to litter most interface code.  You know the drill: If this then show that otherwise show the other thing except in such-and-such a case..  Confusing and brittle.  Twig’s hierarchical layout is the way to go.

Falling back to a parent block depending on complex output can be tricky however.  Here’s a simple way to do it without a bunch of ifs:

Yay. If less.

Or with one ternary conditional if running parent() through default() is unclear:

{{ details|trim|raw ?: parent() }}

ElasticSearch Delete All

Even though it’s not documented anywhere (as far as I can tell), I probably should have realized this would work:


$ curl -XDELETE http://localhost:9200/
{"ok":true,"acknowledged":true}

Deletes all indices in one fell swoop. Nuclear option. Use caution.

Defeating mysterious “This form should not contain extra fields” errors in Symfony Forms

I love the Symfony framework, but really hate the form component at times. Two years after the initial release of Symfony 2 and we’re still waiting on some decent form validation debugging.

But enough griping. If you’ve ever worked with form events, then undoubtedly you have run into the This form should not contain extra fields error. Basically what it means is that the request parameters don’t match up with the form against which you’re trying to validate.

“Yes, but.. but.. which parameters??” I hear you ask.  Try this:

 

Those “extra data” parameters.

 

Not Defined and Not Empty/Null in Twig

Long time no write.  Came across some syntax today that solves an old annoyance in Symfony's Twig.

Rather than blather on in code with the following complex statement to make sure that a value is both defined and not null:

{% if var is defined and var is not null %}

one can instead simply do this:

{% if var|default is not empty %}

or even more simply:

{% if var|default %}

Nice.

Redacted

If you’ve ever seen Stan Friedman talk about UFO’s, you’ve probably seen his shtick about redacted documents. For example:

Always loved that.

Well, move over Stan. Apparently the U.S. government has even bigger secrets than aliens.