If the Hawks cut Wagner in 2018, then this deal is basically for 3 years, $21 million (he would accumulate $15.8 million in cap hits by then, plus the Hawks would have to eat an additional $5.2 million to make him go away).
Had he not signed a deal, he would have made about $1 million this year, which means that even in the '3 years and cut scenario' he'd still be earning $20 million over 2 years in new money. That's a lot better than I would have guessed considering how insanely backloaded the deal looks at first glance.
So even if they cut Wagner in 2018 to avoid those big cap hits, it's still a fair deal from Wagner's perspective.